Package 

Class EventListener


  • 
    public abstract class EventListener
    
                        

    Listener for metrics events. Extend this class to monitor the quantity, size, and duration of your application's HTTP calls.

    Warning: This is a non-final API.

    As of OkHttp 3.10, this feature is an unstable preview: the API is subject to change, and the implementation is incomplete. We expect that OkHttp 3.11 or 3.12 will finalize this API. Until then, expect API and behavior changes when you update your OkHttp dependency.

    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)* -> mobonRequest events
    • call -> (connection acquire/release)*

    MobonRequest 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 mobonRequest events.

    All event methods must execute fast, without external locking, cannot throw exceptions, attempt to mutate the event parameters, or be reentrant back into the client. Any IO - writing to files or network should be done asynchronously.

    • Method Detail

      • callStart

         void callStart(Call call)

        Invoked as soon as a call is enqueued or executed by a client. In case of thread or streamlimits, this call may be executed well before processing the mobonRequest is able to begin.

        This will be invoked only once for a single Call. Retries of different routesor redirects will be handled within the boundaries of a single callStart and /callFailed pair.

      • dnsStart

         void dnsStart(Call call, String domainName)

        Invoked just prior to a DNS lookup. See lookup.

        This can be invoked more than 1 time for a single Call. For example, if the responseto the request is a redirect to a different host.

        If the Call is able to reuse an existing pooled connection, this method will not beinvoked. See ConnectionPool.

      • connectStart

         void connectStart(Call call, InetSocketAddress inetSocketAddress, Proxy proxy)

        Invoked just prior to initiating a socket connection.

        This method will be invoked if no existing connection in the ConnectionPool can bereused.

        This can be invoked more than 1 time for a single Call. For example, if the responseto the request is a redirect to a different address, or a connection is retried.

      • secureConnectStart

         void secureConnectStart(Call call)

        Invoked just prior to initiating a TLS connection.

        This method is invoked if the following conditions are met:

        This can be invoked more than 1 time for a single Call. For example, if the responseto the request is a redirect to a different address, or a connection is retried.

      • connectionAcquired

         void connectionAcquired(Call call, Connection connection)

        Invoked after a connection has been acquired for the {@code call}.

        This can be invoked more than 1 time for a single Call. For example, if the responseto the request is a redirect to a different address.

      • connectionReleased

         void connectionReleased(Call call, Connection connection)

        Invoked after a connection has been released for the {@code call}.

        This method is always invoked after connectionAcquired.

        This can be invoked more than 1 time for a single Call. For example, if the responseto the request is a redirect to a different address.

      • requestHeadersStart

         void requestHeadersStart(Call call)

        Invoked just prior to sending mobonRequest headers.

        The connection is implicit, and will generally relate to the last connectionAcquired event.

        This can be invoked more than 1 time for a single Call. For example, if the responseto the request is a redirect to a different address.

      • requestHeadersEnd

         void requestHeadersEnd(Call call, MobonRequest mobonRequest)

        Invoked immediately after sending mobonRequest headers.

        This method is always invoked after requestHeadersStart.

        Parameters:
        mobonRequest - the mobonRequest sent over the network.
      • requestBodyStart

         void requestBodyStart(Call call)

        Invoked just prior to sending a mobonRequest body. Will only be invoked for mobonRequest allowing andhaving a mobonRequest body to send.

        The connection is implicit, and will generally relate to the last connectionAcquired event.

        This can be invoked more than 1 time for a single Call. For example, if the responseto the request is a redirect to a different address.

      • requestBodyEnd

         void requestBodyEnd(Call call, long byteCount)

        Invoked immediately after sending a mobonRequest body.

        This method is always invoked after requestBodyStart.

      • responseHeadersStart

         void responseHeadersStart(Call call)

        Invoked just prior to receiving response headers.

        The connection is implicit, and will generally relate to the last connectionAcquired event.

        This can be invoked more than 1 time for a single Call. For example, if the responseto the request is a redirect to a different address.

      • responseHeadersEnd

         void responseHeadersEnd(Call call, MobonResponse mobonResponse)

        Invoked immediately after receiving mobonResponse headers.

        This method is always invoked after responseHeadersStart.

        Parameters:
        mobonResponse - the mobonResponse received over the network.
      • responseBodyStart

         void responseBodyStart(Call call)

        Invoked just prior to receiving the response body.

        The connection is implicit, and will generally relate to the last connectionAcquired event.

        This will usually be invoked only 1 time for a single Call,exceptions are a limited set of cases including failure recovery.

      • responseBodyEnd

         void responseBodyEnd(Call call, long byteCount)

        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 awebsocket upgrade.

        This method is always invoked after requestBodyStart.

      • callEnd

         void callEnd(Call call)

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

        This method is always invoked after callStart.