Package jmri

Interface ShutDownManager

  • All Superinterfaces:
    PropertyChangeProvider
    All Known Implementing Classes:
    DefaultShutDownManager

    public interface ShutDownManager
    extends PropertyChangeProvider
    Manage tasks to be completed when the program shuts down normally.

    Implementations of this interface allow other objects to register and deregister ShutDownTask objects, which are invoked in an orderly way when the program is is commanded to terminate. There is no requirement a ShutDownTask not interact with the user interface, and an assumption that, barring a headless application, that ShutDownTasks may interact with the user interface.

    There can only be one instance of this operating, and it is generally obtained via the instance manager.

    ShutDownTasks should leave the system in a state that can continue, in case a later task aborts the shutdown.

    An instance of this is normally obtained from the instance manager, using may assume that one is always present.

    • Method Detail

      • register

        void register​(@Nonnull
                      ShutDownTask task)
        Register a task object for later execution. An attempt to register an already registered task will be silently ignored.
        Parameters:
        task - the task to execute
        Throws:
        java.lang.NullPointerException - if the task is null
      • register

        void register​(@Nonnull
                      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.
        Parameters:
        task - the verification task
        Throws:
        java.lang.NullPointerException - if the task is null
      • register

        void register​(@Nonnull
                      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.
        Parameters:
        task - the execution task
        Throws:
        java.lang.NullPointerException - if the task is null
      • deregister

        void deregister​(@CheckForNull
                        ShutDownTask task)
        Deregister a task. Attempts to deregister a task that is not registered are silently ignored.
        Parameters:
        task - the task not to execute
      • deregister

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

        void deregister​(@CheckForNull
                        java.lang.Runnable task)
        Deregister a task. Attempts to deregister a task that is not registered are silently ignored.
        Parameters:
        task - the task not to run
      • getCallables

        @Nonnull
        java.util.List<java.util.concurrent.Callable<java.lang.Boolean>> getCallables()
      • restartOS

        boolean restartOS()
        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 java program.

        NOTE If the macOS application->quit menu item is used, this must return false to abort the shutdown.

        Returns:
        false if any shutdown task aborts restarting the application
      • restart

        boolean restart()
        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.

        Returns:
        false if any shutdown task aborts restarting the application
      • shutdownOS

        boolean 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

        NOTE If the macOS application->quit menu item is used, this must return false to abort the shutdown.

        Returns:
        false if any shutdown task aborts restarting the application
      • shutdown

        boolean 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.

        NOTE If the macOS application->quit menu item is used, this must return false to abort the shutdown.

        Returns:
        false if any shutdown task aborts the shutdown or if anything goes wrong.
      • isShuttingDown

        boolean isShuttingDown()
        Allow components that normally request confirmation to shutdown to determine if the shutdown is already underway so as not to request confirmation.
        Returns:
        true if shutting down or restarting