Package jmri.managers

Class DefaultShutDownManager

  • All Implemented Interfaces:
    BeanInterface, PropertyChangeFirer, PropertyChangeProvider, ShutDownManager

    public class DefaultShutDownManager
    extends Bean
    implements ShutDownManager
    The default implementation of ShutDownManager. This implementation makes the following assumptions:
    • The shutdown() and restart() methods are called on the application's main thread.
    • If the application has a graphical user interface, the application's main thread is the event dispatching thread.
    • Application windows may contain code that should be run within a registered ShutDownTask.run() method, but are not. A side effect of this assumption is that all displayable application windows are closed by this implementation when shutdown() or restart() is called and a ShutDownTask has not aborted the shutdown or restart.
    • It is expected that SIGINT and SIGTERM should trigger a clean application exit.

    If another implementation of ShutDownManager has not been registered with the InstanceManager, an instance of this implementation will be automatically registered as the ShutDownManager.

    Developers other applications that cannot accept the above assumptions are recommended to create their own implementations of ShutDownManager that integrates with their application's lifecycle and register that implementation with the InstanceManager as soon as possible in their application.

    • Method Detail

      • setBlockingShutdown

        public void setBlockingShutdown​(boolean value)
        Set if shutdown should block GUI/Layout thread.
        Parameters:
        value - true if blocking, false otherwise
      • register

        public void register​(ShutDownTask s)
        Register a task object for later execution. An attempt to register an already registered task will be silently ignored.
        Specified by:
        register in interface ShutDownManager
        Parameters:
        s - the task to execute
      • register

        public void register​(java.util.concurrent.Callable<java.lang.Boolean> task)
        Register a task for verification that JMRI should stop. An attempt to register an already register task will be silently ignored.
        Specified by:
        register in interface ShutDownManager
        Parameters:
        task - the verification task
      • register

        public void register​(java.lang.Runnable task)
        Register a task that runs when JMRI is stopping. An attempt to register an already register task will be silently ignored.
        Specified by:
        register in interface ShutDownManager
        Parameters:
        task - the execution task
      • deregister

        public void deregister​(ShutDownTask s)
        Deregister a task. Attempts to deregister a task that is not registered are silently ignored.
        Specified by:
        deregister in interface ShutDownManager
        Parameters:
        s - the task not to execute
      • deregister

        public void deregister​(java.util.concurrent.Callable<java.lang.Boolean> task)
        Deregister a task. Attempts to deregister a task that is not registered are silently ignored.
        Specified by:
        deregister in interface ShutDownManager
        Parameters:
        task - the task not to call
      • deregister

        public void deregister​(java.lang.Runnable task)
        Deregister a task. Attempts to deregister a task that is not registered are silently ignored.
        Specified by:
        deregister in interface ShutDownManager
        Parameters:
        task - the task not to run
      • shutdown

        public void shutdown()
        Run the shutdown tasks, and then terminate the program with status 0 if not aborted. Does not return under normal circumstances. Returns false if the shutdown was aborted by the user, in which case the program should continue to operate.
        Specified by:
        shutdown in interface ShutDownManager
      • restart

        public void restart()
        Run the shutdown tasks, and then terminate the program with status 100 if not aborted. Does not return under normal circumstances. Returns false if the shutdown was aborted by the user, in which case the program should continue to operate.

        By exiting the program with status 100, the batch file (MS Windows) or shell script (Linux/macOS/UNIX) can catch the exit status and restart the JMRI java program.

        Specified by:
        restart in interface ShutDownManager
      • restartOS

        public void restartOS()
        Run the shutdown tasks, and then terminate the program with status 210 if not aborted. Does not return under normal circumstances. Returns false if the shutdown was aborted by the user, in which case the program should continue to operate.

        By exiting the program with status 210, the batch file (MS Windows) or shell script (Linux/macOS/UNIX) can catch the exit status and tell the operating system to restart.

        Specified by:
        restartOS in interface ShutDownManager
      • shutdownOS

        public void shutdownOS()
        Run the shutdown tasks, and then terminate the program with status 200 if not aborted. Does not return under normal circumstances. Returns false if the shutdown was aborted by the user, in which case the program should continue to operate.

        By exiting the program with status 200, the batch file (MS Windows) or shell script (Linux/macOS/UNIX) can catch the exit status and shutdown the OS

        Specified by:
        shutdownOS in interface ShutDownManager
      • shutdown

        public void shutdown​(int status,
                             boolean exit)
        First asks the shutdown tasks if shutdown is allowed. Returns if the shutdown was aborted by the user, in which case the program should continue to operate.

        After this check does not return under normal circumstances. Closes any displayable windows. Executes all registered ShutDownTask Runs the Early shutdown tasks, the main shutdown tasks, then terminates the program with provided status.

        Parameters:
        status - integer status on program exit
        exit - true if System.exit() should be called if all tasks are executed correctly; false otherwise
      • isShuttingDown

        public boolean isShuttingDown()
        Allow components that normally request confirmation to shutdown to determine if the shutdown is already underway so as not to request confirmation.
        Specified by:
        isShuttingDown in interface ShutDownManager
        Returns:
        true if shutting down or restarting
      • isShutDownComplete

        public boolean isShutDownComplete()
        Flag to indicate when all shutDown tasks completed. For test purposes, the app would normally exit before setting the flag.
        Returns:
        true when Shutdown tasks are complete and System.exit is not called.
      • setShuttingDown

        protected void setShuttingDown​(boolean state)
        This method is static so that if multiple DefaultShutDownManagers are registered, they are all aware of this state.
        Parameters:
        state - true if shutting down; false otherwise