T
- Type of object returned by the Future.get()
public interface AsyncHandler<T>
onStatusReceived(HttpResponseStatus)
,onHeadersReceived(HttpHeaders)
,onBodyPartReceived(HttpResponseBodyPart)
, which could be invoked multiple times,onTrailingHeadersReceived(HttpHeaders)
, which is only invoked if trailing HTTP headers are receivedonCompleted()
, once the response has been fully read.AsyncHandler.State.ABORT
from any of those callback methods will interrupt asynchronous response
processing, after that only onCompleted()
is going to be called.
It is recommended to create a new instance instead.AsyncHandler ah = new AsyncHandler() {....}; AsyncHttpClient client = new AsyncHttpClient(); client.prepareGet("http://...").execute(ah); client.prepareGet("http://...").execute(ah);
Do NOT perform any blocking operation in there, typically trying to send another request and call get() on its future. There's a chance you might end up in a dead lock. If you really to perform blocking operation, executed it in a different dedicated thread pool.
Modifier and Type | Interface and Description |
---|---|
static class |
AsyncHandler.State |
Modifier and Type | Method and Description |
---|---|
AsyncHandler.State |
onBodyPartReceived(HttpResponseBodyPart bodyPart)
Invoked as soon as some response body part are received.
|
T |
onCompleted()
Invoked once the HTTP response processing is finished.
|
default void |
onConnectionOffer(io.netty.channel.Channel connection)
Notify the callback when trying to offer a connection to the pool.
|
default void |
onConnectionPoolAttempt()
Notify the callback when trying to fetch a connection from the pool.
|
default void |
onConnectionPooled(io.netty.channel.Channel connection)
Notify the callback when a new connection was successfully fetched from the pool.
|
AsyncHandler.State |
onHeadersReceived(io.netty.handler.codec.http.HttpHeaders headers)
Invoked as soon as the HTTP headers have been received.
|
default void |
onHostnameResolutionAttempt(java.lang.String name)
Notify the callback before hostname resolution
|
default void |
onHostnameResolutionFailure(java.lang.String name,
java.lang.Throwable cause)
Notify the callback after hostname resolution failed.
|
default void |
onHostnameResolutionSuccess(java.lang.String name,
java.util.List<java.net.InetSocketAddress> addresses)
Notify the callback after hostname resolution was successful.
|
default void |
onRequestSend(NettyRequest request)
Notify the callback when a request is being written on the channel.
|
default void |
onRetry()
Notify the callback every time a request is being retried.
|
AsyncHandler.State |
onStatusReceived(HttpResponseStatus responseStatus)
Invoked as soon as the HTTP status line has been received
|
default void |
onTcpConnectAttempt(java.net.InetSocketAddress remoteAddress)
Notify the callback when trying to open a new connection.
|
default void |
onTcpConnectFailure(java.net.InetSocketAddress remoteAddress,
java.lang.Throwable cause)
Notify the callback after a failed connect.
|
default void |
onTcpConnectSuccess(java.net.InetSocketAddress remoteAddress,
io.netty.channel.Channel connection)
Notify the callback after a successful connect
|
void |
onThrowable(java.lang.Throwable t)
Invoked when an unexpected exception occurs during the processing of the response.
|
default void |
onTlsHandshakeAttempt()
Notify the callback before TLS handshake
|
default void |
onTlsHandshakeFailure(java.lang.Throwable cause)
Notify the callback after the TLS failed
|
default void |
onTlsHandshakeSuccess()
Notify the callback after the TLS was successful
|
default AsyncHandler.State |
onTrailingHeadersReceived(io.netty.handler.codec.http.HttpHeaders headers)
Invoked when trailing headers have been received.
|
AsyncHandler.State onStatusReceived(HttpResponseStatus responseStatus) throws java.lang.Exception
responseStatus
- the status code and test of the responseAsyncHandler.State
telling to CONTINUE or ABORT the current processing.java.lang.Exception
- if something wrong happensAsyncHandler.State onHeadersReceived(io.netty.handler.codec.http.HttpHeaders headers) throws java.lang.Exception
headers
- the HTTP headers.AsyncHandler.State
telling to CONTINUE or ABORT the current processing.java.lang.Exception
- if something wrong happensAsyncHandler.State onBodyPartReceived(HttpResponseBodyPart bodyPart) throws java.lang.Exception
bodyPart
- response's body part.AsyncHandler.State
telling to CONTINUE or ABORT the current processing. Aborting will also close the connection.java.lang.Exception
- if something wrong happensdefault AsyncHandler.State onTrailingHeadersReceived(io.netty.handler.codec.http.HttpHeaders headers) throws java.lang.Exception
headers
- the trailing HTTP headers.AsyncHandler.State
telling to CONTINUE or ABORT the current processing.java.lang.Exception
- if something wrong happensvoid onThrowable(java.lang.Throwable t)
t
- a Throwable
T onCompleted() throws java.lang.Exception
Future
java.lang.Exception
- if something wrong happensdefault void onHostnameResolutionAttempt(java.lang.String name)
name
- the name to be resolveddefault void onHostnameResolutionSuccess(java.lang.String name, java.util.List<java.net.InetSocketAddress> addresses)
name
- the name to be resolvedaddresses
- the resolved addressesdefault void onHostnameResolutionFailure(java.lang.String name, java.lang.Throwable cause)
name
- the name to be resolvedcause
- the failure causedefault void onTcpConnectAttempt(java.net.InetSocketAddress remoteAddress)
Might be called several times if the name was resolved to multiple addresses and we failed to connect to the first(s) one(s).
remoteAddress
- the address we try to connect todefault void onTcpConnectSuccess(java.net.InetSocketAddress remoteAddress, io.netty.channel.Channel connection)
remoteAddress
- the address we try to connect toconnection
- the connectiondefault void onTcpConnectFailure(java.net.InetSocketAddress remoteAddress, java.lang.Throwable cause)
Might be called several times, or be followed by onTcpConnectSuccess when the name was resolved to multiple addresses.
remoteAddress
- the address we try to connect tocause
- the cause of the failuredefault void onTlsHandshakeAttempt()
default void onTlsHandshakeSuccess()
default void onTlsHandshakeFailure(java.lang.Throwable cause)
cause
- the cause of the failuredefault void onConnectionPoolAttempt()
default void onConnectionPooled(io.netty.channel.Channel connection)
connection
- the connectiondefault void onConnectionOffer(io.netty.channel.Channel connection)
connection
- the connectiondefault void onRequestSend(NettyRequest request)
request
- the real request object as passed to the providerdefault void onRetry()
Copyright © 2018. All Rights Reserved.