@Test @Ignore("intended for manual run only") public void connectToRealAddress() throws ExecutionException, InterruptedException { final SslContextFactory sslContextFactory = new SslContextFactory.Client(false); HttpClient httpClient = new HttpClient(sslContextFactory); httpClient.setExecutor(Executors.newCachedThreadPool()); final CompletableFuture<List<InetSocketAddress>> future = new CompletableFuture<>(); final Promise<List<InetSocketAddress>> promise = Promise.from(future); final HappyEyeballsResolver happyEyeballsResolver = new HappyEyeballsResolver(httpClient); final long startTime = System.nanoTime(); happyEyeballsResolver.resolve("www.google.com", 80, promise); final List<InetSocketAddress> inetSocketAddresses = future.get(); final long elapsed = System.nanoTime() - startTime; System.out.printf("Connected to: %s in %1.3fs %n", inetSocketAddresses.get(0).getAddress().getHostAddress(), elapsed/1e9); assertThat(inetSocketAddresses).isNotEmpty(); }
@Override public void resolve(String host, int port, Promise<List<InetSocketAddress>> promise) { final Optional<String> literalIpAddress = isLiteralIpAddress(host); if (literalIpAddress.isPresent()) { completePromise(literalIpAddress.get(), port, promise); } else { resolveAsynchronously(host, port, promise); } }
HappyEyeballsResolver implements SocketAddressResolver { @Override public void resolve(String host, int port, Promise<List<InetSocketAddress>> promise) { final Optional<String> literalIpAddress = isLiteralIpAddress(host); if (literalIpAddress.isPresent()) { completePromise(literalIpAddress.get(), port, promise); } else { resolveAsynchronously(host, port, promise); } } }
HappyEyeballsResolver implements SocketAddressResolver { @Override public void resolve(String host, int port, Promise<List<InetSocketAddress>> promise) { final Optional<String> literalIpAddress = isLiteralIpAddress(host); if (literalIpAddress.isPresent()) { completePromise(literalIpAddress.get(), port, promise); } else { resolveAsynchronously(host, port, promise); } } HappyEyeballsResolver(HttpClient httpClient); }
HappyEyeballsResolver implements SocketAddressResolver { @Override public void resolve(String host, int port, Promise<List<InetSocketAddress>> promise) { final Optional<String> literalIpAddress = isLiteralIpAddress(host); if (literalIpAddress.isPresent()) { completePromise(literalIpAddress.get(), port, promise); } else { resolveAsynchronously(host, port, promise); } } HappyEyeballsResolver(HttpClient httpClient); @Override void resolve(String host, int port, Promise<List<InetSocketAddress>> promise); }
HappyEyeballsResolver implements SocketAddressResolver { @Override public void resolve(String host, int port, Promise<List<InetSocketAddress>> promise) { final Optional<String> literalIpAddress = isLiteralIpAddress(host); if (literalIpAddress.isPresent()) { completePromise(literalIpAddress.get(), port, promise); } else { resolveAsynchronously(host, port, promise); } } HappyEyeballsResolver(HttpClient httpClient); @Override void resolve(String host, int port, Promise<List<InetSocketAddress>> promise); static final long HAPPY_EYEBALLS_TOTAL_TIMEOUT_NANOS; }