Package org.asynchttpclient.handler
Class TransferCompletionHandler
- java.lang.Object
-
- org.asynchttpclient.AsyncCompletionHandler<Response>
-
- org.asynchttpclient.AsyncCompletionHandlerBase
-
- org.asynchttpclient.handler.TransferCompletionHandler
-
- All Implemented Interfaces:
AsyncHandler<Response>,ProgressAsyncHandler<Response>
public class TransferCompletionHandler extends AsyncCompletionHandlerBase
AAsyncHandlerthat can be used to notify a set ofTransferListener
AsyncHttpClient client = new AsyncHttpClient(); TransferCompletionHandler tl = new TransferCompletionHandler(); tl.addTransferListener(new TransferListener() { public void onRequestHeadersSent(HttpHeaders headers) { } public void onResponseHeadersReceived(HttpHeaders 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 org.asynchttpclient.AsyncHandler
AsyncHandler.State
-
-
Constructor Summary
Constructors Constructor 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 whenResponse.getResponseBody()get called.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description TransferCompletionHandleraddTransferListener(TransferListener t)voidheaders(io.netty.handler.codec.http.HttpHeaders headers)AsyncHandler.StateonBodyPartReceived(HttpResponseBodyPart content)Invoked as soon as some response body part are received.@Nullable ResponseonCompleted(@Nullable Response response)Invoked once the HTTP response processing is finished.AsyncHandler.StateonContentWriteProgress(long amount, long current, long total)Invoked when the I/O operation associated with theRequestbody as been progressed.AsyncHandler.StateonHeadersReceived(io.netty.handler.codec.http.HttpHeaders headers)Invoked as soon as the HTTP headers have been received.AsyncHandler.StateonHeadersWritten()Invoked when the HTTP headers have been fully written on the I/O socket.voidonThrowable(Throwable t)Invoked when an unexpected exception occurs during the processing of the response.AsyncHandler.StateonTrailingHeadersReceived(io.netty.handler.codec.http.HttpHeaders headers)Invoked when trailing headers have been received.TransferCompletionHandlerremoveTransferListener(TransferListener t)-
Methods inherited from class org.asynchttpclient.AsyncCompletionHandler
onCompleted, onContentWritten, onStatusReceived
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.asynchttpclient.AsyncHandler
onConnectionOffer, onConnectionPoolAttempt, onConnectionPooled, onHostnameResolutionAttempt, onHostnameResolutionFailure, onHostnameResolutionSuccess, onRequestSend, onRetry, onTcpConnectAttempt, onTcpConnectFailure, onTcpConnectSuccess, onTlsHandshakeAttempt, onTlsHandshakeFailure, onTlsHandshakeSuccess
-
-
-
-
Constructor Detail
-
TransferCompletionHandler
public TransferCompletionHandler()
Create a TransferCompletionHandler that will not accumulate bytes. The resultingResponse.getResponseBody(),Response.getResponseBodyAsStream()will throw an IllegalStateException if called.
-
TransferCompletionHandler
public TransferCompletionHandler(boolean accumulateResponseBytes)
Create a TransferCompletionHandler that can or cannot accumulate bytes and make it available whenResponse.getResponseBody()get called. The default is false.- Parameters:
accumulateResponseBytes- true to accumulates bytes in memory.
-
-
Method Detail
-
addTransferListener
public TransferCompletionHandler addTransferListener(TransferListener t)
-
removeTransferListener
public TransferCompletionHandler removeTransferListener(TransferListener t)
-
headers
public void headers(io.netty.handler.codec.http.HttpHeaders headers)
-
onHeadersReceived
public AsyncHandler.State onHeadersReceived(io.netty.handler.codec.http.HttpHeaders headers) throws Exception
Description copied from interface:AsyncHandlerInvoked as soon as the HTTP headers have been received.- 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
-
onTrailingHeadersReceived
public AsyncHandler.State onTrailingHeadersReceived(io.netty.handler.codec.http.HttpHeaders headers) throws Exception
Description copied from interface:AsyncHandlerInvoked when trailing headers have been received.- Specified by:
onTrailingHeadersReceivedin interfaceAsyncHandler<Response>- Overrides:
onTrailingHeadersReceivedin classAsyncCompletionHandler<Response>- Parameters:
headers- the trailing HTTP headers.- Returns:
- a
AsyncHandler.Statetelling to CONTINUE or ABORT the current processing. - Throws:
Exception- if something wrong happens
-
onBodyPartReceived
public AsyncHandler.State onBodyPartReceived(HttpResponseBodyPart content) throws Exception
Description copied from interface:AsyncHandlerInvoked as soon as some response body part are received. Could be invoked many times. Beware that, depending on the provider (Netty) this can be notified with empty body parts.- 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. Aborting will also close the connection. - Throws:
Exception- if something wrong happens
-
onCompleted
@Nullable public @Nullable Response onCompleted(@Nullable @Nullable Response response) throws Exception
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
-
onHeadersWritten
public AsyncHandler.State onHeadersWritten()
Description copied from class:AsyncCompletionHandlerInvoked when the HTTP headers have been fully written on the I/O socket.- Specified by:
onHeadersWrittenin interfaceProgressAsyncHandler<Response>- Overrides:
onHeadersWrittenin classAsyncCompletionHandler<Response>- Returns:
- a
AsyncHandler.Statetelling to CONTINUE or ABORT the current processing.
-
onContentWriteProgress
public AsyncHandler.State onContentWriteProgress(long amount, long current, long total)
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 transfercurrent- The amount of bytes transferredtotal- The total number of bytes transferred- Returns:
- a
AsyncHandler.Statetelling to CONTINUE or ABORT the current processing.
-
onThrowable
public void onThrowable(Throwable t)
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 classAsyncCompletionHandler<Response>- Parameters:
t- aThrowable
-
-