Top Description Inners Fields Constructors Methods
io.grpc

public final Class LoadBalancerRegistry

extends Object
Class Inheritance
Annotations
@ExperimentalApi:https://github.com/grpc/grpc-java/issues/1771
@ThreadSafe
Static Imports
com.google.common.base.Preconditions.checkArgument, .Preconditions.checkNotNull

Registry of LoadBalancerProviders. The default instance loads providers at runtime through the Java service provider mechanism.
Since
1.17.0

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class

Field Summary

Modifier and TypeField and Description
private final LinkedHashSet<LoadBalancerProvider>
private final LinkedHashMap<String, LoadBalancerProvider>
private static final Iterable<Class<?>>
private static LoadBalancerRegistry
private static final Logger

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
private synchronized void
public synchronized void
deregister(LoadBalancerProvider
the provider that was added to the register via register.
provider
)

Deregisters a provider.

public static synchronized LoadBalancerRegistry
getDefaultRegistry()

Returns the default registry that loads providers via the Java service loader mechanism.

pack-priv static List<Class<?>>
public synchronized LoadBalancerProvider
getProvider(String policy)

Returns the effective provider for the given load-balancing policy, or null if no suitable provider can be found.

pack-priv synchronized Map<String, LoadBalancerProvider>
providers()

Returns effective providers in a new map.

private synchronized void
public synchronized void
register(LoadBalancerProvider provider)

Register a provider.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

allProvidersback to summary
private final LinkedHashSet<LoadBalancerProvider> allProviders
effectiveProvidersback to summary
private final LinkedHashMap<String, LoadBalancerProvider> effectiveProviders
HARDCODED_CLASSESback to summary
private static final Iterable<Class<?>> HARDCODED_CLASSES
instanceback to summary
private static LoadBalancerRegistry instance
loggerback to summary
private static final Logger logger

Constructor Detail

LoadBalancerRegistryback to summary
public LoadBalancerRegistry()

Method Detail

addProviderback to summary
private synchronized void addProvider(LoadBalancerProvider provider)
deregisterback to summary
public synchronized 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 in register.

Parameters
provider:LoadBalancerProvider

the provider that was added to the register via register.

getDefaultRegistryback to summary
public static synchronized LoadBalancerRegistry getDefaultRegistry()

Returns the default registry that loads providers via the Java service loader mechanism.

getHardCodedClassesback to summary
pack-priv static List<Class<?>> getHardCodedClasses()
Annotations
@VisibleForTesting
getProviderback to summary
public synchronized LoadBalancerProvider getProvider(String policy)

Returns the effective provider for the given load-balancing policy, or null if no suitable provider can be found. Each provider declares its policy name via LoadBalancerProvider#getPolicyName.

Annotations
@Nullable
providersback to summary
pack-priv synchronized Map<String, LoadBalancerProvider> providers()

Returns effective providers in a new map.

Annotations
@VisibleForTesting
refreshProviderMapback to summary
private synchronized void refreshProviderMap()
registerback to summary
public synchronized void register(LoadBalancerProvider provider)

Register a provider.

If the provider's isAvailable() returns false, this method will throw IllegalArgumentException.

If more than one provider with the same policy name are registered, the one with the highest priority will be effective. If there are more than one name-sake providers rank the highest priority, the one registered first will be effective.

io.grpc back to summary

private final Class LoadBalancerRegistry.LoadBalancerPriorityAccessor

extends Object
implements ServiceProviders.PriorityAccessor<LoadBalancerProvider>
Class Inheritance
All Implemented Interfaces
io.grpc.ServiceProviders.PriorityAccessor

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public int
getPriority(LoadBalancerProvider provider)

Implements io.grpc.ServiceProviders.PriorityAccessor.getPriority.

A priority, from 0 to 10 that this provider should be used, taking the current environment into consideration.
public boolean
isAvailable(LoadBalancerProvider provider)

Implements io.grpc.ServiceProviders.PriorityAccessor.isAvailable.

Checks this provider is available for use, taking the current environment into consideration.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

LoadBalancerPriorityAccessorback to summary
pack-priv LoadBalancerPriorityAccessor()

Method Detail

getPriorityback to summary
public int getPriority(LoadBalancerProvider provider)

Implements io.grpc.ServiceProviders.PriorityAccessor.getPriority.

Doc from io.grpc.ServiceProviders.PriorityAccessor.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.

Annotations
@Override
isAvailableback to summary
public boolean isAvailable(LoadBalancerProvider provider)

Implements io.grpc.ServiceProviders.PriorityAccessor.isAvailable.

Doc from io.grpc.ServiceProviders.PriorityAccessor.isAvailable.

Checks this provider is available for use, taking the current environment into consideration. If false, no other methods are safe to be called.

Annotations
@Override