X-Git-Url: https://code.wpia.club/?p=gigi.git;a=blobdiff_plain;f=lib%2Fjetty%2Forg%2Feclipse%2Fjetty%2Futil%2FSocketAddressResolver.java;h=f6eff3f026c4979fce4bd0b91dd15da2b841e71e;hp=e75abfc064fd2799fec8a0e9392ad6a577e42c06;hb=ba4f228fa9f72d50991a2218cfd83987ef5d385e;hpb=875b5e9651498a0cd8e0001c0742ba843e47cad0 diff --git a/lib/jetty/org/eclipse/jetty/util/SocketAddressResolver.java b/lib/jetty/org/eclipse/jetty/util/SocketAddressResolver.java index e75abfc0..f6eff3f0 100644 --- a/lib/jetty/org/eclipse/jetty/util/SocketAddressResolver.java +++ b/lib/jetty/org/eclipse/jetty/util/SocketAddressResolver.java @@ -1,6 +1,6 @@ // // ======================================================================== -// Copyright (c) 1995-2014 Mort Bay Consulting Pty. Ltd. +// Copyright (c) 1995-2016 Mort Bay Consulting Pty. Ltd. // ------------------------------------------------------------------------ // All rights reserved. This program and the accompanying materials // are made available under the terms of the Eclipse Public License v1.0 @@ -31,69 +31,10 @@ import org.eclipse.jetty.util.log.Logger; import org.eclipse.jetty.util.thread.Scheduler; /** - * Creates asynchronously {@link SocketAddress} instances, returning them through a {@link Promise}, - * in order to avoid blocking on DNS lookup. - *
- * {@link InetSocketAddress#InetSocketAddress(String, int)} attempts to perform a DNS resolution of - * the host name, and this may block for several seconds. - * This class creates the {@link InetSocketAddress} in a separate thread and provides the result - * through a {@link Promise}, with the possibility to specify a timeout for the operation. - * - * Example usage: - *- * SocketAddressResolver resolver = new SocketAddressResolver(executor, scheduler); - * resolver.resolve("www.google.com", 80, new Promise<SocketAddress>() - * { - * public void succeeded(SocketAddress result) - * { - * // The address was resolved - * } - * - * public void failed(Throwable failure) - * { - * // The address resolution failed - * } - * }); - *+ *
Creates {@link SocketAddress} instances, returning them through a {@link Promise}.
*/ -public class SocketAddressResolver +public interface SocketAddressResolver { - private static final Logger LOG = Log.getLogger(SocketAddressResolver.class); - - private final Executor executor; - private final Scheduler scheduler; - private final long timeout; - - /** - * Creates a new instance with the given executor (to perform DNS resolution in a separate thread), - * the given scheduler (to cancel the operation if it takes too long) and the given timeout, in milliseconds. - * - * @param executor the thread pool to use to perform DNS resolution in pooled threads - * @param scheduler the scheduler to schedule tasks to cancel DNS resolution if it takes too long - * @param timeout the timeout, in milliseconds, for the DNS resolution to complete - */ - public SocketAddressResolver(Executor executor, Scheduler scheduler, long timeout) - { - this.executor = executor; - this.scheduler = scheduler; - this.timeout = timeout; - } - - public Executor getExecutor() - { - return executor; - } - - public Scheduler getScheduler() - { - return scheduler; - } - - public long getTimeout() - { - return timeout; - } - /** * Resolves the given host and port, returning a {@link SocketAddress} through the given {@link Promise} * with the default timeout. @@ -101,75 +42,149 @@ public class SocketAddressResolver * @param host the host to resolve * @param port the port of the resulting socket address * @param promise the callback invoked when the resolution succeeds or fails - * @see #resolve(String, int, long, Promise) */ - public void resolve(String host, int port, PromiseCreates {@link SocketAddress} instances synchronously in the caller thread.
+ */ + public static class Sync implements SocketAddressResolver { - resolve(host, port, timeout, promise); + @Override + public void resolve(String host, int port, PromiseCreates {@link SocketAddress} instances asynchronously in a different thread.
+ *{@link InetSocketAddress#InetSocketAddress(String, int)} attempts to perform a DNS + * resolution of the host name, and this may block for several seconds. + * This class creates the {@link InetSocketAddress} in a separate thread and provides the result + * through a {@link Promise}, with the possibility to specify a timeout for the operation.
+ *Example usage:
+ *+ * SocketAddressResolver resolver = new SocketAddressResolver.Async(executor, scheduler, timeout); + * resolver.resolve("www.google.com", 80, new Promise<SocketAddress>() + * { + * public void succeeded(SocketAddress result) + * { + * // The address was resolved + * } * - * @param host the host to resolve - * @param port the port of the resulting socket address - * @param timeout the timeout, in milliseconds, for the DNS resolution to complete - * @param promise the callback invoked when the resolution succeeds or fails + * public void failed(Throwable failure) + * { + * // The address resolution failed + * } + * }); + **/ - protected void resolve(final String host, final int port, final long timeout, final Promise