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, onStatusReceived
public 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)
TransferListener
t
- a TransferListener
public TransferCompletionHandler removeTransferListener(TransferListener t)
TransferListener
t
- a TransferListener
public void headers(FluentCaseInsensitiveStringsMap headers)
headers
- FluentCaseInsensitiveStringsMap
public AsyncHandler.STATE onHeadersReceived(HttpResponseHeaders headers) throws Exception
AsyncHandler
onHeadersReceived
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
AsyncHandler
onBodyPartReceived
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
AsyncCompletionHandler
onCompleted
in class AsyncCompletionHandlerBase
response
- The Response
Future
Exception
- if something wrong happenspublic AsyncHandler.STATE onHeaderWriteCompleted()
AsyncCompletionHandler
File
, 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)
AsyncCompletionHandler
Request
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)
AsyncHandler
onThrowable
in interface AsyncHandler<Response>
onThrowable
in class AsyncCompletionHandlerBase
t
- a Throwable
Copyright © 2014. All Rights Reserved.