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 interfaceAddressResolver resolves a hostname into a list of addresses.protected static final classUsed as a DNS-based name resolver's internal representation of resolution result.private static enumprivate final classstatic interfaceDnsNameResolver.ResourceResolveris a Dns ResourceRecord resolver.(package private) static interfaceDnsNameResolver.ResourceResolverFactoryis a factory for making resource resolvers.static final classDescribes a parsed SRV record.Nested classes/interfaces inherited from class NameResolver
NameResolver.Args, NameResolver.ConfigOrError, NameResolver.Factory, NameResolver.Listener, NameResolver.Listener2, NameResolver.ResolutionResult, NameResolver.ResolutionResultAttr, NameResolver.ServiceConfigParser -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected DnsNameResolver.AddressResolverprivate final Stringprivate final long(package private) static final longDefault DNS cache duration if network cache ttl value is not specified (null).(package private) static boolean(package private) static booleanprotected static booleanprivate Executorprivate final SharedResourceHolder.Resource<Executor> Executor that will be used if an Executor is not provide viaNameResolver.Args.private final Stringprivate static final Stringprivate static final Stringprivate static final Stringprivate NameResolver.Listener2private static StringAccess throughgetLocalHostname().private static final Logger(package private) static final StringJava networking system properties name for caching DNS result.private final int(package private) final ProxyDetectorprivate final Randomprotected booleanprivate booleanprivate final AtomicReference<DnsNameResolver.ResourceResolver> private static final DnsNameResolver.ResourceResolverFactoryprivate static final Stringprivate static final Stringprivate static final Stringprivate static final Stringprivate static final String(package private) static final Stringprivate final NameResolver.ServiceConfigParserprivate booleanprivate final com.google.common.base.Stopwatchprivate final SynchronizationContextprivate final booleanTrue if using an executor resource that should be released after use. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedDnsNameResolver(String nsAuthority, String name, NameResolver.Args args, SharedResourceHolder.Resource<Executor> executorResource, com.google.common.base.Stopwatch stopwatch, boolean isAndroid) -
Method Summary
Modifier and TypeMethodDescriptionprivate booleanprivate EquivalentAddressGroupprotected DnsNameResolver.InternalResolutionResultdoResolve(boolean forceTxt) Main logic of name resolution.getClientLanguagesFromChoice(Map<String, ?> serviceConfigChoice) protected StringgetHost()getHostnamesFromChoice(Map<String, ?> serviceConfigChoice) private static Stringprivate static longgetNetworkAddressCacheTtlNanos(boolean isAndroid) Returns value of network address cache ttl property if not Android environment.private static final DoublegetPercentageFromChoice(Map<String, ?> serviceConfigChoice) (package private) final intgetPort()protected DnsNameResolver.ResourceResolver(package private) static DnsNameResolver.ResourceResolverFactoryReturns 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.ConfigOrErrorparseServiceConfig(List<String> rawTxtRecords, Random random, String localHostname) parseTxtResults(List<String> txtRecords) Parse TXT service config records as JSON.voidrefresh()Re-resolve the name.private voidresolve()private List<EquivalentAddressGroup> private NameResolver.ConfigOrErrorprotected voidsetAddressResolver(DnsNameResolver.AddressResolver addressResolver) protected voidsetResourceResolver(DnsNameResolver.ResourceResolver resourceResolver) protected static booleanshouldUseJndi(boolean jndiEnabled, boolean jndiLocalhostEnabled, String target) voidshutdown()Stops the resolution.voidstart(NameResolver.Listener2 listener) Starts the resolution.Methods inherited from class 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
nullwhich 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:NameResolverReturns 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.- Specified by:
getServiceAuthorityin classNameResolver
-
getHost
-
start
Description copied from class:NameResolverStarts 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(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:
startin classNameResolver- Parameters:
listener- used to receive updates on the target
-
refresh
public void refresh()Description copied from class:NameResolverRe-resolve the name.Can only be called after
NameResolver.start(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:
refreshin 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:NameResolverStops the resolution. Updates to the Listener will stop.- Specified by:
shutdownin 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
nullif 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)
-