Skip to content

Commit cad188e

Browse files
authored
adds proxy RSocket for WeightedStatsRequestInterceptor (#976)
1 parent d77df7b commit cad188e

2 files changed

Lines changed: 61 additions & 1 deletion

File tree

rsocket-core/src/main/java/io/rsocket/loadbalance/WeightedStats.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package 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
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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+
}

0 commit comments

Comments
 (0)