Package io.grpc.util

Class GracefulSwitchLoadBalancer


  • @ExperimentalApi("https://github.com/grpc/grpc-java/issues/5999")
    @NotThreadSafe
    public final class GracefulSwitchLoadBalancer
    extends ForwardingLoadBalancer
    A 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 a provider's parseLoadBalancingPolicyConfig() implementation.

    Alternatively, the balancer may switch to a policy prior to handling resolved addresses for 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
    • Field Summary

      • Fields inherited from class io.grpc.LoadBalancer

        ATTR_HEALTH_CHECKING_CONFIG, EMPTY_PICKER, HAS_HEALTH_PRODUCER_LISTENER_KEY, HEALTH_CONSUMER_LISTENER_ARG_KEY, IS_PETIOLE_POLICY
    • Constructor Detail

      • GracefulSwitchLoadBalancer

        public GracefulSwitchLoadBalancer​(io.grpc.LoadBalancer.Helper helper)
    • Method Detail

      • acceptResolvedAddresses

        public io.grpc.Status acceptResolvedAddresses​(io.grpc.LoadBalancer.ResolvedAddresses resolvedAddresses)
        Overrides:
        acceptResolvedAddresses in class io.grpc.LoadBalancer
      • switchTo

        @Deprecated
        public void switchTo​(io.grpc.LoadBalancer.Factory newBalancerFactory)
        Deprecated.
        Use parseLoadBalancingPolicyConfig() and pass the configuration to LoadBalancer.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.
      • 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.
      • createLoadBalancingPolicyConfig

        public static Object createLoadBalancingPolicyConfig​(io.grpc.LoadBalancer.Factory childFactory,
                                                             @Nullable
                                                             Object childConfig)
        Directly create a config to pass to GracefulSwitch. The object returned is the same as would be found in ConfigOrError.getConfig().