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.Actions 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 thisShutdownHooksinstance to specify a customLoggerwhich will be used to log the information of the associated actions. -
Method Summary
Modifier and TypeMethodDescriptionvoidadd(ShutdownHooks.Action action) Adds a newShutdownHooks.Actionto thisShutdownHooksinstance.voidadd(Object context, ShutdownHooks.Action action) Adds a newShutdownHooks.Actionto thisShutdownHooksinstance.
-
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 thisShutdownHooksinstance to specify a customLoggerwhich will be used to log the information of the associated actions.- Parameters:
logger- the actions
-
-
Method Details
-
add
Adds a newShutdownHooks.Actionto thisShutdownHooksinstance.- Parameters:
action- the action to perform.
-
add
Adds a newShutdownHooks.Actionto thisShutdownHooksinstance.- Parameters:
context- the context, which will simply be logged as theShutdownHooksperforms its actionsaction- the action to perform.
-