Java 类io.vertx.core.dns.DnsClient 实例源码

项目:runrightfast-vertx    文件:DemoMXBeanImpl.java   
@Override
public String lookupIPAddress(final String dnsServer, final String host) {
    final DnsClient client = vertx.createDnsClient(53, dnsServer);
    final CompletableFuture<String> future = new CompletableFuture<>();
    client.lookup("vertx.io", result -> {
        if (result.succeeded()) {
            future.complete(result.result());
        } else {
            future.completeExceptionally(result.cause());
        }
    });

    try {
        return future.get();
    } catch (final InterruptedException | ExecutionException ex) {
        throw new RuntimeException(ex);
    }
}
项目:qbit    文件:DnsSupport.java   
/**
 * Load the services nodes by its "${SRV.service}${SRV.name}".
 *
 * @param callback   callback
 * @param serviceURL serviceURL
 */
public void loadServiceEndpointsByDNSService(final Callback<List<EndpointDefinition>> callback,
                                             final String serviceURL) {
    final DnsClient dnsClient = dnsClientProvider.get();
    dnsClient.resolveSRV(serviceURL, event ->
            {
                if (event.succeeded()) {
                    if (debug) logger.debug("loadServiceEndpointsByDNSService SUCCESS serviceURL={} ", serviceURL);
                    callback.resolve(convertEndpoints(event.result()));
                } else {

                    Throwable error = event.cause();

                    logger.info("loadServiceEndpointsByDNSService FAILURE  " + serviceURL, error);


                    attemptRecover(callback, serviceURL, error);

                }
            }
    );
}
项目:qbit    文件:DnsSupport.java   
private void attemptRecover(final Callback<List<EndpointDefinition>> callback, final String serviceURL, final Throwable error) {
    final DnsClient dnsClient2 = dnsClientProvider.getIfErrors();

    dnsClient2.resolveSRV(serviceURL, event -> {

        if (event.succeeded()) {

            if (debug)
                logger.debug("loadServiceEndpointsByDNSService FAIL OVER SUCCESS serviceURL={} ", serviceURL);
            callback.resolve(convertEndpoints(event.result()));
        } else {

            logger.info("loadServiceEndpointsByDNSService FAIL OVER FAILURE  " + serviceURL, event.cause());

            //Send the first failure
            callback.onError(error);
        }
    });
}
项目:runrightfast-vertx    文件:VertxDnsClientTest.java   
@Test
public void testDnsClient() throws Exception {
    final DnsClient client = vertx.createDnsClient(53, "8.8.8.8");
    final CompletableFuture<String> future = new CompletableFuture<>();
    client.lookup("vertx.io", result -> {
        if (result.succeeded()) {
            future.complete(result.result());
        } else {
            future.completeExceptionally(result.cause());
        }
    });

    log.info(future.get());
}
项目:qbit    文件:DnsClientFromResolveConfSupplier.java   
/**
 * Get a DNS client.
 *
 * @return dns client.
 */
@Override
public DnsClient get() {
    final URI uri = addressList.get(index);
    try {
        if (debug) logger.debug("DnsClient.get port {} host {}", uri.getPort(), uri.getHost());
        return vertx.createDnsClient(uri.getPort(), uri.getHost());
    } catch (Exception ex) {
        logger.error("DnsClient.get EXCEPTION ", ex);
        logger.error("DnsClient.get EXCEPTION port {} host {}", uri.getPort(), uri.getHost());
        return getIfErrors();
    }
}
项目:qbit    文件:DnsClientFromResolveConfSupplier.java   
@Override
public DnsClient getIfErrors() {
    nextAddress();
    final URI uri = addressList.get(index);
    if (debug) logger.debug("DnsClient.get FAIL OVER port {} host {}", uri.getPort(), uri.getHost());
    return vertx.createDnsClient(uri.getPort(), uri.getHost());
}
项目:qbit    文件:DnsSingleClientSupplier.java   
/**
 * Supply an instance of DnsClient.
 *
 * @return DnsClient.
 */
@Override
public DnsClient get() {

    if (debug) logger.debug("DnsSingleClientSupplier.get()::host = {}, port = {}", host, port);
    return vertx.createDnsClient(port, host);
}
项目:sfs    文件:SfsVertxImpl.java   
@Override
public DnsClient createDnsClient(int port, String host) {
    return vertx.createDnsClient(port, host);
}
项目:qbit    文件:DnsClientSupplier.java   
default DnsClient getIfErrors() {
    return get();
}
项目:hono    文件:DelegatingAuthenticationService.java   
/**
 * Sets the DNS client to use for checking availability of an <em>Authentication</em> service.
 * <p>
 * If not set, the vert.x instance's address resolver is used instead.
 *
 * @param dnsClient The client.
 * @throws NullPointerException if client is {@code null}.
 */
@Autowired(required = false)
public void setDnsClient(final DnsClient dnsClient) {
    this.dnsClient = Objects.requireNonNull(dnsClient);
}