T
- Type of object returned by the Future.get()
public interface AsyncHandler<T>
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:
It is recommended to create a new instance instead.AsyncHandler ah = new AsyncHandler() {....}; AsyncHttpClient client = new AsyncHttpClient(); client.prepareGet("http://...").execute(ah); client.prepareGet("http://...").execute(ah);
Modifier and Type | Interface and Description |
---|---|
static class |
AsyncHandler.STATE |
Modifier and Type | Method and Description |
---|---|
AsyncHandler.STATE |
onBodyPartReceived(HttpResponseBodyPart bodyPart)
Invoked as soon as some response body part are received.
|
T |
onCompleted()
Invoked once the HTTP response processing is finished.
|
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.
|
void onThrowable(Throwable t)
t
- a Throwable
AsyncHandler.STATE onBodyPartReceived(HttpResponseBodyPart bodyPart) throws Exception
bodyPart
- response's body part.AsyncHandler.STATE
telling to CONTINUE or ABORT the current processing.Exception
- if something wrong happensAsyncHandler.STATE onStatusReceived(HttpResponseStatus responseStatus) throws Exception
responseStatus
- the status code and test of the responseAsyncHandler.STATE
telling to CONTINUE or ABORT the current processing.Exception
- if something wrong happensAsyncHandler.STATE onHeadersReceived(HttpResponseHeaders headers) throws Exception
headers
- the HTTP headers.AsyncHandler.STATE
telling to CONTINUE or ABORT the current processing.Exception
- if something wrong happensCopyright © 2015. All Rights Reserved.