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 classClass 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 voidCancel all defer actions globally.static voidCancel all defer actions for the current stack depth.static Disposabledefer(Disposable disposable) Defer execution of some disposable object.static Deferrers.Deferreddefer(Deferrers.Deferred deferred) Defer some action.static RunnableDefer execution of some runnable action.static <T extends Closeable>
Tdefer(T closeable) Defer closing of an closeable object.static <T> TdeferredClose(T closeable) Defer object containing public close() method.static booleanisEmpty()Check that presented defer actions for the current thread.static voidProcess 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
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
-
cancelDeferredActions
-
processDeferredActions
-
isEmpty
-