File tree Expand file tree Collapse file tree
rsocket-core/src/main/java/io/rsocket/loadbalance Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11package io .rsocket .loadbalance ;
22
3+ import io .rsocket .RSocket ;
4+
35/**
4- * Representation of stats used by the {@link WeightedLoadbalanceStrategy}
6+ * Representation of stats used by the {@link WeightedLoadbalanceStrategy}.
57 *
68 * @since 1.1
79 */
@@ -16,4 +18,15 @@ public interface WeightedStats {
1618 double predictedLatency ();
1719
1820 double weightedAvailability ();
21+
22+ /**
23+ * Wraps an RSocket with a proxy that implements WeightedStats.
24+ *
25+ * @param rsocket the RSocket to proxy.
26+ * @return the wrapped RSocket.
27+ * @since 1.1.1
28+ */
29+ default RSocket wrap (RSocket rsocket ) {
30+ return new WeightedStatsRSocketProxy (rsocket , this );
31+ }
1932}
Original file line number Diff line number Diff line change 1+ package io .rsocket .loadbalance ;
2+
3+ import io .rsocket .RSocket ;
4+ import io .rsocket .util .RSocketProxy ;
5+
6+ /**
7+ * {@link RSocketProxy} that implements {@link WeightedStats} and delegates to an existing {@link
8+ * WeightedStats} instance.
9+ */
10+ class WeightedStatsRSocketProxy extends RSocketProxy implements WeightedStats {
11+
12+ private final WeightedStats weightedStats ;
13+
14+ public WeightedStatsRSocketProxy (RSocket source , WeightedStats weightedStats ) {
15+ super (source );
16+ this .weightedStats = weightedStats ;
17+ }
18+
19+ @ Override
20+ public double higherQuantileLatency () {
21+ return this .weightedStats .higherQuantileLatency ();
22+ }
23+
24+ @ Override
25+ public double lowerQuantileLatency () {
26+ return this .weightedStats .lowerQuantileLatency ();
27+ }
28+
29+ @ Override
30+ public int pending () {
31+ return this .weightedStats .pending ();
32+ }
33+
34+ @ Override
35+ public double predictedLatency () {
36+ return this .weightedStats .predictedLatency ();
37+ }
38+
39+ @ Override
40+ public double weightedAvailability () {
41+ return this .weightedStats .weightedAvailability ();
42+ }
43+
44+ public WeightedStats getDelegate () {
45+ return this .weightedStats ;
46+ }
47+ }
You can’t perform that action at this time.
0 commit comments