com.ning.http.client
Interface AsyncHandler<T>

Type Parameters:
T - Type of object returned by the Future.get()
All Known Subinterfaces:
ProgressAsyncHandler<T>
All Known Implementing Classes:
AsyncCompletionHandler, AsyncCompletionHandlerBase, WebDavCompletionHandlerBase

public interface AsyncHandler<T>

An asynchronous handler or callback which gets invoked as soon as some data are available when processing an asynchronous response. Callbacks method gets invoked in the following order: (1) onStatusReceived(HttpResponseStatus) (2) onHeadersReceived(HttpResponseHeaders) (3) onBodyPartReceived(HttpResponseBodyPart), which could be invoked multiple times (4) onCompleted(), once the response has been fully read. Interrupting the process of the asynchronous response can be achieved by returning a AsyncHandler.STATE.ABORT at any moment during the processing of the asynchronous response. NOTE: Sending another asynchronous request from an AsyncHandler must be done using another thread to avoid potential deadlock inside the AsyncHttpProvider The recommended way is to use the ExecutorService from the AsyncHttpClientConfig: &#64;Override public T onCompleted() throws Exception &#123; asyncHttpClient.getConfig().executorService().execute(new Runnable() &#123; public void run() &#123; asyncHttpClient.prepareGet(...); &#125; &#125;); return T; &#125;


Nested Class Summary
static class AsyncHandler.STATE
           
 
Method Summary
 AsyncHandler.STATE onBodyPartReceived(HttpResponseBodyPart bodyPart)
          Invoked as soon as some response body part are received.
 T onCompleted()
          Invoked once the HTTP response has been fully received
 AsyncHandler.STATE onHeadersReceived(HttpResponseHeaders headers)
          Invoked as soon as the HTTP headers has been received.
 AsyncHandler.STATE onStatusReceived(HttpResponseStatus responseStatus)
          Invoked as soon as the HTTP status line has been received
 void onThrowable(Throwable t)
          Invoked when an unexpected exception occurs during the processing of the response
 

Method Detail

onThrowable

void onThrowable(Throwable t)
Invoked when an unexpected exception occurs during the processing of the response

Parameters:
t - a Throwable

onBodyPartReceived

AsyncHandler.STATE onBodyPartReceived(HttpResponseBodyPart bodyPart)
                                      throws Exception
Invoked as soon as some response body part are received.

Parameters:
bodyPart - response's body part.
Returns:
a AsyncHandler.STATE telling to CONTINUE or ABORT the current processing.
Throws:
Exception - if something wrong happens

onStatusReceived

AsyncHandler.STATE onStatusReceived(HttpResponseStatus responseStatus)
                                    throws Exception
Invoked as soon as the HTTP status line has been received

Parameters:
responseStatus - the status code and test of the response
Returns:
a AsyncHandler.STATE telling to CONTINUE or ABORT the current processing.
Throws:
Exception - if something wrong happens

onHeadersReceived

AsyncHandler.STATE onHeadersReceived(HttpResponseHeaders headers)
                                     throws Exception
Invoked as soon as the HTTP headers has been received.

Parameters:
headers - the HTTP headers.
Returns:
a AsyncHandler.STATE telling to CONTINUE or ABORT the current processing.
Throws:
Exception - if something wrong happens

onCompleted

T onCompleted()
              throws Exception
Invoked once the HTTP response has been fully received

Returns:
T Type of the value that will be returned by the associated Future
Throws:
Exception - if something wrong happens


Copyright © 2010. All Rights Reserved.