Example usage for io.vertx.core.dns DnsClient lookup

List of usage examples for io.vertx.core.dns DnsClient lookup

Introduction

In this page you can find the example usage for io.vertx.core.dns DnsClient lookup.

Prototype

@Fluent
DnsClient lookup(String name, Handler<AsyncResult<@Nullable String>> handler);

Source Link

Document

Try to lookup the A (ipv4) or AAAA (ipv6) record for the given name.

Usage

From source file:co.runrightfast.vertx.demo.testHarness.jmx.DemoMXBeanImpl.java

License:Apache License

@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 {/* w w w.ja v a 2s.c o m*/
            future.completeExceptionally(result.cause());
        }
    });

    try {
        return future.get();
    } catch (final InterruptedException | ExecutionException ex) {
        throw new RuntimeException(ex);
    }
}

From source file:docoverride.dns.Examples.java

License:Open Source License

public void example16(Vertx vertx) {
    DnsClient client = vertx.createDnsClient(53, "10.0.0.1");
    client.lookup("nonexisting.vert.xio", ar -> {
        if (ar.succeeded()) {
            String record = ar.result();
            System.out.println(record);
        } else {/*from   w w  w  . ja  va2s . com*/
            Throwable cause = ar.cause();
            if (cause instanceof DnsException) {
                DnsException exception = (DnsException) cause;
                DnsResponseCode code = exception.code();
                // ...
            } else {
                System.out.println("Failed to resolve entry" + ar.cause());
            }
        }
    });
}

From source file:examples.DNSExamples.java

License:Open Source License

public void example2(Vertx vertx) {
    DnsClient client = vertx.createDnsClient(53, "10.0.0.1");
    client.lookup("vertx.io", ar -> {
        if (ar.succeeded()) {
            System.out.println(ar.result());
        } else {//from  w w w. j a  v  a  2s  .  com
            System.out.println("Failed to resolve entry" + ar.cause());
        }
    });
}