public class ShutdownManager
extends java.lang.Object
getInstance()
.Modifier and Type | Class and Description |
---|---|
private static class |
ShutdownManager.Hook
Aggregates a runnable and an associated sequence value.
|
Modifier and Type | Field and Description |
---|---|
static int |
CLIENT_SEQUENCE
Shutdown sequence value for client hooks.
|
private java.util.WeakHashMap |
hookMap_
Maps Objects to Hooks.
|
static int |
HUB_SEQUENCE
Shutdown sequence value for hub hooks.
|
private static ShutdownManager |
instance_ |
private static java.util.logging.Logger |
logger_ |
static int |
PREPARE_SEQUENCE
Shutdown sequence for preparatory hooks.
|
Modifier | Constructor and Description |
---|---|
private |
ShutdownManager()
Private constructor prevents instantiation.
|
Modifier and Type | Method and Description |
---|---|
private void |
doCleanup()
Invoked on shutdown by runtime.
|
static void |
forceLog(java.util.logging.Logger logger,
java.util.logging.Level level,
java.lang.String msg,
java.lang.Throwable error)
Writes a log-like message directly to standard error if it has
an appropriate level.
|
static ShutdownManager |
getInstance()
Returns sole instance of this class.
|
void |
registerHook(java.lang.Object key,
int iseq,
java.lang.Runnable runnable)
Register a runnable to be run on shutdown with a given key and sequence.
|
void |
unregisterHook(java.lang.Object key)
Unregisters a key earlier registered using
registerHook(java.lang.Object, int, java.lang.Runnable) . |
public static final int PREPARE_SEQUENCE
public static final int CLIENT_SEQUENCE
public static final int HUB_SEQUENCE
private static final ShutdownManager instance_
private static final java.util.logging.Logger logger_
private final java.util.WeakHashMap hookMap_
private ShutdownManager()
public void registerHook(java.lang.Object key, int iseq, java.lang.Runnable runnable)
iseq
are run earlier at shutdown.
Suitable sequence values are given by HUB_SEQUENCE
and
CLIENT_SEQUENCE
.
The key
is kept in a WeakHashMap, so if it is GC'd,
the runnable will never execute.key
- key which can be used to unregister the hook lateriseq
- value indicating position in shutdown sequencerunnable
- to be run on shutdownpublic void unregisterHook(java.lang.Object key)
registerHook(java.lang.Object, int, java.lang.Runnable)
.key
- registration keyprivate void doCleanup()
public static ShutdownManager getInstance()
public static void forceLog(java.util.logging.Logger logger, java.util.logging.Level level, java.lang.String msg, java.lang.Throwable error)
logger
- loggerlevel
- level of message to logmsg
- text of logging messageerror
- associated throwable if any; may be null