Package io.grpc
Class LoadBalancerRegistry
- java.lang.Object
-
- io.grpc.LoadBalancerRegistry
-
@ExperimentalApi("https://github.com/grpc/grpc-java/issues/1771") @ThreadSafe public final class LoadBalancerRegistry extends Object
Registry ofLoadBalancerProvider
s. Thedefault instance
loads providers at runtime through the Java service provider mechanism.- Since:
- 1.17.0
-
-
Constructor Summary
Constructors Constructor Description LoadBalancerRegistry()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
deregister(LoadBalancerProvider provider)
Deregisters a provider.static LoadBalancerRegistry
getDefaultRegistry()
Returns the default registry that loads providers via the Java service loader mechanism.LoadBalancerProvider
getProvider(String policy)
Returns the effective provider for the given load-balancing policy, ornull
if no suitable provider can be found.void
register(LoadBalancerProvider provider)
Register a provider.
-
-
-
Method Detail
-
register
public void register(LoadBalancerProvider provider)
Register a provider.If the provider's
isAvailable()
returnsfalse
, this method will throwIllegalArgumentException
.If more than one provider with the same
policy name
are registered, the one with the highestpriority
will be effective. If there are more than one name-sake providers rank the highest priority, the one registered first will be effective.
-
deregister
public void deregister(LoadBalancerProvider provider)
Deregisters a provider. No-op if the provider is not in the registry. If there are more than one providers with the same policy name as the deregistered one in the registry, one of them will become the effective provider for that policy, per the rule documented inregister(io.grpc.LoadBalancerProvider)
.- Parameters:
provider
- the provider that was added to the register viaregister(io.grpc.LoadBalancerProvider)
.
-
getDefaultRegistry
public static LoadBalancerRegistry getDefaultRegistry()
Returns the default registry that loads providers via the Java service loader mechanism.
-
getProvider
@Nullable public LoadBalancerProvider getProvider(String policy)
Returns the effective provider for the given load-balancing policy, ornull
if no suitable provider can be found. Each provider declares its policy name viaLoadBalancerProvider.getPolicyName()
.
-
-