Package org.eclipse.jetty.util
Class SocketAddressResolver.Async
- java.lang.Object
-
- org.eclipse.jetty.util.SocketAddressResolver.Async
-
- All Implemented Interfaces:
SocketAddressResolver
- Enclosing interface:
- SocketAddressResolver
@ManagedObject("The asynchronous address resolver") public static class SocketAddressResolver.Async extends java.lang.Object implements SocketAddressResolver
Creates
SocketAddress
instances asynchronously in a different thread.InetSocketAddress(String, int)
attempts to perform a DNS resolution of the host name, and this may block for several seconds. This class creates theInetSocketAddress
in a separate thread and provides the result through aPromise
, 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 } public void failed(Throwable failure) { // The address resolution failed } });
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.eclipse.jetty.util.SocketAddressResolver
SocketAddressResolver.Async, SocketAddressResolver.Sync
-
-
Constructor Summary
Constructors Constructor Description Async(java.util.concurrent.Executor executor, Scheduler scheduler, 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.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.util.concurrent.Executor
getExecutor()
Scheduler
getScheduler()
long
getTimeout()
void
resolve(java.lang.String host, int port, Promise<java.util.List<java.net.InetSocketAddress>> promise)
Resolves the given host and port, returning aSocketAddress
through the givenPromise
with the default timeout.
-
-
-
Constructor Detail
-
Async
public Async(java.util.concurrent.Executor executor, Scheduler scheduler, 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.- Parameters:
executor
- the thread pool to use to perform DNS resolution in pooled threadsscheduler
- the scheduler to schedule tasks to cancel DNS resolution if it takes too longtimeout
- the timeout, in milliseconds, for the DNS resolution to complete
-
-
Method Detail
-
getExecutor
public java.util.concurrent.Executor getExecutor()
-
getScheduler
public Scheduler getScheduler()
-
getTimeout
@ManagedAttribute(value="The timeout, in milliseconds, to resolve an address", readonly=true) public long getTimeout()
-
resolve
public void resolve(java.lang.String host, int port, Promise<java.util.List<java.net.InetSocketAddress>> promise)
Description copied from interface:SocketAddressResolver
Resolves the given host and port, returning aSocketAddress
through the givenPromise
with the default timeout.- Specified by:
resolve
in interfaceSocketAddressResolver
- Parameters:
host
- the host to resolveport
- the port of the resulting socket addresspromise
- the callback invoked when the resolution succeeds or fails
-
-