Package io.grpc.internal
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 Summary
Fields Modifier and Type Field Description private static booleanenableNewPickFirststatic java.lang.StringGRPC_PF_USE_HAPPY_EYEBALLSprivate static java.lang.StringSHUFFLE_ADDRESS_LIST_KEY
-
Constructor Summary
Constructors Constructor Description PickFirstLoadBalancerProvider()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private static java.lang.ObjectgetLbPolicyConfig(java.util.Map<java.lang.String,?> rawLbPolicyConfig)java.lang.StringgetPolicyName()Returns the load-balancing policy name associated with this provider, which makes it selectable viaLoadBalancerRegistry.getProvider(java.lang.String).intgetPriority()A priority, from 0 to 10 that this provider should be used, taking the current environment into consideration.booleanisAvailable()Whether this provider is available for use, taking the current environment into consideration.static booleanisEnabledHappyEyeballs()static booleanisEnabledNewPickFirst()LoadBalancernewLoadBalancer(LoadBalancer.Helper helper)Creates aLoadBalancerthat will be used inside a channel.NameResolver.ConfigOrErrorparseLoadBalancingPolicyConfig(java.util.Map<java.lang.String,?> rawLbPolicyConfig)Parses the config for the Load Balancing policy unpacked from the service config.-
Methods inherited from class io.grpc.LoadBalancerProvider
equals, hashCode, toString
-
-
-
-
Field Detail
-
GRPC_PF_USE_HAPPY_EYEBALLS
public static final java.lang.String GRPC_PF_USE_HAPPY_EYEBALLS
- See Also:
- Constant Field Values
-
SHUFFLE_ADDRESS_LIST_KEY
private static final java.lang.String SHUFFLE_ADDRESS_LIST_KEY
- See Also:
- Constant Field Values
-
enableNewPickFirst
private static boolean enableNewPickFirst
-
-
Method Detail
-
isEnabledHappyEyeballs
public static boolean isEnabledHappyEyeballs()
-
isAvailable
public boolean isAvailable()
Description copied from class:LoadBalancerProviderWhether this provider is available for use, taking the current environment into consideration. Iffalse,LoadBalancer.Factory.newLoadBalancer(io.grpc.LoadBalancer.Helper)is not safe to be called.- Specified by:
isAvailablein classLoadBalancerProvider
-
getPriority
public int getPriority()
Description copied from class:LoadBalancerProviderA 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:
getPriorityin classLoadBalancerProvider
-
getPolicyName
public java.lang.String getPolicyName()
Description copied from class:LoadBalancerProviderReturns the load-balancing policy name associated with this provider, which makes it selectable viaLoadBalancerRegistry.getProvider(java.lang.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:
getPolicyNamein classLoadBalancerProvider
-
newLoadBalancer
public LoadBalancer newLoadBalancer(LoadBalancer.Helper helper)
Description copied from class:LoadBalancer.FactoryCreates aLoadBalancerthat will be used inside a channel.- Specified by:
newLoadBalancerin classLoadBalancer.Factory
-
parseLoadBalancingPolicyConfig
public NameResolver.ConfigOrError parseLoadBalancingPolicyConfig(java.util.Map<java.lang.String,?> rawLbPolicyConfig)
Description copied from class:LoadBalancerProviderParses the config for the Load Balancing policy unpacked from the service config. This will return aNameResolver.ConfigOrErrorwhich contains either the successfully parsed config, or theStatusrepresenting 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:
parseLoadBalancingPolicyConfigin classLoadBalancerProvider- Parameters:
rawLbPolicyConfig- TheMaprepresentation of the load balancing policy choice.- Returns:
- a tuple of the fully parsed and validated balancer configuration, else the Status.
- See Also:
- A24-lb-policy-config.md
-
getLbPolicyConfig
private static java.lang.Object getLbPolicyConfig(java.util.Map<java.lang.String,?> rawLbPolicyConfig)
-
isEnabledNewPickFirst
public static boolean isEnabledNewPickFirst()
-
-