Class DefaultShutDownManager
- All Implemented Interfaces:
BeanInterface,PropertyChangeFirer,PropertyChangeProvider,ShutDownManager
ShutDownManager. This implementation
makes the following assumptions:
- The
shutdown()andrestart()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.
-
Field Summary
FieldsFields inherited from class jmri.beans.Bean
propertyChangeSupport -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidderegister(Runnable task) Deregister a task.voidderegister(Callable<Boolean> task) Deregister a task.voidDeregister a task.booleanFlag to indicate when all shutDown tasks completed.booleanAllow components that normally request confirmation to shutdown to determine if the shutdown is already underway so as not to request confirmation.voidRegister a task that runs when JMRI is stopping.voidRegister a task for verification that JMRI should stop.voidRegister a task object for later execution.voidrestart()Run the shutdown tasks, and then terminate the program with status 100 if not aborted.voidRun the shutdown tasks, and then terminate the program with status 210 if not aborted.voidsetBlockingShutdown(boolean value) Set if shutdown should block GUI/Layout thread.protected voidsetShuttingDown(boolean state) This method is static so that if multiple DefaultShutDownManagers are registered, they are all aware of this state.(package private) static voidsetStaticShuttingDown(boolean state) voidshutdown()Run the shutdown tasks, and then terminate the program with status 0 if not aborted.voidshutdown(int status, boolean exit) First asks the shutdown tasks if shutdown is allowed.voidRun the shutdown tasks, and then terminate the program with status 200 if not aborted.Methods inherited from class jmri.beans.Bean
addPropertyChangeListener, addPropertyChangeListener, fireIndexedPropertyChange, fireIndexedPropertyChange, fireIndexedPropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getPropertyChangeListeners, getPropertyChangeListeners, isNotifyOnEDT, removePropertyChangeListener, removePropertyChangeListenerMethods inherited from class jmri.beans.UnboundBean
getIndexedProperty, getProperty, getPropertyNames, hasIndexedProperty, hasProperty, setIndexedProperty, setPropertyMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface jmri.beans.PropertyChangeProvider
addPropertyChangeListener, addPropertyChangeListener, getPropertyChangeListeners, getPropertyChangeListeners, removePropertyChangeListener, removePropertyChangeListener
-
Field Details
-
shutdownHook
-
tasksTimeOutMilliSec
-
-
Constructor Details
-
DefaultShutDownManager
public DefaultShutDownManager()Create a new shutdown manager.
-
-
Method Details
-
setBlockingShutdown
Set if shutdown should block GUI/Layout thread.- Parameters:
value- true if blocking, false otherwise
-
register
Register a task object for later execution. An attempt to register an already registered task will be silently ignored.- Specified by:
registerin interfaceShutDownManager- Parameters:
s- the task to execute
-
register
Register a task for verification that JMRI should stop. An attempt to register an already register task will be silently ignored.- Specified by:
registerin interfaceShutDownManager- Parameters:
task- the verification task
-
register
Register a task that runs when JMRI is stopping. An attempt to register an already register task will be silently ignored.- Specified by:
registerin interfaceShutDownManager- Parameters:
task- the execution task
-
deregister
Deregister a task. Attempts to deregister a task that is not registered are silently ignored.- Specified by:
deregisterin interfaceShutDownManager- Parameters:
s- the task not to execute
-
deregister
Deregister a task. Attempts to deregister a task that is not registered are silently ignored.- Specified by:
deregisterin interfaceShutDownManager- Parameters:
task- the task not to call
-
deregister
Deregister a task. Attempts to deregister a task that is not registered are silently ignored.- Specified by:
deregisterin interfaceShutDownManager- Parameters:
task- the task not to run
-
getCallables
- Specified by:
getCallablesin interfaceShutDownManager
-
getRunnables
- Specified by:
getRunnablesin interfaceShutDownManager
-
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:
shutdownin interfaceShutDownManager
-
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:
restartin interfaceShutDownManager
-
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:
restartOSin interfaceShutDownManager
-
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:
shutdownOSin interfaceShutDownManager
-
shutdown
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
ShutDownTaskRuns the Early shutdown tasks, the main shutdown tasks, then terminates the program with provided status.- Parameters:
status- integer status on program exitexit- true if System.exit() should be called if all tasks are executed correctly; false otherwise
-
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:
isShuttingDownin interfaceShutDownManager- Returns:
- true if shutting down or restarting
-
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
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
-
setStaticShuttingDown
-