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 Details

    • register

      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:
      NullPointerException - if the task is null
    • register

      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:
      NullPointerException - if the task is null
    • register

      void register​(@Nonnull 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:
      NullPointerException - if the task is null
    • deregister

      Deregister a task. Attempts to deregister a task that is not registered are silently ignored.
      Parameters:
      task - the task not to execute
    • deregister

      Deregister a task. Attempts to deregister a task that is not registered are silently ignored.
      Parameters:
      task - the task not to call
    • deregister

      Deregister a task. Attempts to deregister a task that is not registered are silently ignored.
      Parameters:
      task - the task not to run
    • tasks

      Deprecated.
      since 4.21.1; use getCallables() and getRunnables() instead
      Provide access to the current registered shutdown tasks.

      Note that implementations are free to provide a copy of the list of registered tasks and do not need to provide modifiable live access to the internal list of registered tasks.

      Returns:
      the list of shutdown tasks or an empty list if no shutdown tasks are registered
    • getCallables

    • getRunnables

    • 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