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 processing is finished. This class also implement the ProgressAsyncHandler callback, all doing nothing except returning AsyncHandler.STATE.CONTINUE


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 processing is finished.
abstract  T onCompleted(Response response)
          Invoked once the HTTP response processing is finished.
 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. Could be invoked many times.

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 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 AsyncHandler.STATE onHeadersReceived(HttpResponseHeaders headers)
                                     throws Exception
Invoked as soon as the HTTP headers has been received. Can potentially be invoked morethan once if a broken server sent trailling headers.

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 processing is finished.

Gets always invoked as last callback method.

Specified by:
onCompleted in interface AsyncHandler<T>
Returns:
T 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. The exception may have been produced by implementation of onXXXReceived method invokation.

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 processing is finished.

Gets always invoked as last callback method.

Parameters:
response - The Response
Returns:
T Value that will be returned by the associated Future
Throws:
Exception - if something wrong happens

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 © 2011. All Rights Reserved.