public class TransferCompletionHandler extends AsyncCompletionHandlerBase
org.asynchttpclient.AsyncHandler that can be used to notify a set of TransferListener
AsyncHttpClient client = new AsyncHttpClient();
TransferCompletionHandler tl = new TransferCompletionHandler();
tl.addTransferListener(new TransferListener() {
public void onRequestHeadersSent(FluentCaseInsensitiveStringsMap headers) {
}
public void onResponseHeadersReceived(FluentCaseInsensitiveStringsMap headers) {
}
public void onBytesReceived(ByteBuffer buffer) {
}
public void onBytesSent(long amount, long current, long total) {
}
public void onRequestResponseCompleted() {
}
public void onThrowable(Throwable t) {
}
});
Response response = httpClient.prepareGet("http://...").execute(tl).get();
AsyncHandler.STATE| Constructor and Description |
|---|
TransferCompletionHandler()
Create a TransferCompletionHandler that will not accumulate bytes.
|
TransferCompletionHandler(boolean accumulateResponseBytes)
Create a TransferCompletionHandler that can or cannot accumulate bytes and make it available when
org.asynchttpclient.Response#getResponseBody() get called. |
| Modifier and Type | Method and Description |
|---|---|
TransferCompletionHandler |
addTransferListener(TransferListener t)
Add a
TransferListener |
void |
headers(FluentCaseInsensitiveStringsMap headers)
Set headers to this listener.
|
AsyncHandler.STATE |
onBodyPartReceived(HttpResponseBodyPart content)
Invoked as soon as some response body part are received.
|
Response |
onCompleted(Response response)
Invoked once the HTTP response processing is finished.
|
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. |
void |
onThrowable(Throwable t)
Invoked when an unexpected exception occurs during the processing of the response.
|
TransferCompletionHandler |
removeTransferListener(TransferListener t)
Remove a
TransferListener |
onCompleted, onContentWriteCompleted, onStatusReceivedpublic TransferCompletionHandler()
org.asynchttpclient.Response#getResponseBody(),
org.asynchttpclient.Response#getResponseBodyAsStream() and Response.getResponseBodyExcerpt(int) will throw an IllegalStateException if called.public TransferCompletionHandler(boolean accumulateResponseBytes)
org.asynchttpclient.Response#getResponseBody() get called. The
default is false.accumulateResponseBytes - true to accumulates bytes in memory.public TransferCompletionHandler addTransferListener(TransferListener t)
TransferListenert - a TransferListenerpublic TransferCompletionHandler removeTransferListener(TransferListener t)
TransferListenert - a TransferListenerpublic void headers(FluentCaseInsensitiveStringsMap headers)
headers - FluentCaseInsensitiveStringsMappublic AsyncHandler.STATE onHeadersReceived(HttpResponseHeaders headers) throws Exception
AsyncHandleronHeadersReceived in interface AsyncHandler<Response>onHeadersReceived in class AsyncCompletionHandler<Response>headers - the HTTP headers.AsyncHandler.STATE telling to CONTINUE or ABORT the current processing.Exception - if something wrong happenspublic AsyncHandler.STATE onBodyPartReceived(HttpResponseBodyPart content) throws Exception
AsyncHandleronBodyPartReceived in interface AsyncHandler<Response>onBodyPartReceived in class AsyncCompletionHandler<Response>content - response's body part.AsyncHandler.STATE telling to CONTINUE or ABORT the current processing.Exception - if something wrong happenspublic Response onCompleted(Response response) throws Exception
AsyncCompletionHandleronCompleted in class AsyncCompletionHandlerBaseresponse - The ResponseFutureException - if something wrong happenspublic AsyncHandler.STATE onHeaderWriteCompleted()
AsyncCompletionHandlerFile, String or FileInputStream has been fully
written on the I/O socket.onHeaderWriteCompleted in interface ProgressAsyncHandler<Response>onHeaderWriteCompleted in class AsyncCompletionHandler<Response>AsyncHandler.STATE telling to CONTINUE or ABORT the current processing.public AsyncHandler.STATE onContentWriteProgress(long amount, long current, long total)
AsyncCompletionHandlerRequest body as been progressed.onContentWriteProgress in interface ProgressAsyncHandler<Response>onContentWriteProgress in class AsyncCompletionHandler<Response>amount - The amount of bytes to transfer.current - The amount of bytes transferredtotal - The total number of bytes transferredAsyncHandler.STATE telling to CONTINUE or ABORT the current processing.public void onThrowable(Throwable t)
AsyncHandleronThrowable in interface AsyncHandler<Response>onThrowable in class AsyncCompletionHandlerBaset - a ThrowableCopyright © 2018. All Rights Reserved.