Package io.grpc.util
Class GracefulSwitchLoadBalancer
- java.lang.Object
-
- io.grpc.LoadBalancer
-
- io.grpc.util.ForwardingLoadBalancer
-
- io.grpc.util.GracefulSwitchLoadBalancer
-
@ExperimentalApi("https://github.com/grpc/grpc-java/issues/5999") @NotThreadSafe public final class GracefulSwitchLoadBalancer extends ForwardingLoadBalancerA load balancer that gracefully swaps to a new lb policy. If the channel is currently in a state other than READY, the new policy will be swapped into place immediately. Otherwise, the channel will keep using the old policy until the new policy reports READY or the old policy exits READY.The child balancer and configuration is specified using service config. Config objects are generally created by calling
parseLoadBalancingPolicyConfig(List)from aprovider's parseLoadBalancingPolicyConfig()implementation.Alternatively, the balancer may
switch toa policy prior tohandling resolved addressesfor the first time. This causes graceful switch to ignore the service config and pass through the resolved addresses directly to the child policy.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class io.grpc.LoadBalancer
io.grpc.LoadBalancer.CreateSubchannelArgs, io.grpc.LoadBalancer.ErrorPicker, io.grpc.LoadBalancer.Factory, io.grpc.LoadBalancer.FixedResultPicker, io.grpc.LoadBalancer.Helper, io.grpc.LoadBalancer.PickDetailsConsumer, io.grpc.LoadBalancer.PickResult, io.grpc.LoadBalancer.PickSubchannelArgs, io.grpc.LoadBalancer.ResolvedAddresses, io.grpc.LoadBalancer.Subchannel, io.grpc.LoadBalancer.SubchannelPicker, io.grpc.LoadBalancer.SubchannelStateListener
-
-
Constructor Summary
Constructors Constructor Description GracefulSwitchLoadBalancer(io.grpc.LoadBalancer.Helper helper)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description io.grpc.StatusacceptResolvedAddresses(io.grpc.LoadBalancer.ResolvedAddresses resolvedAddresses)static ObjectcreateLoadBalancingPolicyConfig(io.grpc.LoadBalancer.Factory childFactory, Object childConfig)Directly create a config to pass to GracefulSwitch.protected io.grpc.LoadBalancerdelegate()Returns the underlying balancer.StringdelegateType()voidhandleResolvedAddresses(io.grpc.LoadBalancer.ResolvedAddresses resolvedAddresses)voidhandleSubchannelState(io.grpc.LoadBalancer.Subchannel subchannel, io.grpc.ConnectivityStateInfo stateInfo)Deprecated.static io.grpc.NameResolver.ConfigOrErrorparseLoadBalancingPolicyConfig(List<Map<String,?>> loadBalancingConfigs)Provided a JSON list of LoadBalancingConfigs, parse it into a config to pass to GracefulSwitch.static io.grpc.NameResolver.ConfigOrErrorparseLoadBalancingPolicyConfig(List<Map<String,?>> loadBalancingConfigs, io.grpc.LoadBalancerRegistry lbRegistry)Provided a JSON list of LoadBalancingConfigs, parse it into a config to pass to GracefulSwitch.voidshutdown()voidswitchTo(io.grpc.LoadBalancer.Factory newBalancerFactory)Deprecated.UseparseLoadBalancingPolicyConfig()and pass the configuration toLoadBalancer.ResolvedAddresses.Builder.setLoadBalancingPolicyConfig(java.lang.Object)-
Methods inherited from class io.grpc.util.ForwardingLoadBalancer
canHandleEmptyAddressListFromNameResolution, handleNameResolutionError, requestConnection, toString
-
-
-
-
Method Detail
-
handleResolvedAddresses
public void handleResolvedAddresses(io.grpc.LoadBalancer.ResolvedAddresses resolvedAddresses)
- Overrides:
handleResolvedAddressesin classForwardingLoadBalancer
-
acceptResolvedAddresses
public io.grpc.Status acceptResolvedAddresses(io.grpc.LoadBalancer.ResolvedAddresses resolvedAddresses)
- Overrides:
acceptResolvedAddressesin classio.grpc.LoadBalancer
-
switchTo
@Deprecated public void switchTo(io.grpc.LoadBalancer.Factory newBalancerFactory)
Deprecated.UseparseLoadBalancingPolicyConfig()and pass the configuration toLoadBalancer.ResolvedAddresses.Builder.setLoadBalancingPolicyConfig(java.lang.Object)Gracefully switch to a new policy defined by the given factory, if the given factory isn't equal to the current one.
-
delegate
protected io.grpc.LoadBalancer delegate()
Description copied from class:ForwardingLoadBalancerReturns the underlying balancer.- Specified by:
delegatein classForwardingLoadBalancer
-
handleSubchannelState
@Deprecated public void handleSubchannelState(io.grpc.LoadBalancer.Subchannel subchannel, io.grpc.ConnectivityStateInfo stateInfo)
Deprecated.- Overrides:
handleSubchannelStatein classForwardingLoadBalancer
-
shutdown
public void shutdown()
- Overrides:
shutdownin classForwardingLoadBalancer
-
delegateType
public String delegateType()
-
parseLoadBalancingPolicyConfig
public static io.grpc.NameResolver.ConfigOrError parseLoadBalancingPolicyConfig(List<Map<String,?>> loadBalancingConfigs)
Provided a JSON list of LoadBalancingConfigs, parse it into a config to pass to GracefulSwitch.
-
parseLoadBalancingPolicyConfig
public static io.grpc.NameResolver.ConfigOrError parseLoadBalancingPolicyConfig(List<Map<String,?>> loadBalancingConfigs, io.grpc.LoadBalancerRegistry lbRegistry)
Provided a JSON list of LoadBalancingConfigs, parse it into a config to pass to GracefulSwitch.
-
-