@Override public List<LookupResult> resolve(final String fqdn) { Preconditions.checkNotNull(fqdn, "fqdn"); try { final List<LookupResult> nodes = delegate.resolve(fqdn); // No nodes resolved? Return stale data. if (nodes.isEmpty()) { List<LookupResult> cached = cache.getIfPresent(fqdn); return (cached != null) ? cached : nodes; } cache.put(fqdn, nodes); return nodes; } catch (Exception e) { if (cache.getIfPresent(fqdn) != null) { return cache.getIfPresent(fqdn); } throw Throwables.propagate(e); } } }
@Override public List<LookupResult> resolve(final String fqdn) { Preconditions.checkNotNull(fqdn, "fqdn"); try { final List<LookupResult> nodes = delegate.resolve(fqdn); // No nodes resolved? Return stale data. if (nodes.isEmpty()) { List<LookupResult> cached = cache.getIfPresent(fqdn); return (cached != null) ? cached : nodes; } cache.put(fqdn, nodes); return nodes; } catch (Exception e) { if (cache.getIfPresent(fqdn) != null) { return cache.getIfPresent(fqdn); } throw Throwables.propagate(e); } } }
public void updateDNS() { synchronized (sync) { if (shutdown) { return; } long ttl = TimeUnit.SECONDS.convert(period, periodUnit); try { List<LookupResult> lookupResults = srvResolver.resolve(srvRecord); List<HostAndPort> hosts = Lists.newArrayListWithCapacity(lookupResults.size()); for (LookupResult lookupResult : lookupResults) { hosts.add(HostAndPort.fromParts(lookupResult.host(), lookupResult.port())); ttl = Math.min(ttl, lookupResult.ttl()); } List<HostAndPort> newAddresses = Ordering.from(HostAndPortComparator.INSTANCE).sortedCopy(hosts); if (!newAddresses.equals(addresses)) { addresses = newAddresses; log.info("Connecting to " + newAddresses); List<AddressAndClient> addressAndClients = getAddressesAndClients(newAddresses); setPendingClient(addressAndClients); } } finally { long delay = clamp(MIN_DNS_WAIT_TIME, MAX_DNS_WAIT_TIME, ttl); refreshJob = this.executor.schedule(this::updateDNS, delay, TimeUnit.SECONDS); } } }
nodes = resolver.resolve(fqdn); } catch (DnsException e) { if (errorHandler != null) {
nodes = resolver.resolve(fqdn); } catch (DnsException e) { if (errorHandler != null) {
@Override public List<LookupResult> resolve(String fqdn) { // Only catch and report RuntimeException to avoid Error's since that would // most likely only aggravate any condition that causes them to be thrown. final DnsTimingContext resolveTimer = reporter.resolveTimer(); final List<LookupResult> result; try { result = delegate.resolve(fqdn); } catch (RuntimeException error) { reporter.reportFailure(error); throw error; } finally { resolveTimer.stop(); } if (result.isEmpty()) { reporter.reportEmpty(); } return result; } }
@Override public List<LookupResult> resolve(String fqdn) { // Only catch and report RuntimeException to avoid Error's since that would // most likely only aggravate any condition that causes them to be thrown. final DnsTimingContext resolveTimer = reporter.resolveTimer(); final List<LookupResult> result; try { result = delegate.resolve(fqdn); } catch (RuntimeException error) { reporter.reportFailure(error); throw error; } finally { resolveTimer.stop(); } if (result.isEmpty()) { reporter.reportEmpty(); } return result; } }
builder.setScheme(auditServiceScheme); if (useSrvDNS) { List<LookupResult> results = dnsSrvResolver.resolve(auditServiceHost); if (results != null && !results.isEmpty()) { LookupResult result = results.get(0);
builder.setScheme(authServiceScheme); if (useSrvDNS) { List<LookupResult> results = dnsSrvResolver.resolve(authServiceHost); if (results != null && !results.isEmpty()) { LookupResult result = results.get(0);
public List<LookupResult> dnsSrvLookup(String url) { return DnsSrvResolvers.newBuilder() .cachingLookups(true) .retainingDataOnFailures(true) .metered(dnsReporter) .dnsLookupTimeoutMillis(1000) .build() .resolve(url); } }