public abstract class EventListener extends Object
All start/connect/acquire events will eventually receive a matching end/release event, either successful (non-null parameters), or failed (non-null throwable). The first common parameters of each event pair are used to link the event in case of concurrent or repeated events e.g. dnsStart(call, domainName) -> dnsEnd(call, domainName, inetAddressList).
Nesting is as follows
Request events are ordered: requestHeaders -> requestBody -> responseHeaders -> responseBody
Since connections may be reused, the dns and connect events may not be present for a call, or may be repeated in case of failure retries, even concurrently in case of happy eyeballs type scenarios. A redirect cross domain, or to use https may cause additional connection and request events.
All event methods must execute fast, without external locking, cannot throw exceptions, attempt to mutate the event parameters, or be re-entrant back into the client. Any IO - writing to files or network should be done asynchronously.
Modifier and Type | Class and Description |
---|---|
static interface |
EventListener.Factory |
Modifier and Type | Field and Description |
---|---|
static EventListener |
NONE |
Constructor and Description |
---|
EventListener() |
Modifier and Type | Method and Description |
---|---|
void |
callEnd(Call call)
Invoked immediately after a call has completely ended.
|
void |
callFailed(Call call,
IOException ioe)
Invoked when a call fails permanently.
|
void |
callStart(Call call)
Invoked as soon as a call is enqueued or executed by a client.
|
void |
connectEnd(Call call,
InetSocketAddress inetSocketAddress,
Proxy proxy,
Protocol protocol)
Invoked immediately after a socket connection was attempted.
|
void |
connectFailed(Call call,
InetSocketAddress inetSocketAddress,
Proxy proxy,
Protocol protocol,
IOException ioe)
Invoked when a connection attempt fails.
|
void |
connectionAcquired(Call call,
Connection connection)
Invoked after a connection has been acquired for the
call . |
void |
connectionReleased(Call call,
Connection connection)
Invoked after a connection has been released for the
call . |
void |
connectStart(Call call,
InetSocketAddress inetSocketAddress,
Proxy proxy)
Invoked just prior to initiating a socket connection.
|
void |
dnsEnd(Call call,
String domainName,
List<InetAddress> inetAddressList)
Invoked immediately after a DNS lookup.
|
void |
dnsStart(Call call,
String domainName)
Invoked just prior to a DNS lookup.
|
void |
requestBodyEnd(Call call,
long byteCount)
Invoked immediately after sending a request body.
|
void |
requestBodyStart(Call call)
Invoked just prior to sending a request body.
|
void |
requestFailed(Call call,
IOException ioe)
Invoked when a request fails to be written.
|
void |
requestHeadersEnd(Call call,
Request request)
Invoked immediately after sending request headers.
|
void |
requestHeadersStart(Call call)
Invoked just prior to sending request headers.
|
void |
responseBodyEnd(Call call,
long byteCount)
Invoked immediately after receiving a response body and completing reading it.
|
void |
responseBodyStart(Call call)
Invoked just prior to receiving the response body.
|
void |
responseFailed(Call call,
IOException ioe)
Invoked when a response fails to be read.
|
void |
responseHeadersEnd(Call call,
Response response)
Invoked immediately after receiving response headers.
|
void |
responseHeadersStart(Call call)
Invoked just prior to receiving response headers.
|
void |
secureConnectEnd(Call call,
Handshake handshake)
Invoked immediately after a TLS connection was attempted.
|
void |
secureConnectStart(Call call)
Invoked just prior to initiating a TLS connection.
|
public static final EventListener NONE
public void callStart(Call call)
This will be invoked only once for a single Call
. Retries of different routes
or redirects will be handled within the boundaries of a single callStart and callEnd(okhttp3.Call)
/callFailed(okhttp3.Call, java.io.IOException)
pair.
public void dnsStart(Call call, String domainName)
Dns.lookup(String)
.
This can be invoked more than 1 time for a single Call
. For example, if the response
to the Call.request()
is a redirect to a different host.
If the Call
is able to reuse an existing pooled connection, this method will not be
invoked. See ConnectionPool
.
public void dnsEnd(Call call, String domainName, List<InetAddress> inetAddressList)
This method is invoked after dnsStart(okhttp3.Call, java.lang.String)
.
public void connectStart(Call call, InetSocketAddress inetSocketAddress, Proxy proxy)
This method will be invoked if no existing connection in the ConnectionPool
can be
reused.
This can be invoked more than 1 time for a single Call
. For example, if the response
to the Call.request()
is a redirect to a different address, or a connection is retried.
public void secureConnectStart(Call call)
This method is invoked if the following conditions are met:
Call.request()
requires TLS.ConnectionPool
can be reused.This can be invoked more than 1 time for a single Call
. For example, if the response
to the Call.request()
is a redirect to a different address, or a connection is retried.
public void secureConnectEnd(Call call, @Nullable Handshake handshake)
This method is invoked after secureConnectStart(okhttp3.Call)
.
public void connectEnd(Call call, InetSocketAddress inetSocketAddress, Proxy proxy, @Nullable Protocol protocol)
If the call
uses HTTPS, this will be invoked after
secureConnectEnd(Call, Handshake)
, otherwise it will invoked after
connectStart(Call, InetSocketAddress, Proxy)
.
public void connectFailed(Call call, InetSocketAddress inetSocketAddress, Proxy proxy, @Nullable Protocol protocol, IOException ioe)
If the call
uses HTTPS, this will be invoked after secureConnectEnd(Call,
Handshake)
, otherwise it will invoked after connectStart(Call, InetSocketAddress,
Proxy)
.
public void connectionAcquired(Call call, Connection connection)
call
.
This can be invoked more than 1 time for a single Call
. For example, if the response
to the Call.request()
is a redirect to a different address.
public void connectionReleased(Call call, Connection connection)
call
.
This method is always invoked after connectionAcquired(Call, Connection)
.
This can be invoked more than 1 time for a single Call
. For example, if the response
to the Call.request()
is a redirect to a different address.
public void requestHeadersStart(Call call)
The connection is implicit, and will generally relate to the last
connectionAcquired(Call, Connection)
event.
This can be invoked more than 1 time for a single Call
. For example, if the response
to the Call.request()
is a redirect to a different address.
public void requestHeadersEnd(Call call, Request request)
This method is always invoked after requestHeadersStart(Call)
.
request
- the request sent over the network. It is an error to access the body of this
request.public void requestBodyStart(Call call)
The connection is implicit, and will generally relate to the last
connectionAcquired(Call, Connection)
event.
This can be invoked more than 1 time for a single Call
. For example, if the response
to the Call.request()
is a redirect to a different address.
public void requestBodyEnd(Call call, long byteCount)
This method is always invoked after requestBodyStart(Call)
.
public void requestFailed(Call call, IOException ioe)
This method is invoked after requestHeadersStart(okhttp3.Call)
or requestBodyStart(okhttp3.Call)
. Note
that request failures do not necessarily fail the entire call.
public void responseHeadersStart(Call call)
The connection is implicit, and will generally relate to the last
connectionAcquired(Call, Connection)
event.
This can be invoked more than 1 time for a single Call
. For example, if the response
to the Call.request()
is a redirect to a different address.
public void responseHeadersEnd(Call call, Response response)
This method is always invoked after responseHeadersStart(okhttp3.Call)
.
response
- the response received over the network. It is an error to access the body of
this response.public void responseBodyStart(Call call)
The connection is implicit, and will generally relate to the last
connectionAcquired(Call, Connection)
event.
This will usually be invoked only 1 time for a single Call
,
exceptions are a limited set of cases including failure recovery.
public void responseBodyEnd(Call call, long byteCount)
Will only be invoked for requests having a response body e.g. won't be invoked for a websocket upgrade.
This method is always invoked after requestBodyStart(Call)
.
public void responseFailed(Call call, IOException ioe)
This method is invoked after responseHeadersStart(okhttp3.Call)
or responseBodyStart(okhttp3.Call)
.
Note that response failures do not necessarily fail the entire call.
public void callEnd(Call call)
This method is always invoked after callStart(Call)
.
public void callFailed(Call call, IOException ioe)
This method is always invoked after callStart(Call)
.
Copyright © 2019. All rights reserved.