Class LoadBalancerProvider
- java.lang.Object
-
- io.grpc.LoadBalancer.Factory
-
- io.grpc.LoadBalancerProvider
-
@ExperimentalApi("https://github.com/grpc/grpc-java/issues/1771") public abstract class LoadBalancerProvider extends LoadBalancer.Factory
Provider ofLoadBalancer
s. Each provider is bounded to a load-balancing policy name.Implementations can be automatically discovered by gRPC via Java's SPI mechanism. For automatic discovery, the implementation must have a zero-argument constructor and include a resource named
META-INF/services/io.grpc.LoadBalancerProvider
in their JAR. The file's contents should be the implementation's class name. Implementations that need arguments in their constructor can be manually registered byLoadBalancerRegistry.register(io.grpc.LoadBalancerProvider)
.Implementations should not throw. If they do, it may interrupt class loading. If exceptions may reasonably occur for implementation-specific reasons, implementations should generally handle the exception gracefully and return
false
fromisAvailable()
.- Since:
- 1.17.0
-
-
Constructor Summary
Constructors Constructor Description LoadBalancerProvider()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description boolean
equals(Object other)
Uses identity equality.abstract String
getPolicyName()
Returns the load-balancing policy name associated with this provider, which makes it selectable viaLoadBalancerRegistry.getProvider(java.lang.String)
.abstract int
getPriority()
A priority, from 0 to 10 that this provider should be used, taking the current environment into consideration.int
hashCode()
abstract boolean
isAvailable()
Whether this provider is available for use, taking the current environment into consideration.NameResolver.ConfigOrError
parseLoadBalancingPolicyConfig(Map<String,?> rawLoadBalancingPolicyConfig)
Parses the config for the Load Balancing policy unpacked from the service config.String
toString()
-
Methods inherited from class io.grpc.LoadBalancer.Factory
newLoadBalancer
-
-
-
-
Method Detail
-
isAvailable
public abstract boolean isAvailable()
Whether 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.
-
getPriority
public abstract int getPriority()
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.
-
getPolicyName
public abstract String getPolicyName()
Returns 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.
-
parseLoadBalancingPolicyConfig
public NameResolver.ConfigOrError parseLoadBalancingPolicyConfig(Map<String,?> rawLoadBalancingPolicyConfig)
Parses the config for the Load Balancing policy unpacked from the service config. This will return aNameResolver.ConfigOrError
which contains either the successfully parsed config, or theStatus
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.- Parameters:
rawLoadBalancingPolicyConfig
- TheMap
representation of the load balancing policy choice.- Returns:
- a tuple of the fully parsed and validated balancer configuration, else the Status.
- Since:
- 1.20.0
- See Also:
- A24-lb-policy-config.md
-
equals
public final boolean equals(Object other)
Uses identity equality.
-
-