Package com.ning.http.client.listener
Class TransferCompletionHandler
java.lang.Object
com.ning.http.client.AsyncCompletionHandler<Response>
com.ning.http.client.AsyncCompletionHandlerBase
com.ning.http.client.listener.TransferCompletionHandler
- All Implemented Interfaces:
AsyncHandler<Response>,ProgressAsyncHandler<Response>
A
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();
-
Nested Class Summary
Nested classes/interfaces inherited from interface com.ning.http.client.AsyncHandler
AsyncHandler.STATE -
Constructor Summary
ConstructorsConstructorDescriptionCreate a TransferCompletionHandler that will not accumulate bytes.TransferCompletionHandler(boolean accumulateResponseBytes) Create a TransferCompletionHandler that can or cannot accumulate bytes and make it available whenorg.asynchttpclient.Response#getResponseBody()get called. -
Method Summary
Modifier and TypeMethodDescriptionAdd aTransferListenervoidheaders(FluentCaseInsensitiveStringsMap headers) Set headers to this listener.onBodyPartReceived(HttpResponseBodyPart content) Invoked as soon as some response body part are received.onCompleted(Response response) Invoked once the HTTP response processing is finished.onContentWriteProgress(long amount, long current, long total) Invoked when the I/O operation associated with theRequestbody as been progressed.onHeadersReceived(HttpResponseHeaders headers) Invoked as soon as the HTTP headers has been received.Invoked when the content (aFile,StringorFileInputStreamhas been fully written on the I/O socket.voidInvoked when an unexpected exception occurs during the processing of the response.Remove aTransferListenerMethods inherited from class com.ning.http.client.AsyncCompletionHandler
onCompleted, onContentWriteCompleted, onStatusReceived
-
Constructor Details
-
TransferCompletionHandler
public TransferCompletionHandler()Create a TransferCompletionHandler that will not accumulate bytes. The resultingorg.asynchttpclient.Response#getResponseBody(),org.asynchttpclient.Response#getResponseBodyAsStream()andResponse.getResponseBodyExcerpt(int)will throw an IllegalStateException if called. -
TransferCompletionHandler
public TransferCompletionHandler(boolean accumulateResponseBytes) Create a TransferCompletionHandler that can or cannot accumulate bytes and make it available whenorg.asynchttpclient.Response#getResponseBody()get called. The default is false.- Parameters:
accumulateResponseBytes- true to accumulates bytes in memory.
-
-
Method Details
-
addTransferListener
Add aTransferListener- Parameters:
t- aTransferListener- Returns:
- this
-
removeTransferListener
Remove aTransferListener- Parameters:
t- aTransferListener- Returns:
- this
-
headers
Set headers to this listener.- Parameters:
headers-FluentCaseInsensitiveStringsMap
-
onHeadersReceived
Description copied from interface:AsyncHandlerInvoked as soon as the HTTP headers has been received. Can potentially be invoked more than once if a broken server sent trailing headers.- Specified by:
onHeadersReceivedin interfaceAsyncHandler<Response>- Overrides:
onHeadersReceivedin classAsyncCompletionHandler<Response>- Parameters:
headers- the HTTP headers.- Returns:
- a
AsyncHandler.STATEtelling to CONTINUE or ABORT the current processing. - Throws:
Exception- if something wrong happens
-
onBodyPartReceived
Description copied from interface:AsyncHandlerInvoked as soon as some response body part are received. Could be invoked many times.- Specified by:
onBodyPartReceivedin interfaceAsyncHandler<Response>- Overrides:
onBodyPartReceivedin classAsyncCompletionHandler<Response>- Parameters:
content- response's body part.- Returns:
- a
AsyncHandler.STATEtelling to CONTINUE or ABORT the current processing. - Throws:
Exception- if something wrong happens
-
onCompleted
Description copied from class:AsyncCompletionHandlerInvoked once the HTTP response processing is finished.- Overrides:
onCompletedin classAsyncCompletionHandlerBase- Parameters:
response- TheResponse- Returns:
- T Value that will be returned by the associated
Future - Throws:
Exception- if something wrong happens
-
onHeaderWriteCompleted
Description copied from class:AsyncCompletionHandlerInvoked when the content (aFile,StringorFileInputStreamhas been fully written on the I/O socket.- Specified by:
onHeaderWriteCompletedin interfaceProgressAsyncHandler<Response>- Overrides:
onHeaderWriteCompletedin classAsyncCompletionHandler<Response>- Returns:
- a
AsyncHandler.STATEtelling to CONTINUE or ABORT the current processing.
-
onContentWriteProgress
Description copied from class:AsyncCompletionHandlerInvoked when the I/O operation associated with theRequestbody as been progressed.- Specified by:
onContentWriteProgressin interfaceProgressAsyncHandler<Response>- Overrides:
onContentWriteProgressin classAsyncCompletionHandler<Response>- Parameters:
amount- The amount of bytes to transfer.current- The amount of bytes transferredtotal- The total number of bytes transferred- Returns:
- a
AsyncHandler.STATEtelling to CONTINUE or ABORT the current processing.
-
onThrowable
Description copied from interface:AsyncHandlerInvoked when an unexpected exception occurs during the processing of the response. The exception may have been produced by implementation of onXXXReceived method invocation.- Specified by:
onThrowablein interfaceAsyncHandler<Response>- Overrides:
onThrowablein classAsyncCompletionHandlerBase- Parameters:
t- aThrowable
-