Class PickFirstLoadBalancerProvider

java.lang.Object
io.grpc.LoadBalancer.Factory
io.grpc.LoadBalancerProvider
io.grpc.internal.PickFirstLoadBalancerProvider

public final class PickFirstLoadBalancerProvider extends LoadBalancerProvider
Provider for the "pick_first" balancing policy.

This provides no load-balancing over the addresses from the NameResolver. It walks down the address list and sticks to the first that works.

  • Field Details

    • GRPC_PF_USE_HAPPY_EYEBALLS

      public static final String GRPC_PF_USE_HAPPY_EYEBALLS
      See Also:
    • SHUFFLE_ADDRESS_LIST_KEY

      private static final String SHUFFLE_ADDRESS_LIST_KEY
      See Also:
    • enableNewPickFirst

      private static boolean enableNewPickFirst
  • Constructor Details

    • PickFirstLoadBalancerProvider

      public PickFirstLoadBalancerProvider()
  • Method Details

    • isEnabledHappyEyeballs

      public static boolean isEnabledHappyEyeballs()
    • isAvailable

      public boolean isAvailable()
      Description copied from class: LoadBalancerProvider
      Whether this provider is available for use, taking the current environment into consideration. If false, LoadBalancer.Factory.newLoadBalancer(LoadBalancer.Helper) is not safe to be called.
      Specified by:
      isAvailable in class LoadBalancerProvider
    • getPriority

      public int getPriority()
      Description copied from class: LoadBalancerProvider
      A priority, from 0 to 10 that this provider should be used, taking the current environment into consideration. 5 should be considered the default, and then tweaked based on environment detection. A priority of 0 does not imply that the provider wouldn't work; just that it should be last in line.
      Specified by:
      getPriority in class LoadBalancerProvider
    • getPolicyName

      public String getPolicyName()
      Description copied from class: LoadBalancerProvider
      Returns the load-balancing policy name associated with this provider, which makes it selectable via LoadBalancerRegistry.getProvider(String). This is called only when the class is loaded. It shouldn't change, and there is no point doing so.

      The policy name should consist of only lower case letters letters, underscore and digits, and can only start with letters.

      Specified by:
      getPolicyName in class LoadBalancerProvider
    • newLoadBalancer

      public LoadBalancer newLoadBalancer(LoadBalancer.Helper helper)
      Description copied from class: LoadBalancer.Factory
      Creates a LoadBalancer that will be used inside a channel.
      Specified by:
      newLoadBalancer in class LoadBalancer.Factory
    • parseLoadBalancingPolicyConfig

      public NameResolver.ConfigOrError parseLoadBalancingPolicyConfig(Map<String,?> rawLbPolicyConfig)
      Description copied from class: LoadBalancerProvider
      Parses the config for the Load Balancing policy unpacked from the service config. This will return a NameResolver.ConfigOrError which contains either the successfully parsed config, or the Status representing the failure to parse. Implementations are expected to not throw exceptions but return a Status representing the failure. If successful, the load balancing policy config should be immutable.
      Overrides:
      parseLoadBalancingPolicyConfig in class LoadBalancerProvider
      Parameters:
      rawLbPolicyConfig - The Map representation of the load balancing policy choice.
      Returns:
      a tuple of the fully parsed and validated balancer configuration, else the Status.
      See Also:
    • getLbPolicyConfig

      private static Object getLbPolicyConfig(Map<String,?> rawLbPolicyConfig)
    • isEnabledNewPickFirst

      public static boolean isEnabledNewPickFirst()