Skip to content

//okhttp/okhttp3/EventListener

EventListener

[jvm]\ abstract class 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:

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.

Constructors

EventListener [jvm]
fun EventListener()

Types

Name Summary
Companion [jvm]
object Companion
Factory [jvm]
fun interface Factory

Functions

Name Summary
cacheConditionalHit [jvm]
open fun cacheConditionalHit(call: Call, cachedResponse: Response)
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.
cacheHit [jvm]
open fun cacheHit(call: Call, response: Response)
Invoked when a result is served from the cache. The Response provided is the top level Response and normal event sequences will not be received.
cacheMiss [jvm]
open fun cacheMiss(call: Call)
Invoked when a response will be served from the network. The Response will be available from normal event sequences.
callEnd [jvm]
open fun callEnd(call: Call)
Invoked immediately after a call has completely ended. This includes delayed consumption of response body by the caller.
callFailed [jvm]
open fun callFailed(call: Call, ioe: IOException)
Invoked when a call fails permanently.
callStart [jvm]
open fun callStart(call: Call)
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.
canceled [jvm]
open fun canceled(call: Call)
Invoked when a call is canceled.
connectEnd [jvm]
open fun connectEnd(call: Call, inetSocketAddress: InetSocketAddress, proxy: Proxy, protocol: Protocol?)
Invoked immediately after a socket connection was attempted.
connectFailed [jvm]
open fun connectFailed(call: Call, inetSocketAddress: InetSocketAddress, proxy: Proxy, protocol: Protocol?, ioe: IOException)
Invoked when a connection attempt fails. This failure is not terminal if further routes are available and failure recovery is enabled.
connectionAcquired [jvm]
open fun connectionAcquired(call: Call, connection: Connection)
Invoked after a connection has been acquired for the call.
connectionReleased [jvm]
open fun connectionReleased(call: Call, connection: Connection)
Invoked after a connection has been released for the call.
connectStart [jvm]
open fun connectStart(call: Call, inetSocketAddress: InetSocketAddress, proxy: Proxy)
Invoked just prior to initiating a socket connection.
dnsEnd [jvm]
open fun dnsEnd(call: Call, domainName: String, inetAddressList: List<@JvmSuppressWildcardsInetAddress>)
Invoked immediately after a DNS lookup.
dnsStart [jvm]
open fun dnsStart(call: Call, domainName: String)
Invoked just prior to a DNS lookup. See Dns.lookup.
proxySelectEnd [jvm]
open fun proxySelectEnd(call: Call, url: HttpUrl, proxies: List<@JvmSuppressWildcardsProxy>)
Invoked after proxy selection.
proxySelectStart [jvm]
open fun proxySelectStart(call: Call, url: HttpUrl)
Invoked prior to a proxy selection.
requestBodyEnd [jvm]
open fun requestBodyEnd(call: Call, byteCount: Long)
Invoked immediately after sending a request body.
requestBodyStart [jvm]
open fun requestBodyStart(call: Call)
Invoked just prior to sending a request body. Will only be invoked for request allowing and having a request body to send.
requestFailed [jvm]
open fun requestFailed(call: Call, ioe: IOException)
Invoked when a request fails to be written.
requestHeadersEnd [jvm]
open fun requestHeadersEnd(call: Call, request: Request)
Invoked immediately after sending request headers.
requestHeadersStart [jvm]
open fun requestHeadersStart(call: Call)
Invoked just prior to sending request headers.
responseBodyEnd [jvm]
open fun responseBodyEnd(call: Call, byteCount: Long)
Invoked immediately after receiving a response body and completing reading it.
responseBodyStart [jvm]
open fun responseBodyStart(call: Call)
Invoked when data from the response body is first available to the application.
responseFailed [jvm]
open fun responseFailed(call: Call, ioe: IOException)
Invoked when a response fails to be read.
responseHeadersEnd [jvm]
open fun responseHeadersEnd(call: Call, response: Response)
Invoked immediately after receiving response headers.
responseHeadersStart [jvm]
open fun responseHeadersStart(call: Call)
Invoked when response headers are first returned from the server.
satisfactionFailure [jvm]
open fun satisfactionFailure(call: Call, response: Response)
Invoked when a call fails due to cache rules. For example, we’re forbidden from using the network and the cache is insufficient
secureConnectEnd [jvm]
open fun secureConnectEnd(call: Call, handshake: Handshake?)
Invoked immediately after a TLS connection was attempted.
secureConnectStart [jvm]
open fun secureConnectStart(call: Call)
Invoked just prior to initiating a TLS connection.