Package org.apache.sis.internal.system
Class Shutdown
java.lang.Object
java.lang.Thread
org.apache.sis.internal.system.Shutdown
- All Implemented Interfaces:
Runnable
A central place where to manage SIS shutdown process.
- Since:
- 0.3
- Version:
- 0.7
-
Nested Class Summary
Nested classes/interfaces inherited from class java.lang.Thread
Thread.State, Thread.UncaughtExceptionHandler
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static String
Non-null if a shutdown hook is already registered.private static Shutdown
The shutdown hook to be registered to the JVMRuntime
, created when first needed.The resources to dispose.Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprivate
Shutdown()
Creates the thread to be executed at shutdown time. -
Method Summary
Modifier and TypeMethodDescriptionstatic String
Returns the value set by the last call tosetContainer(String)
.static void
Registers a code to execute at JVM shutdown time, or if SIS library is unloaded from a container such as OSGi.private static void
Removes the shutdown hook, if any.void
run()
Invoked at JVM shutdown time.static void
setContainer
(String env) Invoked if the Apache SIS library is executed from an environment that provide its own shutdown hook.static void
Unregisters the supervisor MBean, executes the disposal tasks and shutdowns thesis-utility
threads.static void
unregister
(Callable<?> resource) Unregisters a code from execution at JVM shutdown time.Methods inherited from class java.lang.Thread
activeCount, checkAccess, clone, countStackFrames, currentThread, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, onSpinWait, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, suspend, toString, yield
-
Field Details
-
container
Non-null if a shutdown hook is already registered. That shutdown hook is not necessarilyhook
. It may be an OSGi or Servlet shutdown hook instead, as notified bysetContainer(String)
. -
hook
The shutdown hook to be registered to the JVMRuntime
, created when first needed. -
resources
The resources to dispose. Most recently added resources are last.
-
-
Constructor Details
-
Shutdown
private Shutdown()Creates the thread to be executed at shutdown time.
-
-
Method Details
-
run
public void run()Invoked at JVM shutdown time. -
getContainer
Returns the value set by the last call tosetContainer(String)
.- Returns:
- typically
"OSGi"
,"Servlet"
ornull
.
-
setContainer
Invoked if the Apache SIS library is executed from an environment that provide its own shutdown hook. Example of such environments are OSG and servlet containers. In such case, the shutdown hook will not be registered to the JVMRuntime
.- Parameters:
env
- a description of the container. Should contain version information if possible. Example:"OSGi"
or"JavaServer Web Dev Kit/1.0"
.
-
register
Registers a code to execute at JVM shutdown time, or if SIS library is unloaded from a container such as OSGi. The resources will be disposed at shutdown time in reverse order (most recently added resources disposed first).The same resource shall not be added twice.
- Parameters:
resource
- the resource disposal to register for execution at shutdown time.
-
removeShutdownHook
private static void removeShutdownHook()Removes the shutdown hook, if any. -
unregister
Unregisters a code from execution at JVM shutdown time. This method uses identity comparison (it does not useObject.equals(Object)
).- Parameters:
resource
- the resource disposal to cancel execution.
-
stop
Unregisters the supervisor MBean, executes the disposal tasks and shutdowns thesis-utility
threads. This method may be invoked at JVM shutdown, or if a container like OSGi is unloaded the SIS library.- Parameters:
caller
- the class invoking this method, to be used only for logging purpose, ornull
if the logging system is not available anymore (i.e. the JVM itself is shutting down).- Throws:
Exception
- if an error occurred during unregistration of the supervisor MBean or during a resource disposal.
-