@@ -322,17 +322,11 @@ public void updateBalancingState(final ConnectivityState newState,
322322 }
323323 ConnectivityState oldState = connectivityState ;
324324 connectivityState = newState ;
325- picker = new SubchannelPicker () {
326- @ Override
327- public PickResult pickSubchannel (PickSubchannelArgs args ) {
328- PickResult childResult = newPicker .pickSubchannel (args );
329- if (!childResult .hasResult () && childResult .getDelayReasonToken () != null ) {
330- return PickResult .withNoResult (
331- "priority_" + priority + ":" + childResult .getDelayReasonToken ());
332- }
333- return childResult ;
334- }
335- };
325+ if (newState == CONNECTING || newState == IDLE ) {
326+ picker = new PriorityPicker (newPicker , priority );
327+ } else {
328+ picker = newPicker ;
329+ }
336330
337331 if (deletionTimer != null && deletionTimer .isPending ()) {
338332 return ;
@@ -367,4 +361,41 @@ protected Helper delegate() {
367361 }
368362 }
369363 }
364+
365+ private static final class PriorityPicker extends SubchannelPicker {
366+ private final SubchannelPicker delegate ;
367+ private final String priority ;
368+
369+ PriorityPicker (SubchannelPicker delegate , String priority ) {
370+ this .delegate = com .google .common .base .Preconditions .checkNotNull (delegate , "delegate" );
371+ this .priority = com .google .common .base .Preconditions .checkNotNull (priority , "priority" );
372+ }
373+
374+ @ Override
375+ public PickResult pickSubchannel (PickSubchannelArgs args ) {
376+ PickResult childResult = delegate .pickSubchannel (args );
377+ if (!childResult .hasResult () && childResult .getDelayReasonToken () != null ) {
378+ return PickResult .withNoResult (
379+ "priority_" + priority + ":" + childResult .getDelayReasonToken ());
380+ }
381+ return childResult ;
382+ }
383+
384+ @ Override
385+ public boolean equals (Object o ) {
386+ if (this == o ) {
387+ return true ;
388+ }
389+ if (o == null || getClass () != o .getClass ()) {
390+ return false ;
391+ }
392+ PriorityPicker that = (PriorityPicker ) o ;
393+ return delegate .equals (that .delegate ) && priority .equals (that .priority );
394+ }
395+
396+ @ Override
397+ public int hashCode () {
398+ return java .util .Objects .hash (delegate , priority );
399+ }
400+ }
370401}
0 commit comments