|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectgroovyx.net.http.HTTPBuilder
groovyx.net.http.AsyncHTTPBuilder
public class AsyncHTTPBuilder
This implementation makes all requests asynchronous by submitting jobs to a
ThreadPoolExecutor
. All request methods (including get
and post
) return a Future
instance, whose
get
method will provide access to whatever value was
returned from the response handler closure.
Nested Class Summary |
---|
Nested classes/interfaces inherited from class groovyx.net.http.HTTPBuilder |
---|
HTTPBuilder.SendDelegate |
Field Summary | |
---|---|
static int |
DEFAULT_POOL_SIZE
Default pool size is one is not supplied in the constructor. |
protected ThreadPoolExecutor |
threadPool
|
Fields inherited from class groovyx.net.http.HTTPBuilder |
---|
auth, client, contentEncodingHandler, defaultContentType, defaultRequestHeaders, defaultResponseHandlers, defaultURI, encoders, log, parsers |
Constructor Summary | |
---|---|
AsyncHTTPBuilder(Map<String,?> args)
Accepts the following named parameters: poolSizeMax number of concurrent requests urlDefault request URL contentTypeDefault content type for requests and responses |
Method Summary | |
---|---|
protected Future<?> |
doRequest(HTTPBuilder.SendDelegate delegate)
Submits a Callable instance to the job pool, which in turn will
call HTTPBuilder.doRequest(SendDelegate) in an asynchronous
thread. |
protected void |
finalize()
|
ThreadPoolExecutor |
getThreadPoolExecutor()
Access the underlying threadpool to adjust things like job timeouts. |
protected void |
initThreadPools(int poolSize)
Initializes threading parameters for the HTTPClient's ThreadSafeClientConnManager , and this class' ThreadPoolExecutor. |
void |
shutdown()
Release any system resources held by this instance. |
Methods inherited from class groovyx.net.http.HTTPBuilder |
---|
buildDefaultResponseHandlers, defaultFailureHandler, defaultSuccessHandler, doRequest, get, get, getAuth, getClient, getEncoder, getHandler, getHeaders, getParser, getURL, post, post, request, request, request, setAuthConfig, setContentEncoding, setContentEncodingRegistry, setContentType, setEncoderRegistry, setHeaders, setParserRegistry, setProxy, setURL |
Methods inherited from class java.lang.Object |
---|
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int DEFAULT_POOL_SIZE
protected final ThreadPoolExecutor threadPool
Constructor Detail |
---|
public AsyncHTTPBuilder(Map<String,?> args) throws URISyntaxException
URISyntaxException
Method Detail |
---|
protected Future<?> doRequest(HTTPBuilder.SendDelegate delegate)
Callable
instance to the job pool, which in turn will
call HTTPBuilder.doRequest(SendDelegate)
in an asynchronous
thread. The Future
instance returned by this value (which in
turn should be returned by any of the public request
methods
(including get
and post
) may be used to
retrieve whatever value may be returned from the executed response
handler closure.
doRequest
in class HTTPBuilder
protected void initThreadPools(int poolSize)
ThreadSafeClientConnManager
, and this class' ThreadPoolExecutor.
public ThreadPoolExecutor getThreadPoolExecutor()
Access the underlying threadpool to adjust things like job timeouts.
Note that this is not the same thread pool used by the HttpClient's
ThreadSafeClientConnManager
. Therefore, increasing the
maximum pool size
will
not in turn increase the number of possible concurrent requests. It will
simply cause more requests to be attempted which will then simply
block while waiting for an available connection.
Since ThreadSafeClientConnManager
has no public mechanism to
adjust its pool size, the value
public void shutdown()
shutdown
in class HTTPBuilder
ClientConnectionManager.shutdown()
protected void finalize() throws Throwable
finalize
in class Object
Throwable
shutdown()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |