org.tanukisoftware.wrapper
public class WrapperActionServer extends Object implements 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:
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();
Field Summary | |
---|---|
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 Summary | |
---|---|
WrapperActionServer(int port, InetAddress bindAddress)
Creates and starts WrapperActionServer instance bound to the
specified port and address.
| |
WrapperActionServer(int port)
Creates and starts WrapperActionServer instance bound to the
specified port. |
Method Summary | |
---|---|
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, 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. |
Parameters: port Port on which to listen for connections. bindAddress Address to bind to.
Parameters: port Port on which to listen for connections.
Parameters: enable True to enable to action, false to disable it.
Parameters: enable True to enable to action, false to disable it.
Parameters: enable True to enable to action, false to disable it.
Parameters: enable True to enable to action, false to disable it.
Parameters: enable True to enable to action, false to disable it.
Parameters: enable True to enable to action, false to disable it.
Parameters: enable True to enable to action, false to disable it.
try { ... } catch (Throwable t) { ... }
block.
Parameters: command Command to be registered. Will override any exiting action already registered with the same command. action Action to be registered.
Throws: IOException If the server socket is unable to bind to the specified port or there are any other problems opening a socket.