KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > tanukisoftware > wrapper > jmx > WrapperManagerTesting


1 package org.tanukisoftware.wrapper.jmx;
2
3 /*
4  * Copyright (c) 1999, 2006 Tanuki Software Inc.
5  *
6  * Permission is hereby granted, free of charge, to any person
7  * obtaining a copy of the Java Service Wrapper and associated
8  * documentation files (the "Software"), to deal in the Software
9  * without restriction, including without limitation the rights
10  * to use, copy, modify, merge, publish, distribute, sub-license,
11  * and/or sell copies of the Software, and to permit persons to
12  * whom the Software is furnished to do so, subject to the
13  * following conditions:
14  *
15  * The above copyright notice and this permission notice shall be
16  * included in all copies or substantial portions of the Software.
17  *
18  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
20  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21  * NON-INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
22  * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
23  * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
25  * OTHER DEALINGS IN THE SOFTWARE.
26  */

27
28 /**
29  * @author Leif Mortenson <leif@tanukisoftware.com>
30  */

31 public class WrapperManagerTesting
32     implements WrapperManagerTestingMBean
33 {
34     /*---------------------------------------------------------------
35      * WrapperManagerTestingMBean Methods
36      *-------------------------------------------------------------*/

37     /**
38      * Causes the WrapperManager to go into a state which makes the JVM appear
39      * to be hung when viewed from the native Wrapper code. Does not have
40      * any effect when the JVM is not being controlled from the native
41      * Wrapper.
42      */

43     public void appearHung()
44     {
45         org.tanukisoftware.wrapper.WrapperManager.appearHung();
46     }
47     
48     /**
49      * Cause an access violation within native JNI code. This currently causes
50      * the access violation by attempting to write to a null pointer.
51      */

52     public void accessViolationNative()
53     {
54         // This action normally will not return, so launch it in a background
55
// thread giving JMX a chance to return a response to its client.
56
new Thread JavaDoc()
57         {
58             public void run()
59             {
60                 try
61                 {
62                     Thread.sleep( 1000 );
63                 }
64                 catch ( InterruptedException JavaDoc e )
65                 {
66                 }
67                 
68                 org.tanukisoftware.wrapper.WrapperManager.accessViolationNative();
69             }
70         }.start();
71     }
72     
73     /**
74      * Tells the native wrapper that the JVM wants to shut down and then
75      * promptly halts. Be careful when using this method as an application
76      * will not be given a chance to shutdown cleanly.
77      *
78      * @param exitCode The exit code that the Wrapper will return when it exits.
79      */

80     public void stopImmediate( final int exitCode )
81     {
82         // This action normally will not return, so launch it in a background
83
// thread giving JMX a chance to return a response to its client.
84
new Thread JavaDoc()
85         {
86             public void run()
87             {
88                 try
89                 {
90                     Thread.sleep( 1000 );
91                 }
92                 catch ( InterruptedException JavaDoc e )
93                 {
94                 }
95                 
96                 org.tanukisoftware.wrapper.WrapperManager.stopImmediate( exitCode );
97             }
98         }.start();
99     }
100 }
101
Popular Tags