public interface

AsyncHandler

com.ning.http.client.AsyncHandler<T>
Known Indirect Subclasses

Class Overview

An asynchronous handler or callback which gets invoked as soon as some data is available when processing an asynchronous response.
Callback methods get 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.

Returning a ABORT from any of those callback methods will interrupt asynchronous response processing, after that only onCompleted() is going to be called.

AsyncHandler aren't thread safe, hence you should avoid re-using the same instance when doing concurrent requests. As an exmaple, the following may produce unexpected results:

   AsyncHandler ah = new AsyncHandler() {....};
   AsyncHttpClient client = new AsyncHttpClient();
   client.prepareGet("http://...").execute(ah);
   client.prepareGet("http://...").execute(ah);
 
It is recommended to create a new instance instead.

Summary

Nested Classes
enum AsyncHandler.STATE  
Public Methods
abstract AsyncHandler.STATE onBodyPartReceived(HttpResponseBodyPart bodyPart)
Invoked as soon as some response body part are received.
abstract T onCompleted()
Invoked once the HTTP response processing is finished.
abstract AsyncHandler.STATE onHeadersReceived(HttpResponseHeaders headers)
Invoked as soon as the HTTP headers has been received.
abstract AsyncHandler.STATE onStatusReceived(HttpResponseStatus responseStatus)
Invoked as soon as the HTTP status line has been received
abstract void onThrowable(Throwable t)
Invoked when an unexpected exception occurs during the processing of the response.

Public Methods

public abstract AsyncHandler.STATE onBodyPartReceived (HttpResponseBodyPart bodyPart)

Invoked as soon as some response body part are received. Could be invoked many times.

Parameters
bodyPart response's body part.
Returns
Throws
Exception if something wrong happens

public abstract T onCompleted ()

Invoked once the HTTP response processing is finished.

Gets always invoked as last callback method.

Returns
  • T Value that will be returned by the associated java.util.concurrent.Future
Throws
Exception if something wrong happens

public abstract AsyncHandler.STATE onHeadersReceived (HttpResponseHeaders headers)

Invoked as soon as the HTTP headers has been received. Can potentially be invoked more than once if a broken server sent trailing headers.

Parameters
headers the HTTP headers.
Returns
Throws
Exception if something wrong happens

public abstract AsyncHandler.STATE onStatusReceived (HttpResponseStatus responseStatus)

Invoked as soon as the HTTP status line has been received

Parameters
responseStatus the status code and test of the response
Returns
Throws
Exception if something wrong happens

public abstract 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 invocation.

Parameters
t a Throwable