public class ShutdownHook extends Thread implements ActionListener
Custom hook assuring a clean application shut down when Java Virtual Machine (JVM) gets terminated.
An instance of this class is created and hooked into the JVM for each automated thread. It gets invoked by Java when a request to terminate the JVM is detected, e.g. through Ctrl+C in the system console. The hook takes care of clean shutdown of the executed test script (if any) and proper termination of any existing server connection.
T-Plan Robot Enterprise, (C) 2009-2022 T-Plan Limited. All rights reserved.
Thread.State, Thread.UncaughtExceptionHandler
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
Constructor and Description |
---|
ShutdownHook(ScriptManager scriptManager,
RemoteDesktopClient client)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
actionPerformed(ActionEvent ae)
Implementation of the
ActionListener interface allowing to run
the thread code in the GUI mode with the progress bar displayed using
ProgressDialog.runAWTTask(java.awt.event.ActionListener, java.lang.String, java.lang.String) |
void |
addClient(RemoteDesktopClient client)
Add a desktop client to be closed (disconnected) eventually on JVM
shutdown.
|
static ShutdownHook |
getGlobalHook()
Get the default singleton hook instance registered with the runtime.
|
boolean |
isShutdownInProgress()
Indicate whether the hook has been started, i.e.
|
void |
run()
Implementation of the
java.lang.Runnable interface. |
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield
public ShutdownHook(ScriptManager scriptManager, RemoteDesktopClient client)
scriptManager
- a script manager instance.client
- a desktop client.public static ShutdownHook getGlobalHook()
addClient(com.tplan.robot.remoteclient.RemoteDesktopClient)
and addModule(com.tplan.robot.CLIModule)
methods to add objects
to be closed down properly on the JVM shut down.public final void run()
java.lang.Runnable
interface. This
method gets executed when the encapsulating thread is started.public final void addClient(RemoteDesktopClient client)
client
- a client.public void actionPerformed(ActionEvent ae)
ActionListener
interface allowing to run
the thread code in the GUI mode with the progress bar displayed using
ProgressDialog.runAWTTask(java.awt.event.ActionListener, java.lang.String, java.lang.String)
actionPerformed
in interface ActionListener
ae
- an action event.public boolean isShutdownInProgress()