Class NameResolver
- java.lang.Object
-
- io.grpc.NameResolver
-
@ExperimentalApi("https://github.com/grpc/grpc-java/issues/1770") public abstract class NameResolver extends Object
A pluggable component that resolves a targetURIand return addresses to the caller.A
NameResolveruses the URI's scheme to determine whether it can resolve it, and uses the components after the scheme for actual resolution.The addresses and attributes of a target may be changed over time, thus the caller registers a
NameResolver.Listenerto receive continuous updates.A
NameResolverdoes not need to automatically re-resolve on failure. Instead, theNameResolver.Listeneris responsible for eventually (after an appropriate backoff period) invokingrefresh().Implementations don't need to be thread-safe. All methods are guaranteed to be called sequentially. Additionally, all methods that have side-effects, i.e.,
start(Listener2),shutdown()andrefresh()are called from the sameSynchronizationContextas returned byNameResolver.Args.getSynchronizationContext(). Do not block within the synchronization context; blocking I/O and time-consuming tasks should be offloaded to a separate thread, generallyNameResolver.Args.getOffloadExecutor().- Since:
- 1.0.0
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classNameResolver.ArgsInformation that aNameResolver.Factoryuses to create aNameResolver.static classNameResolver.ConfigOrErrorRepresents either a successfully parsed service config, containing all necessary parts to be later applied by the channel, or a Status containing the error encountered while parsing.static classNameResolver.FactoryFactory that createsNameResolverinstances.static interfaceNameResolver.ListenerReceives address updates.static classNameResolver.Listener2Receives address updates.static classNameResolver.ResolutionResultRepresents the results from a Name Resolver.static interfaceNameResolver.ResolutionResultAttrAnnotation for name resolution result attributes.static classNameResolver.ServiceConfigParserParses and validates service configuration.
-
Field Summary
Fields Modifier and Type Field Description static Attributes.Key<String>ATTR_BACKEND_SERVICE
-
Constructor Summary
Constructors Constructor Description NameResolver()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract StringgetServiceAuthority()Returns the authority used to authenticate connections to servers.voidrefresh()Re-resolve the name.abstract voidshutdown()Stops the resolution.voidstart(NameResolver.Listener listener)Starts the resolution.voidstart(NameResolver.Listener2 listener)Starts the resolution.
-
-
-
Field Detail
-
ATTR_BACKEND_SERVICE
@ExperimentalApi("https://github.com/grpc/grpc-java/issues/11989") @ResolutionResultAttr public static final Attributes.Key<String> ATTR_BACKEND_SERVICE
-
-
Method Detail
-
getServiceAuthority
public abstract String getServiceAuthority()
Returns the authority used to authenticate connections to servers. It must be from a trusted source, because if the authority is tampered with, RPCs may be sent to the attackers which may leak sensitive user data.An implementation must generate it without blocking, typically in line, and must keep it unchanged.
NameResolvers created from the same factory with the same argument must return the same authority.- Since:
- 1.0.0
-
start
public void start(NameResolver.Listener listener)
Starts the resolution. The method is not supposed to throw any exceptions. That might cause the Channel that the name resolver is serving to crash. Errors should be propagated throughNameResolver.Listener.onError(io.grpc.Status).An instance may not be started more than once, by any overload of this method, even after an intervening call to
shutdown().- Parameters:
listener- used to receive updates on the target- Since:
- 1.0.0
-
start
public void start(NameResolver.Listener2 listener)
Starts the resolution. The method is not supposed to throw any exceptions. That might cause the Channel that the name resolver is serving to crash. Errors should be propagated throughNameResolver.Listener2.onError(io.grpc.Status).An instance may not be started more than once, by any overload of this method, even after an intervening call to
shutdown().- Parameters:
listener- used to receive updates on the target- Since:
- 1.21.0
-
shutdown
public abstract void shutdown()
Stops the resolution. Updates to the Listener will stop.- Since:
- 1.0.0
-
refresh
public void refresh()
Re-resolve the name.Can only be called after
start(io.grpc.NameResolver.Listener)has been called.This is only a hint. Implementation takes it as a signal but may not start resolution immediately. It should never throw.
The default implementation is no-op.
- Since:
- 1.0.0
-
-