Class Deferrers
- java.lang.Object
-
- com.igormaznitsa.meta.common.utils.Deferrers
-
public final class Deferrers extends java.lang.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:
ThreadLocal
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Deferrers.Deferred
Class wrapping executeDeferred method and stack depth for action.
-
Field Summary
Fields Modifier and Type Field Description private static java.lang.ThreadLocal<java.util.List<Deferrers.Deferred>>
REGISTRY
Inside registry for defer actions.
-
Constructor Summary
Constructors Modifier Constructor Description private
Deferrers()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
cancelAllDeferredActionsGlobally()
Cancel all defer actions globally.static void
cancelDeferredActions()
Cancel all defer actions for the current stack depth.static Disposable
defer(Disposable disposable)
Defer execution of some disposable object.static Deferrers.Deferred
defer(Deferrers.Deferred deferred)
Defer some action.static java.lang.Runnable
defer(java.lang.Runnable runnable)
Defer execution of some runnable action.static <T extends java.io.Closeable>
Tdefer(T closeable)
Defer closing of an closeable object.static <T> T
deferredClose(T closeable)
Defer object containing public close() method.static boolean
isEmpty()
Check that presented defer actions for the current thread.static void
processDeferredActions()
Process all defer actions for the current stack depth level.
-
-
-
Field Detail
-
REGISTRY
@MustNotContainNull private static final java.lang.ThreadLocal<java.util.List<Deferrers.Deferred>> REGISTRY
Inside registry for defer actions.- Since:
- 1.0
-
-
Method Detail
-
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 java.io.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 java.lang.Runnable defer(java.lang.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:
java.lang.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:
java.lang.AssertionError
- if the disposable object is null- See Also:
Disposable
-
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
-
-