Class Shutdown

java.lang.Object
java.lang.Thread
org.apache.sis.internal.system.Shutdown
All Implemented Interfaces:
Runnable

public final class Shutdown extends Thread
A central place where to manage SIS shutdown process.
Since:
0.3
Version:
0.7
  • Field Details

    • container

      private static String container
      Non-null if a shutdown hook is already registered. That shutdown hook is not necessarily hook. It may be an OSGi or Servlet shutdown hook instead, as notified by setContainer(String).
    • hook

      private static Shutdown hook
      The shutdown hook to be registered to the JVM Runtime, created when first needed.
    • resources

      private static final List<Callable<?>> 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.
      Specified by:
      run in interface Runnable
      Overrides:
      run in class Thread
    • getContainer

      public static String getContainer()
      Returns the value set by the last call to setContainer(String).
      Returns:
      typically "OSGi", "Servlet" or null.
    • setContainer

      public static void setContainer(String env)
      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 JVM Runtime.
      Parameters:
      env - a description of the container. Should contain version information if possible. Example: "OSGi" or "JavaServer Web Dev Kit/1.0".
    • register

      public static void register(Callable<?> resource)
      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

      public static void unregister(Callable<?> resource)
      Unregisters a code from execution at JVM shutdown time. This method uses identity comparison (it does not use Object.equals(Object)).
      Parameters:
      resource - the resource disposal to cancel execution.
    • stop

      public static void stop(Class<?> caller) throws Exception
      Unregisters the supervisor MBean, executes the disposal tasks and shutdowns the sis-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, or null 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.