public class TransferCompletionHandler extends AsyncCompletionHandlerBase
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(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();
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
Response.getResponseBody() get called. |
Modifier and Type | Method and Description |
---|---|
TransferCompletionHandler |
addTransferListener(TransferListener t) |
void |
headers(io.netty.handler.codec.http.HttpHeaders headers) |
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(io.netty.handler.codec.http.HttpHeaders headers)
Invoked as soon as the HTTP headers have been received.
|
AsyncHandler.State |
onHeadersWritten()
Invoked when the HTTP headers have been fully written on the I/O socket.
|
void |
onThrowable(Throwable t)
Invoked when an unexpected exception occurs during the processing of the response.
|
AsyncHandler.State |
onTrailingHeadersReceived(io.netty.handler.codec.http.HttpHeaders headers)
Invoked when trailing headers have been received.
|
TransferCompletionHandler |
removeTransferListener(TransferListener t) |
onCompleted, onContentWritten, onStatusReceived
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
onConnectionOffer, onConnectionPoolAttempt, onConnectionPooled, onHostnameResolutionAttempt, onHostnameResolutionFailure, onHostnameResolutionSuccess, onRequestSend, onRetry, onTcpConnectAttempt, onTcpConnectFailure, onTcpConnectSuccess, onTlsHandshakeAttempt, onTlsHandshakeFailure, onTlsHandshakeSuccess
public TransferCompletionHandler()
Response.getResponseBody()
,
Response.getResponseBodyAsStream()
will throw an IllegalStateException if called.public TransferCompletionHandler(boolean accumulateResponseBytes)
Response.getResponseBody()
get called. The
default is false.accumulateResponseBytes
- true to accumulates bytes in memory.public TransferCompletionHandler addTransferListener(TransferListener t)
public TransferCompletionHandler removeTransferListener(TransferListener t)
public void headers(io.netty.handler.codec.http.HttpHeaders headers)
public AsyncHandler.State onHeadersReceived(io.netty.handler.codec.http.HttpHeaders 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 onTrailingHeadersReceived(io.netty.handler.codec.http.HttpHeaders headers) throws Exception
AsyncHandler
onTrailingHeadersReceived
in interface AsyncHandler<Response>
onTrailingHeadersReceived
in class AsyncCompletionHandler<Response>
headers
- the trailing 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. Aborting will also close the connection.Exception
- if something wrong happenspublic Response onCompleted(Response response) throws Exception
AsyncCompletionHandlerBase
onCompleted
in class AsyncCompletionHandlerBase
response
- The Response
Future
Exception
- if something wrong happenspublic AsyncHandler.State onHeadersWritten()
AsyncCompletionHandler
onHeadersWritten
in interface ProgressAsyncHandler<Response>
onHeadersWritten
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 transfercurrent
- 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 AsyncCompletionHandler<Response>
t
- a Throwable
Copyright © 2019. All rights reserved.