com.ning.http.client
Class AsyncCompletionHandler<T>

java.lang.Object
  extended by com.ning.http.client.AsyncCompletionHandler<T>
Type Parameters:
T - Type of the value that will be returned by the associated Future
All Implemented Interfaces:
AsyncHandler<T>, ProgressAsyncHandler<T>
Direct Known Subclasses:
AsyncCompletionHandlerBase

public abstract class AsyncCompletionHandler<T>
extends Object
implements AsyncHandler<T>, ProgressAsyncHandler<T>

An AsyncHandler augmented with an onCompleted(Response) convenience method which gets called when the Response has been fully received. 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(Response response) throws Exception &#123; asyncHttpClient.getConfig().executorService().execute(new Runnable() &#123; public void run() &#123; asyncHttpClient.prepareGet(...); &#125; &#125;); return T; &#125;


Nested Class Summary
 
Nested classes/interfaces inherited from interface com.ning.http.client.AsyncHandler
AsyncHandler.STATE
 
Constructor Summary
AsyncCompletionHandler()
           
 
Method Summary
 AsyncHandler.STATE onBodyPartReceived(HttpResponseBodyPart content)
          Invoked as soon as some response body part are received.
 T onCompleted()
          Invoked once the HTTP response has been fully received
abstract  T onCompleted(Response response)
          Invoked once the HTTP response has been fully read.
 AsyncHandler.STATE onContentWriteCompleted()
          Invoked when the content (a File, String or FileInputStream has been fully written on the I/O socket.
 AsyncHandler.STATE onContentWriteProgress(long amount, long current, long total)
          Invoked when the I/O operation associated with the Request body as been progressed.
 AsyncHandler.STATE onHeadersReceived(HttpResponseHeaders headers)
          Invoked as soon as the HTTP headers has been received.
 AsyncHandler.STATE onHeaderWriteCompleted()
          Invoked when the content (a File, String or FileInputStream has been fully written on the I/O socket.
 AsyncHandler.STATE onStatusReceived(HttpResponseStatus status)
          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
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AsyncCompletionHandler

public AsyncCompletionHandler()
Method Detail

onBodyPartReceived

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

Specified by:
onBodyPartReceived in interface AsyncHandler<T>
Parameters:
content - response's body part.
Returns:
a AsyncHandler.STATE telling to CONTINUE or ABORT the current processing.
Throws:
Exception - if something wrong happens

onStatusReceived

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

Specified by:
onStatusReceived in interface AsyncHandler<T>
Parameters:
status - 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

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

Specified by:
onHeadersReceived in interface AsyncHandler<T>
Parameters:
headers - the HTTP headers.
Returns:
a AsyncHandler.STATE telling to CONTINUE or ABORT the current processing.
Throws:
Exception - if something wrong happens

onCompleted

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

Specified by:
onCompleted in interface AsyncHandler<T>
Returns:
T Type of the value that will be returned by the associated Future
Throws:
Exception - if something wrong happens

onThrowable

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

Specified by:
onThrowable in interface AsyncHandler<T>
Parameters:
t - a Throwable

onCompleted

public abstract T onCompleted(Response response)
                       throws Exception
Invoked once the HTTP response has been fully read.

Parameters:
response - The Response
Returns:
Type of the value that will be returned by the associated Future
Throws:
Exception

onHeaderWriteCompleted

public AsyncHandler.STATE onHeaderWriteCompleted()
Invoked when the content (a File, String or FileInputStream has been fully written on the I/O socket.

Specified by:
onHeaderWriteCompleted in interface ProgressAsyncHandler<T>
Returns:
a AsyncHandler.STATE telling to CONTINUE or ABORT the current processing.

onContentWriteCompleted

public AsyncHandler.STATE onContentWriteCompleted()
Invoked when the content (a File, String or FileInputStream has been fully written on the I/O socket.

Specified by:
onContentWriteCompleted in interface ProgressAsyncHandler<T>
Returns:
a AsyncHandler.STATE telling to CONTINUE or ABORT the current processing.

onContentWriteProgress

public AsyncHandler.STATE onContentWriteProgress(long amount,
                                                 long current,
                                                 long total)
Invoked when the I/O operation associated with the Request body as been progressed.

Specified by:
onContentWriteProgress in interface ProgressAsyncHandler<T>
Parameters:
amount - The amount of bytes to transfer.
current - The amount of bytes transferred
total - The total number of bytes transferred
Returns:
a AsyncHandler.STATE telling to CONTINUE or ABORT the current processing.


Copyright © 2010. All Rights Reserved.