Class ShutdownHooks
java.lang.Object
dev.getelements.elements.sdk.util.ShutdownHooks
A simple way to manage shutdown hooks. Each instance of
ShutdownHooks
submits a thread to the system runtime
which will be executed upon shutdown of the virtual machine. Each action in this instance is executed serially in
the order in which it was queued to this instance of ShutdownHooks
.
It is safe to queue multiple ShutdownHooks.Action
s from multiple threads. This type internally uses a
simple lockless linked-list to queue all actions. Once queued, the action may not be removed from the queue so the
author of the action must ensure that there are no side effects if the associated action is no longer needed.
Each action may throw an exception, in which case it will be logged to a logger specified by the class that owns
the shutdown hooks.
Created by patricktwohig on 8/23/17.-
Nested Class Summary
Nested Classes -
Constructor Summary
ConstructorsConstructorDescriptionShutdownHooks
(Class<?> aClass) Uses the suppliedClass<?>
's logger to log the shutdown hooks action.ShutdownHooks
(org.slf4j.Logger logger) Allows for the owner of thisShutdownHooks
instance to specify a customLogger
which will be used to log the information of the associated actions. -
Method Summary
Modifier and TypeMethodDescriptionvoid
add
(ShutdownHooks.Action action) Adds a newShutdownHooks.Action
to thisShutdownHooks
instance.void
add
(Object context, ShutdownHooks.Action action) Adds a newShutdownHooks.Action
to thisShutdownHooks
instance.
-
Constructor Details
-
ShutdownHooks
Uses the suppliedClass<?>
's logger to log the shutdown hooks action.- Parameters:
aClass
- the class which owns theShutdownHooks
-
ShutdownHooks
public ShutdownHooks(org.slf4j.Logger logger) Allows for the owner of thisShutdownHooks
instance to specify a customLogger
which will be used to log the information of the associated actions.- Parameters:
logger
- the actions
-
-
Method Details
-
add
Adds a newShutdownHooks.Action
to thisShutdownHooks
instance.- Parameters:
action
- the action to perform.
-
add
Adds a newShutdownHooks.Action
to thisShutdownHooks
instance.- Parameters:
context
- the context, which will simply be logged as theShutdownHooks
performs its actionsaction
- the action to perform.
-