Class TimedCallback

java.lang.Object
com.kosdev.kos.commons.util.TimedCallback

public class TimedCallback extends Object
Wrapper for a callback that handles exceptions and measures the time the callback took and logs a warning if it takes longer than expected. Since most callbacks are intended to be completed quickly, this provides an easy way to warn users when their code is unexpectedly using event threads for long running tasks.
Since:
10
Version:
10
  • Field Details

    • DEFAULT_WARNING_TIME_MS

      public static final int DEFAULT_WARNING_TIME_MS
      See Also:
  • Constructor Details

    • TimedCallback

      public TimedCallback()
  • Method Details

    • getDefaultWarningTimeMs

      public static int getDefaultWarningTimeMs()
      Return the current default warning time.
      Since:
      10
    • call

      public static void call(String name, Object listener, Runnable r)
      Call the specified callback with the default warning time.
      Parameters:
      name - name of the call for use in log messages
      listener - the listener being called, the class name is used in log messages
      r - the callback to run
      Since:
      10
    • call

      public static void call(String name, Object listener, int warningTimeMs, Runnable r)
      Call the specified callback with the default warning time.
      Parameters:
      name - name of the call for use in log messages
      listener - the listener being called, the class name is used in log messages
      warningTimeMs - how long until a warning is generated
      r - the callback to run
      Since:
      10