java.lang.Object
org.miaixz.bus.http.plugin.httpz.HttpzState
A utility class for tracking global statistics and state for the
Httpz client. It provides thread-safe
counters for total requests, failures, and exceptions, as well as a log of recent errors.- Since:
- Java 17+
- Author:
- Kimi Liu
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static LinkedBlockingDeque<String> A deque to store the most recent error messages.protected static DateThe timestamp of the last recorded request activity.protected static AtomicIntegerA counter for the number of requests that resulted in an exception.protected static AtomicIntegerA counter for the number of failed requests (e.g., non-2xx responses).protected static AtomicIntegerA counter for the total number of requests made.protected static DateThe time when the statistics tracking started. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic LinkedBlockingDeque<String> static Datestatic intstatic intstatic intstatic Dateprotected static voidonReqFailure(String url, Exception e) A callback method invoked when a request fails.protected static voidA callback method invoked when a request succeeds.static voidstopStat()Stops the collection of statistics.
-
Field Details
-
reqTotalCount
A counter for the total number of requests made. -
reqFailureCount
A counter for the number of failed requests (e.g., non-2xx responses). -
reqExceptionCount
A counter for the number of requests that resulted in an exception. -
startTime
The time when the statistics tracking started. -
lastAccessTime
The timestamp of the last recorded request activity. -
errorMsgs
A deque to store the most recent error messages.
-
-
Constructor Details
-
HttpzState
public HttpzState()
-
-
Method Details
-
stopStat
public static void stopStat()Stops the collection of statistics. -
getReqTotalCount
public static int getReqTotalCount()- Returns:
- The total number of requests initiated.
-
getReqFailureCount
public static int getReqFailureCount()- Returns:
- The total number of failed requests.
-
getReqExceptionCount
public static int getReqExceptionCount()- Returns:
- The total number of requests that threw an exception.
-
getStartTime
- Returns:
- The start time of the statistics collection.
-
getLastAccessTime
- Returns:
- The timestamp of the last request activity.
-
getErrorMsgs
- Returns:
- A deque containing the most recent error messages.
-
onReqFailure
A callback method invoked when a request fails. It increments the relevant counters and logs the error.- Parameters:
url- The URL of the failed request.e- The exception that occurred, if any.
-
onReqSuccess
protected static void onReqSuccess()A callback method invoked when a request succeeds. It increments the total request counter.
-