EventListener

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

Link copied to clipboard
constructor()

Types

Link copied to clipboard
object Companion
Link copied to clipboard
fun interface Factory

Functions

Link copied to clipboard
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.

Link copied to clipboard
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.

Link copied to clipboard
open fun cacheMiss(call: Call)

Invoked when a response will be served from the network. The Response will be available from normal event sequences.

Link copied to clipboard
open fun callEnd(call: Call)

Invoked immediately after a call has completely ended. This includes delayed consumption of response body by the caller.

Link copied to clipboard
open fun callFailed(call: Call, ioe: IOException)

Invoked when a call fails permanently.

Link copied to clipboard
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.

Link copied to clipboard
open fun canceled(call: Call)

Invoked when a call is canceled.

Link copied to clipboard
open fun connectEnd(call: Call, inetSocketAddress: InetSocketAddress, proxy: Proxy, protocol: Protocol?)

Invoked immediately after a socket connection was attempted.

Link copied to clipboard
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.

Link copied to clipboard
open fun connectionAcquired(call: Call, connection: Connection)

Invoked after a connection has been acquired for the call.

Link copied to clipboard
open fun connectionReleased(call: Call, connection: Connection)

Invoked after a connection has been released for the call.

Link copied to clipboard
open fun connectStart(call: Call, inetSocketAddress: InetSocketAddress, proxy: Proxy)

Invoked just prior to initiating a socket connection.

Link copied to clipboard
open fun dnsEnd(call: Call, domainName: String, inetAddressList: List<@JvmSuppressWildcards InetAddress>)

Invoked immediately after a DNS lookup.

Link copied to clipboard
open fun dnsStart(call: Call, domainName: String)

Invoked just prior to a DNS lookup. See Dns.lookup.

Link copied to clipboard
open fun proxySelectEnd(call: Call, url: HttpUrl, proxies: List<@JvmSuppressWildcards Proxy>)

Invoked after proxy selection.

Link copied to clipboard
open fun proxySelectStart(call: Call, url: HttpUrl)

Invoked prior to a proxy selection.

Link copied to clipboard
open fun requestBodyEnd(call: Call, byteCount: Long)

Invoked immediately after sending a request body.

Link copied to clipboard
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.

Link copied to clipboard
open fun requestFailed(call: Call, ioe: IOException)

Invoked when a request fails to be written.

Link copied to clipboard
open fun requestHeadersEnd(call: Call, request: Request)

Invoked immediately after sending request headers.

Link copied to clipboard
open fun requestHeadersStart(call: Call)

Invoked just prior to sending request headers.

Link copied to clipboard
open fun responseBodyEnd(call: Call, byteCount: Long)

Invoked immediately after receiving a response body and completing reading it.

Link copied to clipboard
open fun responseBodyStart(call: Call)

Invoked when data from the response body is first available to the application.

Link copied to clipboard
open fun responseFailed(call: Call, ioe: IOException)

Invoked when a response fails to be read.

Link copied to clipboard
open fun responseHeadersEnd(call: Call, response: Response)

Invoked immediately after receiving response headers.

Link copied to clipboard
open fun responseHeadersStart(call: Call)

Invoked when response headers are first returned from the server.

Link copied to clipboard
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

Link copied to clipboard
open fun secureConnectEnd(call: Call, handshake: Handshake?)

Invoked immediately after a TLS connection was attempted.

Link copied to clipboard
open fun secureConnectStart(call: Call)

Invoked just prior to initiating a TLS connection.