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-2025 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 |
isCompleted()
Indicates whether the shutdown routine has been completed successfully.
|
boolean |
isShutdownInProgress()
Indicate whether the hook has been started, i.e.
|
void |
run()
Implementation of the
java.lang.Runnable interface. |
void |
setCompleted(boolean completed)
Set a flag indicating that the shutdown routine is already completed and
should not be performed again.
|
void |
setShutdownReason(String shutdownReason)
Set the shutdown reason.
|
void |
setTimeoutMillis(int timeoutMillis)
Set the custom shutdown timeout.
|
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)
(package access)
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()
public void setTimeoutMillis(int timeoutMillis)
timeoutMillis
- the timeout in milliseconds. The default value is
60,000 milliseconds (60 seconds).public boolean isCompleted()
public void setCompleted(boolean completed)
completed
- true to set off (disable) the hook.public void setShutdownReason(String shutdownReason)
shutdownReason
- the shut down reason (justification).