Top Description Inners Fields Constructors Methods
io.grpc

public final Class NameResolverRegistry

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

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

Nested and Inner Type Summary

Modifier and TypeClass and Description
private class
private static class

Field Summary

Modifier and TypeField and Description
private final LinkedHashSet<NameResolverProvider>
private String
private ImmutableMap<String, NameResolverProvider>
effectiveProviders

Generated from allProviders.

private final NameResolver.Factory
private static NameResolverRegistry
private static final Logger
private static final String

Constructor Summary

AccessConstructor and Description
public

Method Summary

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

Deregisters a provider.

public static synchronized NameResolverRegistry
getDefaultRegistry()

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

public synchronized String
pack-priv static List<Class<?>>
public NameResolverProvider
pack-priv synchronized Map<String, NameResolverProvider>
providers()

Returns effective providers map from scheme to the highest priority NameResolverProvider of that scheme.

private synchronized void
public synchronized void
register(NameResolverProvider provider)

Register a provider.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

allProvidersback to summary
private final LinkedHashSet<NameResolverProvider> allProviders
Annotations
@GuardedBy:this
defaultSchemeback to summary
private String defaultScheme
Annotations
@GuardedBy:this
effectiveProvidersback to summary
private ImmutableMap<String, NameResolverProvider> effectiveProviders

Generated from allProviders. Is mapping from scheme key to the highest priority NameResolverProvider. Is replaced instead of mutating.

Annotations
@GuardedBy:this
factoryback to summary
private final NameResolver.Factory factory
instanceback to summary
private static NameResolverRegistry instance
loggerback to summary
private static final Logger logger
UNKNOWN_SCHEMEback to summary
private static final String UNKNOWN_SCHEME

Constructor Detail

NameResolverRegistryback to summary
public NameResolverRegistry()

Method Detail

addProviderback to summary
private synchronized void addProvider(NameResolverProvider provider)
asFactoryback to summary
public NameResolver.Factory asFactory()
deregisterback to summary
public synchronized void deregister(NameResolverProvider provider)

Deregisters a provider. No-op if the provider is not in the registry.

Parameters
provider:NameResolverProvider

the provider that was added to the register via register.

getDefaultRegistryback to summary
public static synchronized NameResolverRegistry getDefaultRegistry()

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

getDefaultSchemeback to summary
public synchronized String getDefaultScheme()
getHardCodedClassesback to summary
pack-priv static List<Class<?>> getHardCodedClasses()
Annotations
@VisibleForTesting
getProviderForSchemeback to summary
public NameResolverProvider getProviderForScheme(String scheme)
providersback to summary
pack-priv synchronized Map<String, NameResolverProvider> providers()

Returns effective providers map from scheme to the highest priority NameResolverProvider of that scheme.

Annotations
@VisibleForTesting
refreshProvidersback to summary
private synchronized void refreshProviders()
registerback to summary
public synchronized void register(NameResolverProvider provider)

Register a provider.

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

Providers will be used in priority order. In case of ties, providers are used in registration order.

io.grpc back to summary

private final Class NameResolverRegistry.NameResolverFactory

extends Factory
Class Inheritance

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public String
getDefaultScheme()

Implements abstract io.grpc.NameResolver.Factory.getDefaultScheme.

Returns the default scheme, which will be used to construct a URI when ManagedChannelBuilder#forTarget(String) is given an authority string instead of a compliant URI.
public NameResolver
newNameResolver(URI
the target URI to be resolved, whose scheme must not be null
targetUri
,
NameResolver.Args
other information that may be useful
args
)

Implements abstract io.grpc.NameResolver.Factory.newNameResolver.

Creates a NameResolver for the given target URI, or null if the given URI cannot be resolved by this factory.

Constructor Detail

NameResolverFactoryback to summary
private NameResolverFactory()

Method Detail

getDefaultSchemeback to summary
public String getDefaultScheme()

Implements abstract io.grpc.NameResolver.Factory.getDefaultScheme.

Doc from io.grpc.NameResolver.Factory.getDefaultScheme.

Returns the default scheme, which will be used to construct a URI when ManagedChannelBuilder#forTarget(String) is given an authority string instead of a compliant URI.

Annotations
@Override
newNameResolverback to summary
public NameResolver newNameResolver(URI targetUri, NameResolver.Args args)

Implements abstract io.grpc.NameResolver.Factory.newNameResolver.

Doc from io.grpc.NameResolver.Factory.newNameResolver.

Creates a NameResolver for the given target URI, or null if the given URI cannot be resolved by this factory. The decision should be solely based on the scheme of the URI.

Parameters
targetUri:URI

the target URI to be resolved, whose scheme must not be null

args:NameResolver.Args

other information that may be useful

Annotations
@Override
@Nullable
io.grpc back to summary

private final Class NameResolverRegistry.NameResolverPriorityAccessor

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

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public int
getPriority(NameResolverProvider 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(NameResolverProvider 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

NameResolverPriorityAccessorback to summary
private NameResolverPriorityAccessor()

Method Detail

getPriorityback to summary
public int getPriority(NameResolverProvider 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(NameResolverProvider 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