java.lang.Object
org.miaixz.bus.http.metric.EventListener
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
-
Nested Class Summary
Nested Classes -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidInvoked immediately after a call has completely ended.voidcallFailed(NewCall call, IOException ioe) Invoked when a call fails permanently.voidInvoked immediately when a call is enqueued or executed by the client.voidconnectEnd(NewCall call, InetSocketAddress inetSocketAddress, Proxy proxy, org.miaixz.bus.core.net.Protocol protocol) Invoked immediately after a socket connection was attempted.voidconnectFailed(NewCall call, InetSocketAddress inetSocketAddress, Proxy proxy, org.miaixz.bus.core.net.Protocol protocol, IOException ioe) Invoked when a connection attempt fails.voidconnectionAcquired(NewCall call, Connection connection) Invoked after a connection is acquired for acall.voidconnectionReleased(NewCall call, Connection connection) Invoked after a connection is released for acall.voidconnectStart(NewCall call, InetSocketAddress inetSocketAddress, Proxy proxy) Invoked just prior to initiating a socket connection.voiddnsEnd(NewCall call, String domainName, List<InetAddress> inetAddressList) Invoked immediately after a DNS lookup.voidInvoked just prior to a DNS lookup.static EventListener.Factoryfactory(EventListener listener) Creates a factory that returns the same listener instance for all calls.voidrequestBodyEnd(NewCall call, long byteCount) Invoked immediately after sending a request body.voidrequestBodyStart(NewCall call) Invoked just prior to sending a request body.voidrequestFailed(NewCall call, IOException ioe) Invoked when a request fails to be written.voidrequestHeadersEnd(NewCall call, Request request) Invoked immediately after sending request headers.voidrequestHeadersStart(NewCall call) Invoked just prior to sending request headers.voidresponseBodyEnd(NewCall call, long byteCount) Invoked immediately after receiving a response body and completing reading it.voidresponseBodyStart(NewCall call) Invoked just prior to receiving a response body.voidresponseFailed(NewCall call, IOException ioe) Invoked when a response fails to be read.voidresponseHeadersEnd(NewCall call, Response response) Invoked immediately after receiving response headers.voidresponseHeadersStart(NewCall call) Invoked just prior to receiving response headers.voidsecureConnectEnd(NewCall call, Handshake handshake) Invoked immediately after a TLS connection was attempted.voidsecureConnectStart(NewCall call) Invoked prior to starting a TLS connection.
-
Field Details
-
NONE
-
-
Constructor Details
-
EventListener
public EventListener()
-
-
Method Details
-
factory
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
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 andcallEnd(org.miaixz.bus.http.NewCall)/callFailed(org.miaixz.bus.http.NewCall, java.io.IOException)pair.- Parameters:
call- The call information.
-
dnsStart
Invoked just prior to a DNS lookup. SeeDnsX.lookup(String).- Parameters:
call- The call information.domainName- The hostname.
-
dnsEnd
Invoked immediately after a DNS lookup. This method is invoked afterdnsStart(org.miaixz.bus.http.NewCall, java.lang.String).- Parameters:
call- The call information.domainName- The hostname.inetAddressList- The list of IP addresses.
-
connectStart
Invoked just prior to initiating a socket connection. This method will be invoked if no existing connection in theConnectionPoolcan be reused.- Parameters:
call- The call information.inetSocketAddress- The socket address.proxy- The proxy.
-
secureConnectStart
Invoked prior to starting a TLS connection.- Parameters:
call- The call information.
-
secureConnectEnd
Invoked immediately after a TLS connection was attempted. This method is invoked aftersecureConnectStart(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
Invoked after a connection is acquired for acall.- Parameters:
call- The call information.connection- The connection information.
-
connectionReleased
Invoked after a connection is released for acall. This method is always invoked afterconnectionAcquired(NewCall, Connection).- Parameters:
call- The call information.connection- The connection information.
-
requestHeadersStart
Invoked just prior to sending request headers. The connection is implicit and is typically associated with the lastconnectionAcquired(NewCall, Connection)event.- Parameters:
call- The call information.
-
requestHeadersEnd
Invoked immediately after sending request headers. This method is always invoked afterrequestHeadersStart(NewCall).- Parameters:
call- The call information.request- The request sent over the network.
-
requestBodyStart
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 lastconnectionAcquired(NewCall, Connection)event.- Parameters:
call- The call information.
-
requestBodyEnd
Invoked immediately after sending a request body. This method is always invoked afterrequestBodyStart(NewCall).- Parameters:
call- The call information.byteCount- The byte count.
-
requestFailed
Invoked when a request fails to be written. This method is invoked afterrequestHeadersStart(org.miaixz.bus.http.NewCall)orrequestBodyStart(org.miaixz.bus.http.NewCall).- Parameters:
call- The call information.ioe- The exception.
-
responseHeadersStart
Invoked just prior to receiving response headers. The connection is implicit and is typically associated with the lastconnectionAcquired(NewCall, Connection)event. This may be invoked multiple times for a singleNewCall. For example, if the response toNewCall.request()is a redirect to another address.- Parameters:
call- The call information.
-
responseHeadersEnd
Invoked immediately after receiving response headers. This method is always invoked afterresponseHeadersStart(org.miaixz.bus.http.NewCall).- Parameters:
call- The call information.response- The response received from the network.
-
responseBodyStart
Invoked just prior to receiving a response body. The connection is implicit and is typically associated with the lastconnectionAcquired(NewCall, Connection)event. This is typically invoked only once for a singleNewCall, except for a limited set of cases including failure recovery.- Parameters:
call- The call information.
-
responseBodyEnd
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 afterrequestBodyStart(NewCall).- Parameters:
call- The call information.byteCount- The byte count.
-
responseFailed
Invoked when a response fails to be read. This method is invoked afterresponseHeadersStart(org.miaixz.bus.http.NewCall)orresponseBodyStart(org.miaixz.bus.http.NewCall).- Parameters:
call- The call information.ioe- The exception.
-
callEnd
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 aftercallStart(NewCall).- Parameters:
call- The call information.
-
callFailed
Invoked when a call fails permanently. This method is always invoked aftercallStart(NewCall).- Parameters:
call- The call information.ioe- The exception.
-