5959@ ExperimentalApi ("https://github.com/grpc/grpc-java/issues/9885" )
6060final class WeightedRoundRobinLoadBalancer extends RoundRobinLoadBalancer {
6161 private static final Logger log = Logger .getLogger (
62- WeightedRoundRobinLoadBalancer .class .getName ());
62+ WeightedRoundRobinLoadBalancer .class .getName ());
6363 private WeightedRoundRobinLoadBalancerConfig config ;
6464 private final SynchronizationContext syncContext ;
6565 private final ScheduledExecutorService timeService ;
@@ -113,7 +113,7 @@ public boolean acceptResolvedAddresses(ResolvedAddresses resolvedAddresses) {
113113 @ Override
114114 public RoundRobinPicker createReadyPicker (List <Subchannel > activeList ) {
115115 return new WeightedRoundRobinPicker (activeList , config .enableOobLoadReport ,
116- config .errorUtilizationPenalty );
116+ config .errorUtilizationPenalty );
117117 }
118118
119119 private final class UpdateWeightTask implements Runnable {
@@ -123,7 +123,7 @@ public void run() {
123123 ((WeightedRoundRobinPicker ) currentPicker ).updateWeight ();
124124 }
125125 weightUpdateTimer = syncContext .schedule (this , config .weightUpdatePeriodNanos ,
126- TimeUnit .NANOSECONDS , timeService );
126+ TimeUnit .NANOSECONDS , timeService );
127127 }
128128 }
129129
@@ -132,7 +132,7 @@ private void afterAcceptAddresses() {
132132 WrrSubchannel weightedSubchannel = (WrrSubchannel ) subchannel ;
133133 if (config .enableOobLoadReport ) {
134134 OrcaOobUtil .setListener (weightedSubchannel ,
135- weightedSubchannel .new OrcaReportListener (config .errorUtilizationPenalty ),
135+ weightedSubchannel .new OrcaReportListener (config .errorUtilizationPenalty ),
136136 OrcaOobUtil .OrcaReportingConfig .newBuilder ()
137137 .setReportInterval (config .oobReportingPeriodNanos , TimeUnit .NANOSECONDS )
138138 .build ());
@@ -206,7 +206,7 @@ private double getWeight() {
206206 nonEmptySince = infTime ;
207207 return 0 ;
208208 } else if (now - nonEmptySince < config .blackoutPeriodNanos
209- && config .blackoutPeriodNanos > 0 ) {
209+ && config .blackoutPeriodNanos > 0 ) {
210210 return 0 ;
211211 } else {
212212 return weight ;
@@ -230,8 +230,8 @@ public void onLoadReport(MetricReport report) {
230230 double newWeight = 0 ;
231231 // Prefer application utilization and fallback to CPU utilization if unset.
232232 double utilization =
233- report .getApplicationUtilization () > 0 ? report .getApplicationUtilization ()
234- : report .getCpuUtilization ();
233+ report .getApplicationUtilization () > 0 ? report .getApplicationUtilization ()
234+ : report .getCpuUtilization ();
235235 if (utilization > 0 && report .getQps () > 0 ) {
236236 double penalty = 0 ;
237237 if (report .getEps () > 0 && errorUtilizationPenalty > 0 ) {
@@ -255,19 +255,19 @@ public void onLoadReport(MetricReport report) {
255255 final class WeightedRoundRobinPicker extends RoundRobinPicker {
256256 private final List <Subchannel > list ;
257257 private final Map <Subchannel , OrcaPerRequestReportListener > subchannelToReportListenerMap =
258- new HashMap <>();
258+ new HashMap <>();
259259 private final boolean enableOobLoadReport ;
260260 private final float errorUtilizationPenalty ;
261- private volatile StaticStrideScheduler ssScheduler ;
261+ private volatile StaticStrideScheduler scheduler ;
262262
263263 WeightedRoundRobinPicker (List <Subchannel > list , boolean enableOobLoadReport ,
264- float errorUtilizationPenalty ) {
264+ float errorUtilizationPenalty ) {
265265 checkNotNull (list , "list" );
266266 Preconditions .checkArgument (!list .isEmpty (), "empty list" );
267267 this .list = list ;
268268 for (Subchannel subchannel : list ) {
269269 this .subchannelToReportListenerMap .put (subchannel ,
270- ((WrrSubchannel ) subchannel ).new OrcaReportListener (errorUtilizationPenalty ));
270+ ((WrrSubchannel ) subchannel ).new OrcaReportListener (errorUtilizationPenalty ));
271271 }
272272 this .enableOobLoadReport = enableOobLoadReport ;
273273 this .errorUtilizationPenalty = errorUtilizationPenalty ;
@@ -276,12 +276,12 @@ final class WeightedRoundRobinPicker extends RoundRobinPicker {
276276
277277 @ Override
278278 public PickResult pickSubchannel (PickSubchannelArgs args ) {
279- Subchannel subchannel = list .get (ssScheduler .pick ());
279+ Subchannel subchannel = list .get (scheduler .pick ());
280280 if (!enableOobLoadReport ) {
281281 return PickResult .withSubchannel (subchannel ,
282282 OrcaPerRequestUtil .getInstance ().newOrcaClientStreamTracerFactory (
283283 subchannelToReportListenerMap .getOrDefault (subchannel ,
284- ((WrrSubchannel ) subchannel ).new OrcaReportListener (errorUtilizationPenalty ))));
284+ ((WrrSubchannel ) subchannel ).new OrcaReportListener (errorUtilizationPenalty ))));
285285 } else {
286286 return PickResult .withSubchannel (subchannel );
287287 }
@@ -295,16 +295,16 @@ private void updateWeight() {
295295 newWeights [i ] = newWeight > 0 ? (float ) newWeight : 0.0f ;
296296 }
297297
298- StaticStrideScheduler ssScheduler = new StaticStrideScheduler (newWeights , random );
299- this .ssScheduler = ssScheduler ;
298+ StaticStrideScheduler scheduler = new StaticStrideScheduler (newWeights , random );
299+ this .scheduler = scheduler ;
300300 }
301301
302302 @ Override
303303 public String toString () {
304304 return MoreObjects .toStringHelper (WeightedRoundRobinPicker .class )
305- .add ("enableOobLoadReport" , enableOobLoadReport )
306- .add ("errorUtilizationPenalty" , errorUtilizationPenalty )
307- .add ("list" , list ).toString ();
305+ .add ("enableOobLoadReport" , enableOobLoadReport )
306+ .add ("errorUtilizationPenalty" , errorUtilizationPenalty )
307+ .add ("list" , list ).toString ();
308308 }
309309
310310 @ VisibleForTesting
@@ -323,8 +323,8 @@ public boolean isEquivalentTo(RoundRobinPicker picker) {
323323 }
324324 // the lists cannot contain duplicate subchannels
325325 return enableOobLoadReport == other .enableOobLoadReport
326- && Float .compare (errorUtilizationPenalty , other .errorUtilizationPenalty ) == 0
327- && list .size () == other .list .size () && new HashSet <>(list ).containsAll (other .list );
326+ && Float .compare (errorUtilizationPenalty , other .errorUtilizationPenalty ) == 0
327+ && list .size () == other .list .size () && new HashSet <>(list ).containsAll (other .list );
328328 }
329329 }
330330
0 commit comments