Class TimeGuard

java.lang.Object
com.igormaznitsa.meta.common.utils.TimeGuard

public final class TimeGuard extends Object
Allows to detect violations of execution time for code blocks or just measure time for them. It works separately for every Thread through ThreadLocal and check stack depth to be informed about current operation level.
Since:
1.0
  • Field Details

  • Constructor Details

    • TimeGuard

      private TimeGuard()
  • Method Details

    • addGuard

      @Weight(value=VARIABLE, comment="Depends on the current call stack depth") public static void addGuard(String alertMessage, @Constraint("X>0") long maxAllowedDelayInMilliseconds)
      Add a time watcher. As target of notification meta error listeners will be used.
      Parameters:
      alertMessage - message for time violation
      maxAllowedDelayInMilliseconds - max allowed delay in milliseconds for executing block
      Since:
      1.0
      See Also:
    • addPoint

      @Weight(value=VARIABLE, comment="Depends on the current call stack depth") public static void addPoint(String timePointName, TimeGuard.TimeAlertListener listener)
      Add a named time point.
      Parameters:
      timePointName - name for the time point
      listener - listener to be notified
      Since:
      1.0
      See Also:
    • checkPoint

      @Weight(value=VARIABLE, comment="Depends on the current call stack depth") public static void checkPoint(String timePointName)
      Check named time point(s). Listener registered for the point will be notified and the point will be removed.
      Parameters:
      timePointName - the name of time point
      Since:
      1.0
    • checkPoints

      @Weight(value=VARIABLE, comment="Depends on the current call stack depth") public static void checkPoints()
      Process all time points for the current stack level.
      Since:
      1.0
    • addGuard

      @Weight(value=VARIABLE, comment="Depends on the current call stack depth") public static void addGuard(String alertMessage, @Constraint("X>0") long maxAllowedDelayInMilliseconds, TimeGuard.TimeAlertListener timeAlertListener)
      Add a time watcher and provide processor of time violation.
      Parameters:
      alertMessage - message for time violation
      maxAllowedDelayInMilliseconds - max allowed delay in milliseconds for executing block
      timeAlertListener - alert listener to be notified, if it is null then the global one will get notification
      Since:
      1.0
      See Also:
    • cancelAll

      @Weight(NORMAL) public static void cancelAll()
      Cancel all time watchers and time points globally for the current thread.
      Since:
      1.0
      See Also:
    • cancel

      @Weight(value=VARIABLE, comment="Depends on the current call stack depth") public static void cancel()
      Cancel all time watchers and time points for the current stack level.
      Since:
      1.0
      See Also:
    • check

      @Weight(value=VARIABLE, comment="Depends on the current call stack depth") public static void check()
      Check all registered time watchers for time bound violations.
      Since:
      1.0
      See Also:
    • isEmpty

      @Weight(value=NORMAL, comment="May create list in thread local storage") public static boolean isEmpty()
      Check that the thread local for the current thread contains time points or watchers.
      Returns:
      true if the thread local storage is empty, false otherwise