com.twitter.common.net
Class UrlResolver

java.lang.Object
  extended by com.twitter.common.net.UrlResolver

public class UrlResolver
extends Object

Class to aid in resolving URLs by following redirects, which can optionally be performed asynchronously using a thread pool.


Nested Class Summary
static class UrlResolver.ResolvedUrl
          Class to wrap the result of a URL resolution.
static interface UrlResolver.ResolvedUrlHandler
          Interface to use for notifying the caller of resolved URLs.
 
Constructor Summary
UrlResolver(int maxRedirects, int threadPoolSize)
           
UrlResolver(int maxRedirects, int threadPoolSize, ProxyConfig proxyConfig)
          Creates a new asynchronous URL resolver.
 
Method Summary
 void clearAsyncTasks(int waitSeconds)
          Terminates the thread pool, waiting at most waitSeconds for active threads to complete.
 void reset()
           
 UrlResolver.ResolvedUrl resolveUrl(String url)
          Resolves a URL synchronously.
 Future<UrlResolver.ResolvedUrl> resolveUrlAsync(String url, UrlResolver.ResolvedUrlHandler handler)
           
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

UrlResolver

public UrlResolver(int maxRedirects,
                   int threadPoolSize,
                   @Nullable
                   ProxyConfig proxyConfig)
Creates a new asynchronous URL resolver. A thread pool will be used to resolve URLs, and resolved URLs will be announced via handler.

Parameters:
maxRedirects - The maximum number of HTTP redirects to follow.
threadPoolSize - The number of threads to use for resolving URLs.
proxyConfig - The proxy settings with which to make the HTTP request, or null for the default configured proxy.

UrlResolver

public UrlResolver(int maxRedirects,
                   int threadPoolSize)
Method Detail

resolveUrlAsync

public Future<UrlResolver.ResolvedUrl> resolveUrlAsync(String url,
                                                       UrlResolver.ResolvedUrlHandler handler)

reset

public void reset()

clearAsyncTasks

public void clearAsyncTasks(int waitSeconds)
Terminates the thread pool, waiting at most waitSeconds for active threads to complete. After this method is called, no more URLs may be submitted for resolution.

Parameters:
waitSeconds - The number of seconds to wait for active threads to complete.

resolveUrl

public UrlResolver.ResolvedUrl resolveUrl(String url)
Resolves a URL synchronously.

Parameters:
url - The URL to resolve.
Returns:
The resolved URL.

toString

public String toString()
Overrides:
toString in class Object