1717package io .grpc .xds ;
1818
1919import static com .google .common .base .Preconditions .checkArgument ;
20- import static com .google .common .base .Preconditions .checkElementIndex ;
2120import static com .google .common .base .Preconditions .checkNotNull ;
2221
2322import com .google .common .annotations .VisibleForTesting ;
4039import io .grpc .SynchronizationContext ;
4140import io .grpc .SynchronizationContext .ScheduledHandle ;
4241import io .grpc .services .MetricReport ;
43- import io .grpc .util .ForwardingLoadBalancerHelper ;
4442import io .grpc .util .ForwardingSubchannel ;
4543import io .grpc .util .MultiChildLoadBalancer ;
4644import io .grpc .xds .orca .OrcaOobUtil ;
@@ -137,12 +135,12 @@ final class WeightedRoundRobinLoadBalancer extends MultiChildLoadBalancer {
137135 }
138136
139137 public WeightedRoundRobinLoadBalancer (Helper helper , Ticker ticker ) {
140- this (new WrrHelper ( OrcaOobUtil . newOrcaReportingHelper ( helper )) , ticker , new Random ());
138+ this (helper , ticker , new Random ());
141139 }
142140
143- public WeightedRoundRobinLoadBalancer ( WrrHelper helper , Ticker ticker , Random random ) {
144- super ( helper );
145- helper . setLoadBalancer ( this );
141+ @ VisibleForTesting
142+ WeightedRoundRobinLoadBalancer ( Helper helper , Ticker ticker , Random random ) {
143+ super ( OrcaOobUtil . newOrcaReportingHelper ( helper ) );
146144 this .ticker = checkNotNull (ticker , "ticker" );
147145 this .infTime = ticker .nanoTime () + Long .MAX_VALUE ;
148146 this .syncContext = checkNotNull (helper .getSynchronizationContext (), "syncContext" );
@@ -152,11 +150,6 @@ public WeightedRoundRobinLoadBalancer(WrrHelper helper, Ticker ticker, Random ra
152150 log .log (Level .FINE , "weighted_round_robin LB created" );
153151 }
154152
155- @ VisibleForTesting
156- WeightedRoundRobinLoadBalancer (Helper helper , Ticker ticker , Random random ) {
157- this (new WrrHelper (OrcaOobUtil .newOrcaReportingHelper (helper )), ticker , random );
158- }
159-
160153 @ Override
161154 protected ChildLbState createChildLbState (Object key , Object policyConfig ,
162155 SubchannelPicker initialPicker , ResolvedAddresses unused ) {
@@ -270,6 +263,11 @@ public WeightedChildLbState(Object key, LoadBalancerProvider policyProvider, Obj
270263 super (key , policyProvider , childConfig , initialPicker );
271264 }
272265
266+ @ Override
267+ protected ChildLbStateHelper createChildHelper () {
268+ return new WrrChildLbStateHelper ();
269+ }
270+
273271 private double getWeight (AtomicInteger staleEndpoints , AtomicInteger notYetUsableEndpoints ) {
274272 if (config == null ) {
275273 return 0 ;
@@ -305,6 +303,13 @@ public void removeSubchannel(WrrSubchannel wrrSubchannel) {
305303 subchannels .remove (wrrSubchannel );
306304 }
307305
306+ final class WrrChildLbStateHelper extends ChildLbStateHelper {
307+ @ Override
308+ public Subchannel createSubchannel (CreateSubchannelArgs args ) {
309+ return new WrrSubchannel (super .createSubchannel (args ), WeightedChildLbState .this );
310+ }
311+ }
312+
308313 final class OrcaReportListener implements OrcaPerRequestReportListener , OrcaOobReportListener {
309314 private final float errorUtilizationPenalty ;
310315
@@ -374,32 +379,6 @@ public void shutdown() {
374379 super .shutdown ();
375380 }
376381
377- private static final class WrrHelper extends ForwardingLoadBalancerHelper {
378- private final Helper delegate ;
379- private WeightedRoundRobinLoadBalancer wrr ;
380-
381- WrrHelper (Helper helper ) {
382- this .delegate = helper ;
383- }
384-
385- void setLoadBalancer (WeightedRoundRobinLoadBalancer lb ) {
386- this .wrr = lb ;
387- }
388-
389- @ Override
390- protected Helper delegate () {
391- return delegate ;
392- }
393-
394- @ Override
395- public Subchannel createSubchannel (CreateSubchannelArgs args ) {
396- checkElementIndex (0 , args .getAddresses ().size (), "Empty address group" );
397- WeightedChildLbState childLbState =
398- (WeightedChildLbState ) wrr .getChildLbStateEag (args .getAddresses ().get (0 ));
399- return wrr .new WrrSubchannel (delegate ().createSubchannel (args ), childLbState );
400- }
401- }
402-
403382 @ VisibleForTesting
404383 final class WrrSubchannel extends ForwardingSubchannel {
405384 private final Subchannel delegate ;
0 commit comments