Java Doc for WrapperActionServer.java in  » Collaboration » Java-Service-Wrapper » org » tanukisoftware » wrapper » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Collaboration » Java Service Wrapper » org.tanukisoftware.wrapper 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   org.tanukisoftware.wrapper.WrapperActionServer

WrapperActionServer
public class WrapperActionServer implements Runnable(Code)
If an application instantiates an instance of this class, the JVM will listen on the specified port for connections. When a connection is detected, the first byte of input will be read from the socket and then the connection will be immediately closed. An action will then be performed based on the byte read from the stream.

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:

  • S : Shutdown cleanly.
  • H : Immediate forced shutdown.
  • R : Restart
  • D : Perform a Thread Dump
  • U : Unexpected shutdown. (Simulate a crash for testing)
  • V : Cause an access violation. (For testing)
  • G : Make the JVM appear to be hung. (For testing)
Additional user defined actions can be defined by calling the WrapperActionServer.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();
 

author:
   Leif Mortenson


Field Summary
final public static  byteCOMMAND_ACCESS_VIOLATION
     Command to invoke an access violation.
final public static  byteCOMMAND_APPEAR_HUNG
     Command to invoke an appear hung action.
final public static  byteCOMMAND_DUMP
     Command to invoke a thread dump action.
final public static  byteCOMMAND_HALT_EXPECTED
     Command to invoke an expected halt action.
final public static  byteCOMMAND_HALT_UNEXPECTED
     Command to invoke an unexpected halt action.
final public static  byteCOMMAND_RESTART
     Command to invoke a restart action.
final public static  byteCOMMAND_SHUTDOWN
     Command to invoke a shutdown action.

Constructor Summary
public  WrapperActionServer(int port, InetAddress bindAddress)
     Creates and starts WrapperActionServer instance bound to the specified port and address.
public  WrapperActionServer(int port)
     Creates and starts WrapperActionServer instance bound to the specified port.

Method Summary
public  voidenableAccessViolationAction(boolean enable)
     Enable or disable the access violation command.
public  voidenableAppearHungAction(boolean enable)
     Enable or disable the appear hung command.
public  voidenableHaltExpectedAction(boolean enable)
     Enable or disable the expected halt command.
public  voidenableHaltUnexpectedAction(boolean enable)
     Enable or disable the unexpected halt command.
public  voidenableRestartAction(boolean enable)
     Enable or disable the restart command.
public  voidenableShutdownAction(boolean enable)
     Enable or disable the shutdown command.
public  voidenableThreadDumpAction(boolean enable)
     Enable or disable the thread dump command.
public  voidregisterAction(byte command, Runnable action)
     Registers an action with the action server.
public  voidrun()
     Thread which will listen for connections on the socket.
public  voidstart()
     Starts the runner thread.
public  voidstop()
     Stops the runner thread, blocking until it has stopped.
public  voidunregisterAction(byte command)
     Unregisters an action with the given command.

Field Detail
COMMAND_ACCESS_VIOLATION
final public static byte COMMAND_ACCESS_VIOLATION(Code)
Command to invoke an access violation.



COMMAND_APPEAR_HUNG
final public static byte COMMAND_APPEAR_HUNG(Code)
Command to invoke an appear hung action.



COMMAND_DUMP
final public static byte COMMAND_DUMP(Code)
Command to invoke a thread dump action.



COMMAND_HALT_EXPECTED
final public static byte COMMAND_HALT_EXPECTED(Code)
Command to invoke an expected halt action.



COMMAND_HALT_UNEXPECTED
final public static byte COMMAND_HALT_UNEXPECTED(Code)
Command to invoke an unexpected halt action.



COMMAND_RESTART
final public static byte COMMAND_RESTART(Code)
Command to invoke a restart action.



COMMAND_SHUTDOWN
final public static byte COMMAND_SHUTDOWN(Code)
Command to invoke a shutdown action.




Constructor Detail
WrapperActionServer
public WrapperActionServer(int port, InetAddress bindAddress)(Code)
Creates and starts WrapperActionServer instance bound to the specified port and address.
Parameters:
  port - Port on which to listen for connections.
Parameters:
  bindAddress - Address to bind to.



WrapperActionServer
public WrapperActionServer(int port)(Code)
Creates and starts WrapperActionServer instance bound to the specified port. The socket will bind to all addresses and should be concidered a security risk.
Parameters:
  port - Port on which to listen for connections.




Method Detail
enableAccessViolationAction
public void enableAccessViolationAction(boolean enable)(Code)
Enable or disable the access violation command. Disabled by default. This command is useful for testing how an application handles the worst case situation where the JVM suddenly crashed. When this happens, the the JVM will simply die and there will be absolutely no chance for any shutdown or cleanup work to be done by the JVM.
Parameters:
  enable - True to enable to action, false to disable it.



enableAppearHungAction
public void enableAppearHungAction(boolean enable)(Code)
Enable or disable the appear hung command. Disabled by default. This command is useful for testing how an application handles the situation where the JVM stops responding to the Wrapper's ping requests. This can happen if the JVM hangs or some piece of code deadlocks. When this happens, the Wrapper will give up after the ping timeout has expired and kill the JVM process. The JVM will not have a chance to clean up and shudown gracefully.
Parameters:
  enable - True to enable to action, false to disable it.



enableHaltExpectedAction
public void enableHaltExpectedAction(boolean enable)(Code)
Enable or disable the expected halt command. Disabled by default. This will shutdown the JVM, but will do so immediately without going through the clean shutdown process.
Parameters:
  enable - True to enable to action, false to disable it.



enableHaltUnexpectedAction
public void enableHaltUnexpectedAction(boolean enable)(Code)
Enable or disable the unexpected halt command. Disabled by default. If this command is executed, the Wrapper will think the JVM crashed and restart it.
Parameters:
  enable - True to enable to action, false to disable it.



enableRestartAction
public void enableRestartAction(boolean enable)(Code)
Enable or disable the restart command. Disabled by default.
Parameters:
  enable - True to enable to action, false to disable it.



enableShutdownAction
public void enableShutdownAction(boolean enable)(Code)
Enable or disable the shutdown command. Disabled by default.
Parameters:
  enable - True to enable to action, false to disable it.



enableThreadDumpAction
public void enableThreadDumpAction(boolean enable)(Code)
Enable or disable the thread dump command. Disabled by default.
Parameters:
  enable - True to enable to action, false to disable it.



registerAction
public void registerAction(byte command, Runnable action)(Code)
Registers an action with the action server. The server will not accept any new connections until an action has returned, so keep that in mind when writing them. Also be aware than any uncaught exceptions will be dumped to the console if uncaught by the action. To avoid this, wrap the code in a try { ... } catch (Throwable t) { ... } block.
Parameters:
  command - Command to be registered. Will override any exitingaction already registered with the same command.
Parameters:
  action - Action to be registered.



run
public void run()(Code)
Thread which will listen for connections on the socket.



start
public void start() throws IOException(Code)
Starts the runner thread.
throws:
  IOException - If the server socket is unable to bind to thespecified port or there are any other problemsopening a socket.



stop
public void stop() throws Exception(Code)
Stops the runner thread, blocking until it has stopped.



unregisterAction
public void unregisterAction(byte command)(Code)
Unregisters an action with the given command. If no action exists with the specified command, the method will quietly ignore the call.



Methods inherited from java.lang.Object
native protected Object clone() throws CloneNotSupportedException(Code)(Java Doc)
public boolean equals(Object obj)(Code)(Java Doc)
protected void finalize() throws Throwable(Code)(Java Doc)
final native public Class getClass()(Code)(Java Doc)
native public int hashCode()(Code)(Java Doc)
final native public void notify()(Code)(Java Doc)
final native public void notifyAll()(Code)(Java Doc)
public String toString()(Code)(Java Doc)
final native public void wait(long timeout) throws InterruptedException(Code)(Java Doc)
final public void wait(long timeout, int nanos) throws InterruptedException(Code)(Java Doc)
final public void wait() throws InterruptedException(Code)(Java Doc)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.