Class DnsNameResolver
- Direct Known Subclasses:
GrpclbNameResolver
NameResolver
.
Each A
or AAAA
record emits an EquivalentAddressGroup
in the list
passed to NameResolver.Listener2.onResult2(ResolutionResult)
.
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interface
AddressResolver resolves a hostname into a list of addresses.protected static final class
Used as a DNS-based name resolver's internal representation of resolution result.private static enum
private final class
static interface
DnsNameResolver.ResourceResolver
is a Dns ResourceRecord resolver.(package private) static interface
DnsNameResolver.ResourceResolverFactory
is a factory for making resource resolvers.static final class
Describes a parsed SRV record.Nested classes/interfaces inherited from class io.grpc.NameResolver
NameResolver.Args, NameResolver.ConfigOrError, NameResolver.Factory, NameResolver.Listener, NameResolver.Listener2, NameResolver.ResolutionResult, NameResolver.ResolutionResultAttr, NameResolver.ServiceConfigParser
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected DnsNameResolver.AddressResolver
private final String
private final long
(package private) static final long
Default DNS cache duration if network cache ttl value is not specified (null
).(package private) static boolean
(package private) static boolean
protected static boolean
private Executor
private final SharedResourceHolder.Resource
<Executor> Executor that will be used if an Executor is not provide viaNameResolver.Args
.private final String
private static final String
private static final String
private static final String
private NameResolver.Listener2
private static String
Access throughgetLocalHostname()
.private static final Logger
(package private) static final String
Java networking system properties name for caching DNS result.private final int
(package private) final ProxyDetector
private final Random
protected boolean
private boolean
private final AtomicReference
<DnsNameResolver.ResourceResolver> private static final DnsNameResolver.ResourceResolverFactory
private static final String
private static final String
private static final String
private static final String
private static final String
(package private) static final String
private final NameResolver.ServiceConfigParser
private boolean
private final com.google.common.base.Stopwatch
private final SynchronizationContext
private final boolean
True if using an executor resource that should be released after use. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
DnsNameResolver
(String nsAuthority, String name, NameResolver.Args args, SharedResourceHolder.Resource<Executor> executorResource, com.google.common.base.Stopwatch stopwatch, boolean isAndroid) -
Method Summary
Modifier and TypeMethodDescriptionprivate boolean
private EquivalentAddressGroup
protected DnsNameResolver.InternalResolutionResult
doResolve
(boolean forceTxt) Main logic of name resolution.getClientLanguagesFromChoice
(Map<String, ?> serviceConfigChoice) protected String
getHost()
getHostnamesFromChoice
(Map<String, ?> serviceConfigChoice) private static String
private static long
getNetworkAddressCacheTtlNanos
(boolean isAndroid) Returns value of network address cache ttl property if not Android environment.private static final Double
getPercentageFromChoice
(Map<String, ?> serviceConfigChoice) (package private) final int
getPort()
protected DnsNameResolver.ResourceResolver
(package private) static DnsNameResolver.ResourceResolverFactory
Returns the authority used to authenticate connections to servers.maybeChooseServiceConfig
(Map<String, ?> choice, Random random, String hostname) Determines if a given Service Config choice applies, and if so, returns it.(package private) static NameResolver.ConfigOrError
parseServiceConfig
(List<String> rawTxtRecords, Random random, String localHostname) parseTxtResults
(List<String> txtRecords) Parse TXT service config records as JSON.void
refresh()
Re-resolve the name.private void
resolve()
private List
<EquivalentAddressGroup> private NameResolver.ConfigOrError
protected void
setAddressResolver
(DnsNameResolver.AddressResolver addressResolver) protected void
setResourceResolver
(DnsNameResolver.ResourceResolver resourceResolver) protected static boolean
shouldUseJndi
(boolean jndiEnabled, boolean jndiLocalhostEnabled, String target) void
shutdown()
Stops the resolution.void
start
(NameResolver.Listener2 listener) Starts the resolution.Methods inherited from class io.grpc.NameResolver
start
-
Field Details
-
logger
-
SERVICE_CONFIG_CHOICE_CLIENT_LANGUAGE_KEY
- See Also:
-
SERVICE_CONFIG_CHOICE_PERCENTAGE_KEY
- See Also:
-
SERVICE_CONFIG_CHOICE_CLIENT_HOSTNAME_KEY
- See Also:
-
SERVICE_CONFIG_CHOICE_SERVICE_CONFIG_KEY
- See Also:
-
SERVICE_CONFIG_PREFIX
- See Also:
-
SERVICE_CONFIG_CHOICE_KEYS
-
SERVICE_CONFIG_NAME_PREFIX
- See Also:
-
JNDI_PROPERTY
-
JNDI_LOCALHOST_PROPERTY
-
JNDI_TXT_PROPERTY
-
NETWORKADDRESS_CACHE_TTL_PROPERTY
Java networking system properties name for caching DNS result.Default value is -1 (cache forever) if security manager is installed. If security manager is not installed, the ttl value is
null
which falls back togRPC default value
.For android, gRPC doesn't attempt to cache; this property value will be ignored.
- See Also:
-
DEFAULT_NETWORK_CACHE_TTL_SECONDS
static final long DEFAULT_NETWORK_CACHE_TTL_SECONDSDefault DNS cache duration if network cache ttl value is not specified (null
).- See Also:
-
enableJndi
static boolean enableJndi -
enableJndiLocalhost
static boolean enableJndiLocalhost -
enableTxt
protected static boolean enableTxt -
resourceResolverFactory
-
proxyDetector
-
localHostname
Access throughgetLocalHostname()
. -
random
-
addressResolver
-
resourceResolver
-
authority
-
host
-
port
private final int port -
executorResource
Executor that will be used if an Executor is not provide viaNameResolver.Args
. -
cacheTtlNanos
private final long cacheTtlNanos -
syncContext
-
stopwatch
private final com.google.common.base.Stopwatch stopwatch -
resolved
protected boolean resolved -
shutdown
private boolean shutdown -
executor
-
usingExecutorResource
private final boolean usingExecutorResourceTrue if using an executor resource that should be released after use. -
serviceConfigParser
-
resolving
private boolean resolving -
listener
-
-
Constructor Details
-
Method Details
-
getServiceAuthority
Description copied from class:NameResolver
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.
NameResolver
s created from the same factory with the same argument must return the same authority.- Specified by:
getServiceAuthority
in classNameResolver
-
getHost
-
start
Description copied from class:NameResolver
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
NameResolver.shutdown()
.- Overrides:
start
in classNameResolver
- Parameters:
listener
- used to receive updates on the target
-
refresh
public void refresh()Description copied from class:NameResolver
Re-resolve the name.Can only be called after
NameResolver.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.
- Overrides:
refresh
in classNameResolver
-
resolveAddresses
-
resolveServiceConfig
-
detectProxy
- Throws:
IOException
-
doResolve
Main logic of name resolution. -
parseServiceConfig
-
resolve
private void resolve() -
cacheRefreshRequired
private boolean cacheRefreshRequired() -
shutdown
public void shutdown()Description copied from class:NameResolver
Stops the resolution. Updates to the Listener will stop.- Specified by:
shutdown
in classNameResolver
-
getPort
final int getPort() -
parseTxtResults
Parse TXT service config records as JSON.- Throws:
IOException
- if one of the txt records contains improperly formatted JSON.
-
getPercentageFromChoice
-
getClientLanguagesFromChoice
-
getHostnamesFromChoice
-
getNetworkAddressCacheTtlNanos
private static long getNetworkAddressCacheTtlNanos(boolean isAndroid) Returns value of network address cache ttl property if not Android environment. For android, DnsNameResolver does not cache the dns lookup result. -
maybeChooseServiceConfig
@Nullable static Map<String,?> maybeChooseServiceConfig(Map<String, ?> choice, Random random, String hostname) Determines if a given Service Config choice applies, and if so, returns it.- Parameters:
choice
- The service config choice.- Returns:
- The service config object or
null
if this choice does not apply. - See Also:
-
setAddressResolver
-
setResourceResolver
-
getResourceResolver
-
getResourceResolverFactory
@Nullable static DnsNameResolver.ResourceResolverFactory getResourceResolverFactory(ClassLoader loader) -
getLocalHostname
-
shouldUseJndi
protected static boolean shouldUseJndi(boolean jndiEnabled, boolean jndiLocalhostEnabled, String target)
-