44
44
* generally created by calling {@link #parseLoadBalancingPolicyConfig(List)} from a
45
45
* {@link io.grpc.LoadBalancerProvider#parseLoadBalancingPolicyConfig
46
46
* provider's parseLoadBalancingPolicyConfig()} implementation.
47
- *
48
- * <p>Alternatively, the balancer may {@link #switchTo(LoadBalancer.Factory) switch to} a policy
49
- * prior to {@link
50
- * LoadBalancer#handleResolvedAddresses(ResolvedAddresses) handling resolved addresses} for the
51
- * first time. This causes graceful switch to ignore the service config and pass through the
52
- * resolved addresses directly to the child policy.
53
47
*/
54
48
@ ExperimentalApi ("https://github.com/grpc/grpc-java/issues/5999" )
55
49
@ NotThreadSafe // Must be accessed in SynchronizationContext
56
50
public final class GracefulSwitchLoadBalancer extends ForwardingLoadBalancer {
57
51
private final LoadBalancer defaultBalancer = new LoadBalancer () {
58
52
@ Override
59
- public void handleResolvedAddresses (ResolvedAddresses resolvedAddresses ) {
60
- // Most LB policies using this class will receive child policy configuration within the
61
- // service config, so they are naturally calling switchTo() just before
62
- // handleResolvedAddresses(), within their own handleResolvedAddresses(). If switchTo() is
63
- // not called immediately after construction that does open up potential for bugs in the
64
- // parent policies, where they fail to call switchTo(). So we will use the exception to try
65
- // to notice those bugs quickly, as it will fail very loudly.
66
- throw new IllegalStateException (
67
- "GracefulSwitchLoadBalancer must switch to a load balancing policy before handling"
68
- + " ResolvedAddresses" );
53
+ public Status acceptResolvedAddresses (ResolvedAddresses resolvedAddresses ) {
54
+ throw new AssertionError ("real LB is called instead" );
69
55
}
70
56
71
57
@ Override
@@ -104,7 +90,6 @@ public String toString() {
104
90
private LoadBalancer pendingLb = defaultBalancer ;
105
91
private ConnectivityState pendingState ;
106
92
private SubchannelPicker pendingPicker ;
107
- private boolean switchToCalled ;
108
93
109
94
private boolean currentLbIsReady ;
110
95
@@ -114,10 +99,6 @@ public GracefulSwitchLoadBalancer(Helper helper) {
114
99
115
100
@ Override
116
101
public void handleResolvedAddresses (ResolvedAddresses resolvedAddresses ) {
117
- if (switchToCalled ) {
118
- delegate ().handleResolvedAddresses (resolvedAddresses );
119
- return ;
120
- }
121
102
Config config = (Config ) resolvedAddresses .getLoadBalancingPolicyConfig ();
122
103
switchToInternal (config .childFactory );
123
104
delegate ().handleResolvedAddresses (
@@ -128,9 +109,6 @@ public void handleResolvedAddresses(ResolvedAddresses resolvedAddresses) {
128
109
129
110
@ Override
130
111
public Status acceptResolvedAddresses (ResolvedAddresses resolvedAddresses ) {
131
- if (switchToCalled ) {
132
- return delegate ().acceptResolvedAddresses (resolvedAddresses );
133
- }
134
112
Config config = (Config ) resolvedAddresses .getLoadBalancingPolicyConfig ();
135
113
switchToInternal (config .childFactory );
136
114
return delegate ().acceptResolvedAddresses (
@@ -139,19 +117,6 @@ public Status acceptResolvedAddresses(ResolvedAddresses resolvedAddresses) {
139
117
.build ());
140
118
}
141
119
142
- /**
143
- * Gracefully switch to a new policy defined by the given factory, if the given factory isn't
144
- * equal to the current one.
145
- *
146
- * @deprecated Use {@code parseLoadBalancingPolicyConfig()} and pass the configuration to
147
- * {@link io.grpc.LoadBalancer.ResolvedAddresses.Builder#setLoadBalancingPolicyConfig}
148
- */
149
- @ Deprecated
150
- public void switchTo (LoadBalancer .Factory newBalancerFactory ) {
151
- switchToCalled = true ;
152
- switchToInternal (newBalancerFactory );
153
- }
154
-
155
120
private void switchToInternal (LoadBalancer .Factory newBalancerFactory ) {
156
121
checkNotNull (newBalancerFactory , "newBalancerFactory" );
157
122
0 commit comments