Module bus.http

Class EventListener

java.lang.Object
org.miaixz.bus.http.metric.EventListener

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

All event methods must execute quickly, without external locking, without throwing exceptions, without attempting to mutate the event parameters, and without reentrant calls into the client. Any IO writing should be done asynchronously.

Since:
Java 17+
Author:
Kimi Liu
  • Field Details

  • Constructor Details

    • EventListener

      public EventListener()
  • Method Details

    • factory

      public static EventListener.Factory factory(EventListener listener)
      Creates a factory that returns the same listener instance for all calls.
      Parameters:
      listener - The listener to be returned by the factory.
      Returns:
      A factory that returns the given listener.
    • callStart

      public void callStart(NewCall call)
      Invoked immediately when a call is enqueued or executed by the client. In case of thread or stream limits, this call may be executed before processing of the request starts.

      This is invoked only once for a single NewCall. Retries of different routes or redirects will be handled within the boundaries of a single callStart and callEnd(org.miaixz.bus.http.NewCall)/callFailed(org.miaixz.bus.http.NewCall, java.io.IOException) pair.

      Parameters:
      call - The call information.
    • dnsStart

      public void dnsStart(NewCall call, String domainName)
      Invoked just prior to a DNS lookup. See DnsX.lookup(String).
      Parameters:
      call - The call information.
      domainName - The hostname.
    • dnsEnd

      public void dnsEnd(NewCall call, String domainName, List<InetAddress> inetAddressList)
      Invoked immediately after a DNS lookup. This method is invoked after dnsStart(org.miaixz.bus.http.NewCall, java.lang.String).
      Parameters:
      call - The call information.
      domainName - The hostname.
      inetAddressList - The list of IP addresses.
    • connectStart

      public void connectStart(NewCall 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 be reused.
      Parameters:
      call - The call information.
      inetSocketAddress - The socket address.
      proxy - The proxy.
    • secureConnectStart

      public void secureConnectStart(NewCall call)
      Invoked prior to starting a TLS connection.
      Parameters:
      call - The call information.
    • secureConnectEnd

      public void secureConnectEnd(NewCall call, Handshake handshake)
      Invoked immediately after a TLS connection was attempted. This method is invoked after secureConnectStart(org.miaixz.bus.http.NewCall).
      Parameters:
      call - The call information.
      handshake - The handshake information.
    • connectEnd

      public void connectEnd(NewCall call, InetSocketAddress inetSocketAddress, Proxy proxy, org.miaixz.bus.core.net.Protocol protocol)
      Invoked immediately after a socket connection was attempted.
      Parameters:
      call - The call information.
      inetSocketAddress - The socket address.
      proxy - The proxy.
      protocol - The protocol.
    • connectFailed

      public void connectFailed(NewCall call, InetSocketAddress inetSocketAddress, Proxy proxy, org.miaixz.bus.core.net.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.
      Parameters:
      call - The call information.
      inetSocketAddress - The socket address.
      proxy - The proxy.
      protocol - The protocol.
      ioe - The exception.
    • connectionAcquired

      public void connectionAcquired(NewCall call, Connection connection)
      Invoked after a connection is acquired for a call.
      Parameters:
      call - The call information.
      connection - The connection information.
    • connectionReleased

      public void connectionReleased(NewCall call, Connection connection)
      Invoked after a connection is released for a call. This method is always invoked after connectionAcquired(NewCall, Connection).
      Parameters:
      call - The call information.
      connection - The connection information.
    • requestHeadersStart

      public void requestHeadersStart(NewCall call)
      Invoked just prior to sending request headers. The connection is implicit and is typically associated with the last connectionAcquired(NewCall, Connection) event.
      Parameters:
      call - The call information.
    • requestHeadersEnd

      public void requestHeadersEnd(NewCall call, Request request)
      Invoked immediately after sending request headers. This method is always invoked after requestHeadersStart(NewCall).
      Parameters:
      call - The call information.
      request - The request sent over the network.
    • requestBodyStart

      public void requestBodyStart(NewCall call)
      Invoked just prior to sending a request body. Will only be invoked if the request permits and has a request body to send. The connection is implicit and is typically associated with the last connectionAcquired(NewCall, Connection) event.
      Parameters:
      call - The call information.
    • requestBodyEnd

      public void requestBodyEnd(NewCall call, long byteCount)
      Invoked immediately after sending a request body. This method is always invoked after requestBodyStart(NewCall).
      Parameters:
      call - The call information.
      byteCount - The byte count.
    • requestFailed

      public void requestFailed(NewCall call, IOException ioe)
      Invoked when a request fails to be written. This method is invoked after requestHeadersStart(org.miaixz.bus.http.NewCall) or requestBodyStart(org.miaixz.bus.http.NewCall).
      Parameters:
      call - The call information.
      ioe - The exception.
    • responseHeadersStart

      public void responseHeadersStart(NewCall call)
      Invoked just prior to receiving response headers. The connection is implicit and is typically associated with the last connectionAcquired(NewCall, Connection) event. This may be invoked multiple times for a single NewCall. For example, if the response to NewCall.request() is a redirect to another address.
      Parameters:
      call - The call information.
    • responseHeadersEnd

      public void responseHeadersEnd(NewCall call, Response response)
      Invoked immediately after receiving response headers. This method is always invoked after responseHeadersStart(org.miaixz.bus.http.NewCall).
      Parameters:
      call - The call information.
      response - The response received from the network.
    • responseBodyStart

      public void responseBodyStart(NewCall call)
      Invoked just prior to receiving a response body. The connection is implicit and is typically associated with the last connectionAcquired(NewCall, Connection) event. This is typically invoked only once for a single NewCall, except for a limited set of cases including failure recovery.
      Parameters:
      call - The call information.
    • responseBodyEnd

      public void responseBodyEnd(NewCall call, long byteCount)
      Invoked immediately after receiving a response body and completing reading it. Will only be invoked for requests that have a response body, for example, it will not be invoked for a websocket upgrade. This method is always invoked after requestBodyStart(NewCall).
      Parameters:
      call - The call information.
      byteCount - The byte count.
    • responseFailed

      public void responseFailed(NewCall call, IOException ioe)
      Invoked when a response fails to be read. This method is invoked after responseHeadersStart(org.miaixz.bus.http.NewCall) or responseBodyStart(org.miaixz.bus.http.NewCall).
      Parameters:
      call - The call information.
      ioe - The exception.
    • callEnd

      public void callEnd(NewCall call)
      Invoked immediately after a call has completely ended. This includes any delayed consumption of the response body by the caller. This method is always invoked after callStart(NewCall).
      Parameters:
      call - The call information.
    • callFailed

      public void callFailed(NewCall call, IOException ioe)
      Invoked when a call fails permanently. This method is always invoked after callStart(NewCall).
      Parameters:
      call - The call information.
      ioe - The exception.