Class Deferrers
java.lang.Object
com.igormaznitsa.meta.common.utils.Deferrers
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:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
Class wrapping executeDeferred method and stack depth for action. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final ThreadLocal
<List<Deferrers.Deferred>> Inside registry for defer actions. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic void
Cancel all defer actions globally.static void
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 Runnable
Defer execution of some runnable action.static <T extends 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
Process all defer actions for the current stack depth level.
-
Field Details
-
REGISTRY
Inside registry for defer actions.- Since:
- 1.0
-
-
Constructor Details
-
Deferrers
private Deferrers()
-
-
Method Details
-
defer
Defer some action.- Parameters:
deferred
- action to be defer.- Returns:
- the same object from arguments
- Since:
- 1.0
-
deferredClose
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
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
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
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
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
Check that presented defer actions for the current thread.- Returns:
- true if presented, false otherwise
- Since:
- 1.0
-