EventListener
Listener for metrics events. Extend this class to monitor the quantity, size, and duration of your application's HTTP calls.
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)
.
Events are typically nested with this structure:
call (callStart, callEnd, callFailed)
proxy selection (proxySelectStart, proxySelectEnd)
connect (connectStart, connectEnd, connectFailed)
secure connect (secureConnectStart, secureConnectEnd)
connection held (connectionAcquired, connectionReleased)
request (requestFailed)
headers (requestHeadersStart, requestHeadersEnd)
body (requestBodyStart, requestBodyEnd)
response (responseFailed)
headers (responseHeadersStart, responseHeadersEnd)
body (responseBodyStart, responseBodyEnd)
This nesting is typical but not strict. For example, when calls use "Expect: continue" the request body start and end events occur within the response header events. Similarly, duplex calls interleave the request and response bodies.
Since connections may be reused, the proxy selection, DNS, and connect events may not be present for a call. In future releases of OkHttp these events may also occur concurrently to permit multiple routes to be attempted simultaneously.
Events and sequences of events may be repeated for retries and follow-ups.
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.
Types
Functions
Invoked when a response will be served from the cache or network based on validating the cached Response freshness. Will be followed by cacheHit or cacheMiss after the network Response is available.
Invoked when a call fails permanently.
Invoked immediately after a socket connection was attempted.
Invoked when a connection attempt fails. This failure is not terminal if further routes are available and failure recovery is enabled.
Invoked after a connection has been acquired for the call
.
Invoked after a connection has been released for the call
.
Invoked just prior to initiating a socket connection.
Invoked immediately after a DNS lookup.
Invoked just prior to a DNS lookup. See Dns.lookup.
Invoked after proxy selection.
Invoked prior to a proxy selection.
Invoked immediately after sending a request body.
Invoked just prior to sending a request body. Will only be invoked for request allowing and having a request body to send.
Invoked when a request fails to be written.
Invoked immediately after sending request headers.
Invoked just prior to sending request headers.
Invoked immediately after receiving a response body and completing reading it.
Invoked when data from the response body is first available to the application.
Invoked when a response fails to be read.
Invoked immediately after receiving response headers.
Invoked when response headers are first returned from the server.
Invoked when a call fails due to cache rules. For example, we're forbidden from using the network and the cache is insufficient
Invoked immediately after a TLS connection was attempted.
Invoked just prior to initiating a TLS connection.