类 EventListener
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
- call -> (dns -> connect -> secure connect)* -> request events
- call -> (connection acquire/release)*
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.
-
嵌套类概要
嵌套类 -
字段概要
字段 -
构造器概要
构造器 -
方法概要
修饰符和类型方法说明voidInvoked immediately after a call has completely ended.voidcallFailed(Call call, IOException ioe) Invoked when a call fails permanently.voidInvoked as soon as a call is enqueued or executed by a client.voidconnectEnd(Call call, InetSocketAddress inetSocketAddress, Proxy proxy, Protocol protocol) Invoked immediately after a socket connection was attempted.voidconnectFailed(Call call, InetSocketAddress inetSocketAddress, Proxy proxy, Protocol protocol, IOException ioe) Invoked when a connection attempt fails.voidconnectionAcquired(Call call, Connection connection) Invoked after a connection has been acquired for thecall.voidconnectionReleased(Call call, Connection connection) Invoked after a connection has been released for thecall.voidconnectStart(Call call, InetSocketAddress inetSocketAddress, Proxy proxy) Invoked just prior to initiating a socket connection.voiddnsEnd(Call call, String domainName, List<InetAddress> inetAddressList) Invoked immediately after a DNS lookup.voidInvoked just prior to a DNS lookup.voidrequestBodyEnd(Call call, long byteCount) Invoked immediately after sending a request body.voidrequestBodyStart(Call call) Invoked just prior to sending a request body.voidrequestFailed(Call call, IOException ioe) Invoked when a request fails to be written.voidrequestHeadersEnd(Call call, Request request) Invoked immediately after sending request headers.voidrequestHeadersStart(Call call) Invoked just prior to sending request headers.voidresponseBodyEnd(Call call, long byteCount) Invoked immediately after receiving a response body and completing reading it.voidresponseBodyStart(Call call) Invoked just prior to receiving the response body.voidresponseFailed(Call call, IOException ioe) Invoked when a response fails to be read.voidresponseHeadersEnd(Call call, Response response) Invoked immediately after receiving response headers.voidresponseHeadersStart(Call call) Invoked just prior to receiving response headers.voidsecureConnectEnd(Call call, Handshake handshake) Invoked immediately after a TLS connection was attempted.voidsecureConnectStart(Call call) Invoked just prior to initiating a TLS connection.
-
字段详细资料
-
NONE
-
-
构造器详细资料
-
EventListener
public EventListener()
-
-
方法详细资料
-
callStart
Invoked as soon as a call is enqueued or executed by a client. In case of thread or stream limits, this call may be executed well before processing the request is able to begin.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 andcallEnd(com.lark.oapi.okhttp.Call)/callFailed(com.lark.oapi.okhttp.Call, java.io.IOException)pair. -
dnsStart
Invoked just prior to a DNS lookup. SeeDns.lookup(String).This can be invoked more than 1 time for a single
Call. For example, if the response to theCall.request()is a redirect to a different host.If the
Callis able to reuse an existing pooled connection, this method will not be invoked. SeeConnectionPool. -
dnsEnd
Invoked immediately after a DNS lookup.This method is invoked after
dnsStart(com.lark.oapi.okhttp.Call, java.lang.String). -
connectStart
Invoked just prior to initiating a socket connection.This method will be invoked if no existing connection in the
ConnectionPoolcan be reused.This can be invoked more than 1 time for a single
Call. For example, if the response to theCall.request()is a redirect to a different address, or a connection is retried. -
secureConnectStart
Invoked just prior to initiating a TLS connection.This method is invoked if the following conditions are met:
- The
Call.request()requires TLS. - No existing connection from the
ConnectionPoolcan be reused.
This can be invoked more than 1 time for a single
Call. For example, if the response to theCall.request()is a redirect to a different address, or a connection is retried. - The
-
secureConnectEnd
Invoked immediately after a TLS connection was attempted.This method is invoked after
secureConnectStart(com.lark.oapi.okhttp.Call). -
connectEnd
public void connectEnd(Call call, InetSocketAddress inetSocketAddress, Proxy proxy, @Nullable Protocol protocol) Invoked immediately after a socket connection was attempted.If the
calluses HTTPS, this will be invoked aftersecureConnectEnd(Call, Handshake), otherwise it will invoked afterconnectStart(Call, InetSocketAddress, Proxy). -
connectFailed
public void connectFailed(Call call, InetSocketAddress inetSocketAddress, Proxy proxy, @Nullable Protocol protocol, IOException ioe) Invoked when a connection attempt fails. This failure is not terminal if further routes are available and failure recovery is enabled.If the
calluses HTTPS, this will be invoked aftersecureConnectEnd(Call, Handshake), otherwise it will invoked afterconnectStart(Call, InetSocketAddress, Proxy). -
connectionAcquired
Invoked after a connection has been acquired for thecall.This can be invoked more than 1 time for a single
Call. For example, if the response to theCall.request()is a redirect to a different address. -
connectionReleased
Invoked after a connection has been released for thecall.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 theCall.request()is a redirect to a different address. -
requestHeadersStart
Invoked just prior to sending request headers.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 theCall.request()is a redirect to a different address. -
requestHeadersEnd
Invoked immediately after sending request headers.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.
-
requestBodyStart
Invoked just prior to sending a request body. Will only be invoked for request allowing and having a request body to send.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 theCall.request()is a redirect to a different address. -
requestBodyEnd
Invoked immediately after sending a request body.This method is always invoked after
requestBodyStart(Call). -
requestFailed
Invoked when a request fails to be written.This method is invoked after
requestHeadersStart(com.lark.oapi.okhttp.Call)orrequestBodyStart(com.lark.oapi.okhttp.Call). Note that request failures do not necessarily fail the entire call. -
responseHeadersStart
Invoked just prior to receiving response headers.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 theCall.request()is a redirect to a different address. -
responseHeadersEnd
Invoked immediately after receiving response headers.This method is always invoked after
responseHeadersStart(com.lark.oapi.okhttp.Call).- 参数:
response- the response received over the network. It is an error to access the body of this response.
-
responseBodyStart
Invoked just prior to receiving the response body.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. -
responseBodyEnd
Invoked immediately after receiving a response body and completing reading it.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). -
responseFailed
Invoked when a response fails to be read.This method is invoked after
responseHeadersStart(com.lark.oapi.okhttp.Call)orresponseBodyStart(com.lark.oapi.okhttp.Call). Note that response failures do not necessarily fail the entire call. -
callEnd
Invoked immediately after a call has completely ended. This includes delayed consumption of response body by the caller.This method is always invoked after
callStart(Call). -
callFailed
Invoked when a call fails permanently.This method is always invoked after
callStart(Call).
-