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 java.lang.Object
Registry ofLoadBalancerProvider
s. Thedefault instance
loads providers at runtime through the Java service provider mechanism.- Since:
- 1.17.0
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
LoadBalancerRegistry.LoadBalancerPriorityAccessor
-
Field Summary
Fields Modifier and Type Field Description private java.util.LinkedHashSet<LoadBalancerProvider>
allProviders
private java.util.LinkedHashMap<java.lang.String,LoadBalancerProvider>
effectiveProviders
private static java.lang.Iterable<java.lang.Class<?>>
HARDCODED_CLASSES
private static LoadBalancerRegistry
instance
private static java.util.logging.Logger
logger
-
Constructor Summary
Constructors Constructor Description LoadBalancerRegistry()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private void
addProvider(LoadBalancerProvider provider)
void
deregister(LoadBalancerProvider provider)
Deregisters a provider.static LoadBalancerRegistry
getDefaultRegistry()
Returns the default registry that loads providers via the Java service loader mechanism.(package private) static java.util.List<java.lang.Class<?>>
getHardCodedClasses()
LoadBalancerProvider
getProvider(java.lang.String policy)
Returns the effective provider for the given load-balancing policy, ornull
if no suitable provider can be found.(package private) java.util.Map<java.lang.String,LoadBalancerProvider>
providers()
Returns effective providers in a new map.private void
refreshProviderMap()
void
register(LoadBalancerProvider provider)
Register a provider.
-
-
-
Field Detail
-
logger
private static final java.util.logging.Logger logger
-
instance
private static LoadBalancerRegistry instance
-
HARDCODED_CLASSES
private static final java.lang.Iterable<java.lang.Class<?>> HARDCODED_CLASSES
-
allProviders
private final java.util.LinkedHashSet<LoadBalancerProvider> allProviders
-
effectiveProviders
private final java.util.LinkedHashMap<java.lang.String,LoadBalancerProvider> effectiveProviders
-
-
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.
-
addProvider
private void addProvider(LoadBalancerProvider provider)
-
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)
.
-
refreshProviderMap
private void refreshProviderMap()
-
getDefaultRegistry
public static LoadBalancerRegistry getDefaultRegistry()
Returns the default registry that loads providers via the Java service loader mechanism.
-
getProvider
@Nullable public LoadBalancerProvider getProvider(java.lang.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()
.
-
providers
java.util.Map<java.lang.String,LoadBalancerProvider> providers()
Returns effective providers in a new map.
-
getHardCodedClasses
static java.util.List<java.lang.Class<?>> getHardCodedClasses()
-
-