@ExperimentalApi(value="https://github.com/grpc/grpc-java/issues/1770") public abstract class NameResolver extends Object
URI
and return addresses to the caller.
A NameResolver
uses 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.Listener
to receive continuous updates.
A NameResolver
does not need to automatically re-resolve on failure. Instead, the
NameResolver.Listener
is responsible for eventually (after an appropriate backoff period) invoking
refresh()
.
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()
and refresh()
are called from the same
SynchronizationContext
as returned by NameResolver.Args.getSynchronizationContext()
. Do
not block within the synchronization context; blocking I/O and time-consuming tasks
should be offloaded to a separate thread, generally NameResolver.Args.getOffloadExecutor()
.
Modifier and Type | Class and Description |
---|---|
static class |
NameResolver.Args
Information that a
NameResolver.Factory uses to create a NameResolver . |
static class |
NameResolver.ConfigOrError
Represents 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 class |
NameResolver.Factory
Factory that creates
NameResolver instances. |
static interface |
NameResolver.Listener
Receives address updates.
|
static class |
NameResolver.Listener2
Receives address updates.
|
static class |
NameResolver.ResolutionResult
Represents the results from a Name Resolver.
|
static interface |
NameResolver.ResolutionResultAttr
Annotation for name resolution result attributes.
|
static class |
NameResolver.ServiceConfigParser
Parses and validates service configuration.
|
Constructor and Description |
---|
NameResolver() |
Modifier and Type | Method and Description |
---|---|
abstract String |
getServiceAuthority()
Returns the authority used to authenticate connections to servers.
|
void |
refresh()
Re-resolve the name.
|
abstract void |
shutdown()
Stops the resolution.
|
void |
start(NameResolver.Listener listener)
Starts the resolution.
|
void |
start(NameResolver.Listener2 listener)
Starts the resolution.
|
public abstract String getServiceAuthority()
An implementation must generate it without blocking, typically in line, and
must keep it unchanged. NameResolver
s created from the same factory
with the same argument must return the same authority.
public void start(NameResolver.Listener listener)
listener
- used to receive updates on the targetpublic void start(NameResolver.Listener2 listener)
listener
- used to receive updates on the targetpublic abstract void shutdown()
public void refresh()
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.