Module bus.http

Class HttpzState

java.lang.Object
org.miaixz.bus.http.plugin.httpz.HttpzState

public class HttpzState extends Object
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 Details

    • reqTotalCount

      protected static AtomicInteger reqTotalCount
      A counter for the total number of requests made.
    • reqFailureCount

      protected static AtomicInteger reqFailureCount
      A counter for the number of failed requests (e.g., non-2xx responses).
    • reqExceptionCount

      protected static AtomicInteger reqExceptionCount
      A counter for the number of requests that resulted in an exception.
    • startTime

      protected static Date startTime
      The time when the statistics tracking started.
    • lastAccessTime

      protected static Date lastAccessTime
      The timestamp of the last recorded request activity.
    • errorMsgs

      protected static LinkedBlockingDeque<String> 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

      public static Date getStartTime()
      Returns:
      The start time of the statistics collection.
    • getLastAccessTime

      public static Date getLastAccessTime()
      Returns:
      The timestamp of the last request activity.
    • getErrorMsgs

      public static LinkedBlockingDeque<String> getErrorMsgs()
      Returns:
      A deque containing the most recent error messages.
    • onReqFailure

      protected static void onReqFailure(String url, Exception e)
      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.