Package com.ning.http.client
Interface AsyncHandler<T>
- Type Parameters:
T- Type of object returned by theFuture.get()
- All Known Subinterfaces:
ProgressAsyncHandler<T>
- All Known Implementing Classes:
AsyncCompletionHandler,AsyncCompletionHandlerBase,BodyDeferringAsyncHandler,ResumableAsyncHandler,TransferCompletionHandler,WebDavCompletionHandlerBase,WebSocketUpgradeHandler
public interface AsyncHandler<T>
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:
Callback methods get invoked in the following order:
onStatusReceived(HttpResponseStatus),onHeadersReceived(HttpResponseHeaders),onBodyPartReceived(HttpResponseBodyPart), which could be invoked multiple times,onCompleted(), once the response has been fully read.
AsyncHandler.STATE.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.-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptiononBodyPartReceived(HttpResponseBodyPart bodyPart) Invoked as soon as some response body part are received.Invoked once the HTTP response processing is finished.onHeadersReceived(HttpResponseHeaders headers) Invoked as soon as the HTTP headers has been received.onStatusReceived(HttpResponseStatus responseStatus) Invoked as soon as the HTTP status line has been receivedvoidInvoked when an unexpected exception occurs during the processing of the response.
-
Method Details
-
onThrowable
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- aThrowable
-
onBodyPartReceived
Invoked as soon as some response body part are received. Could be invoked many times.- Parameters:
bodyPart- response's body part.- Returns:
- a
AsyncHandler.STATEtelling to CONTINUE or ABORT the current processing. - Throws:
Exception- if something wrong happens
-
onStatusReceived
Invoked as soon as the HTTP status line has been received- Parameters:
responseStatus- the status code and test of the response- Returns:
- a
AsyncHandler.STATEtelling to CONTINUE or ABORT the current processing. - Throws:
Exception- if something wrong happens
-
onHeadersReceived
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:
- a
AsyncHandler.STATEtelling to CONTINUE or ABORT the current processing. - Throws:
Exception- if something wrong happens
-
onCompleted
Invoked once the HTTP response processing is finished. Gets always invoked as last callback method.
-