Class Deferrers

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

public final class Deferrers extends Object
Auxiliary tool to defer some actions and process them in some point in future. it check stack depth and executes only locally (for the stack level) defer actions. It works through ThreadLocal so that actions saved separately for every thread.
Since:
1.0
See Also:
  • Field Details

  • Constructor Details

    • Deferrers

      private Deferrers()
  • Method Details

    • defer

      @Weight(NORMAL) public static Deferrers.Deferred defer(Deferrers.Deferred deferred)
      Defer some action.
      Parameters:
      deferred - action to be defer.
      Returns:
      the same object from arguments
      Since:
      1.0
    • deferredClose

      @Warning("Using reflection") @Weight(NORMAL) public static <T> T deferredClose(T closeable)
      Defer object containing public close() method. It catches all exceptions during closing and make notifications only for global error listeners. It finds a public 'close' method of the object and call that through reflection.
      Type Parameters:
      T - type of the object to be processed
      Parameters:
      closeable - an object with close() method.
      Returns:
      the same object from arguments.
      Since:
      1.0
    • defer

      @Weight(NORMAL) public static <T extends Closeable> T defer(T closeable)
      Defer closing of an closeable object.
      Type Parameters:
      T - type of closeable object
      Parameters:
      closeable - an object implements java.io.Closeable
      Returns:
      the same closeable object from arguments
      Since:
      1.0
    • defer

      @Weight(NORMAL) public static Runnable defer(Runnable runnable)
      Defer execution of some runnable action.
      Parameters:
      runnable - some runnable action to be executed in future
      Returns:
      the same runnable object from arguments.
      Throws:
      AssertionError - if the runnable object is null
    • defer

      @Weight(NORMAL) public static Disposable defer(Disposable disposable)
      Defer execution of some disposable object.
      Parameters:
      disposable - some disposable object to be processed.
      Returns:
      the same object from arguments
      Throws:
      AssertionError - if the disposable object is null
      See Also:
    • cancelAllDeferredActionsGlobally

      @Weight(NORMAL) public static void cancelAllDeferredActionsGlobally()
      Cancel all defer actions globally.
      Since:
      1.0
    • cancelDeferredActions

      @Weight(value=VARIABLE, comment="Depends on the current call stack depth") public static void cancelDeferredActions()
      Cancel all defer actions for the current stack depth.
      Since:
      1.0
    • processDeferredActions

      @Weight(value=VARIABLE, comment="Depends on the current call stack depth") public static void processDeferredActions()
      Process all defer actions for the current stack depth level.
      Since:
      1.0
    • isEmpty

      @Weight(NORMAL) public static boolean isEmpty()
      Check that presented defer actions for the current thread.
      Returns:
      true if presented, false otherwise
      Since:
      1.0