public class WrapperActionServer
extends java.lang.Object
implements java.lang.Runnable
The easiest way to invoke an action manually is to telnet to the specified
port and then type the single command key.
telnet localhost 9999
, for example.
Valid commands include:
Additional user defined actions can be defined by calling the
registerAction( byte command, Runnable action )
method.
The Wrapper project reserves the right to define any upper case
commands in the future. To avoid future conflicts, please use lower
case for user defined commands.
This application will work even in most deadlock situations because the thread is in issolation from the rest of the application. If the JVM is truely hung, this class will fail to accept connections but the Wrapper itself will detect the hang and restart the JVM externally.
The following code can be used in your application to start up the WrapperActionServer with all default actions enabled:
int port = 9999; WrapperActionServer server = new WrapperActionServer( port ); server.enableShutdownAction( true ); server.enableHaltExpectedAction( true ); server.enableRestartAction( true ); server.enableThreadDumpAction( true ); server.enableHaltUnexpectedAction( true ); server.enableAccessViolationAction( true ); server.enableAppearHungAction( true ); server.start();Then remember to stop the server when your application shuts down:
server.stop();
Modifier and Type | Field and Description |
---|---|
static byte |
COMMAND_ACCESS_VIOLATION
Command to invoke an access violation.
|
static byte |
COMMAND_APPEAR_HUNG
Command to invoke an appear hung action.
|
static byte |
COMMAND_DUMP
Command to invoke a thread dump action.
|
static byte |
COMMAND_HALT_EXPECTED
Command to invoke an expected halt action.
|
static byte |
COMMAND_HALT_UNEXPECTED
Command to invoke an unexpected halt action.
|
static byte |
COMMAND_RESTART
Command to invoke a restart action.
|
static byte |
COMMAND_SHUTDOWN
Command to invoke a shutdown action.
|
Constructor and Description |
---|
WrapperActionServer(int port)
Creates and starts WrapperActionServer instance bound to the
specified port.
|
WrapperActionServer(int port,
java.net.InetAddress bindAddress)
Creates and starts WrapperActionServer instance bound to the
specified port and address.
|
Modifier and Type | Method and Description |
---|---|
void |
enableAccessViolationAction(boolean enable)
Enable or disable the access violation command.
|
void |
enableAppearHungAction(boolean enable)
Enable or disable the appear hung command.
|
void |
enableHaltExpectedAction(boolean enable)
Enable or disable the expected halt command.
|
void |
enableHaltUnexpectedAction(boolean enable)
Enable or disable the unexpected halt command.
|
void |
enableRestartAction(boolean enable)
Enable or disable the restart command.
|
void |
enableShutdownAction(boolean enable)
Enable or disable the shutdown command.
|
void |
enableThreadDumpAction(boolean enable)
Enable or disable the thread dump command.
|
void |
registerAction(byte command,
java.lang.Runnable action)
Registers an action with the action server.
|
void |
run()
Thread which will listen for connections on the socket.
|
void |
start()
Starts the runner thread.
|
void |
stop()
Stops the runner thread, blocking until it has stopped.
|
void |
unregisterAction(byte command)
Unregisters an action with the given command.
|
public static final byte COMMAND_SHUTDOWN
public static final byte COMMAND_HALT_EXPECTED
public static final byte COMMAND_RESTART
public static final byte COMMAND_DUMP
public static final byte COMMAND_HALT_UNEXPECTED
public static final byte COMMAND_ACCESS_VIOLATION
public static final byte COMMAND_APPEAR_HUNG
public WrapperActionServer(int port, java.net.InetAddress bindAddress)
port
- Port on which to listen for connections.bindAddress
- Address to bind to.public WrapperActionServer(int port)
port
- Port on which to listen for connections.public void run()
run
in interface java.lang.Runnable
public void start() throws java.io.IOException
java.io.IOException
- If the server socket is unable to bind to the
specified port or there are any other problems
opening a socket.public void stop() throws java.lang.Exception
java.lang.Exception
- If the thread is unable to interrupt.public void registerAction(byte command, java.lang.Runnable action)
try { ... } catch (Throwable t) { ... }
block.command
- Command to be registered. Will override any exiting
action already registered with the same command.action
- Action to be registered.public void unregisterAction(byte command)
command
- Command to be unregistered.public void enableShutdownAction(boolean enable)
enable
- True to enable to action, false to disable it.public void enableHaltExpectedAction(boolean enable)
enable
- True to enable to action, false to disable it.public void enableRestartAction(boolean enable)
enable
- True to enable to action, false to disable it.public void enableThreadDumpAction(boolean enable)
enable
- True to enable to action, false to disable it.public void enableHaltUnexpectedAction(boolean enable)
enable
- True to enable to action, false to disable it.public void enableAccessViolationAction(boolean enable)
enable
- True to enable to action, false to disable it.public void enableAppearHungAction(boolean enable)
enable
- True to enable to action, false to disable it.Copyright 1999, 2024 Tanuki Software Inc., All Rights Reserved.