KickJava   Java API By Example, From Geeks To Geeks.

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


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 WrapperManager
32     implements WrapperManagerMBean
33 {
34     /*---------------------------------------------------------------
35      * WrapperManagerMBean Methods
36      *-------------------------------------------------------------*/

37     /**
38      * Obtain the current version of Wrapper.
39      *
40      * @return The version of the Wrapper.
41      */

42     public String JavaDoc getVersion()
43     {
44         return org.tanukisoftware.wrapper.WrapperManager.getVersion();
45     }
46     
47     /**
48      * Obtain the build time of Wrapper.
49      *
50      * @return The time that the Wrapper was built.
51      */

52     public String JavaDoc getBuildTime()
53     {
54         return org.tanukisoftware.wrapper.WrapperManager.getBuildTime();
55     }
56     
57     /**
58      * Returns the Id of the current JVM. JVM Ids increment from 1 each time
59      * the wrapper restarts a new one.
60      *
61      * @return The Id of the current JVM.
62      */

63     public int getJVMId()
64     {
65         return org.tanukisoftware.wrapper.WrapperManager.getJVMId();
66     }
67     
68     /**
69      * Sets the title of the console in which the Wrapper is running. This
70      * is currently only supported on Windows platforms.
71      * <p>
72      * As an alternative, it is also possible to set the console title from
73      * within the wrapper.conf file using the wrapper.console.title property.
74      *
75      * @param title The new title. The specified string will be encoded
76      * to a byte array using the default encoding for the
77      * current platform.
78      */

79     public void setConsoleTitle( String JavaDoc title )
80     {
81         org.tanukisoftware.wrapper.WrapperManager.setConsoleTitle( title );
82     }
83     
84     /**
85      * Returns the PID of the Wrapper process.
86      *
87      * A PID of 0 will be returned if the JVM was launched standalone.
88      *
89      * This value can also be obtained using the 'wrapper.pid' system property.
90      *
91      * @return The PID of the Wrpper process.
92      */

93     public int getWrapperPID()
94     {
95         return org.tanukisoftware.wrapper.WrapperManager.getWrapperPID();
96     }
97     
98     /**
99      * Returns the PID of the Java process.
100      *
101      * A PID of 0 will be returned if the native library has not been initialized.
102      *
103      * This value can also be obtained using the 'wrapper.java.pid' system property.
104      *
105      * @return The PID of the Java process.
106      */

107     public int getJavaPID()
108     {
109         return org.tanukisoftware.wrapper.WrapperManager.getJavaPID();
110     }
111     
112     /**
113      * Requests that the current JVM process request a thread dump. This is
114      * the same as pressing CTRL-BREAK (under Windows) or CTRL-\ (under Unix)
115      * in the the console in which Java is running. This method does nothing
116      * if the native library is not loaded.
117      */

118     public void requestThreadDump()
119     {
120         org.tanukisoftware.wrapper.WrapperManager.requestThreadDump();
121     }
122     
123     /**
124      * Returns true if the JVM was launched by the Wrapper application. False
125      * if the JVM was launched manually without the Wrapper controlling it.
126      *
127      * @return True if the current JVM was launched by the Wrapper.
128      */

129     public boolean isControlledByNativeWrapper()
130     {
131         return org.tanukisoftware.wrapper.WrapperManager.isControlledByNativeWrapper();
132     }
133     
134     /**
135      * Returns true if the Wrapper was launched as an NT service on Windows or
136      * as a daemon process on UNIX platforms. False if launched as a console.
137      * This can be useful if you wish to display a user interface when in
138      * Console mode. On UNIX platforms, this is not as useful because an
139      * X display may not be visible even if launched in a console.
140      *
141      * @return True if the Wrapper is running as an NT service or daemon
142      * process.
143      */

144     public boolean isLaunchedAsService()
145     {
146         return org.tanukisoftware.wrapper.WrapperManager.isLaunchedAsService();
147     }
148     
149     /**
150      * Returns true if the wrapper.debug property, or any of the logging
151      * channels are set to DEBUG in the wrapper configuration file. Useful
152      * for deciding whether or not to output certain information to the
153      * console.
154      *
155      * @return True if the Wrapper is logging any Debug level output.
156      */

157     public boolean isDebugEnabled()
158     {
159         return org.tanukisoftware.wrapper.WrapperManager.isDebugEnabled();
160     }
161     
162     /**
163      * Tells the native wrapper that the JVM wants to restart, then informs
164      * all listeners that the JVM is about to shutdown before killing the JVM.
165      * <p>
166      * The restart is actually performed in a background thread allowing JMX
167      * a chance to respond to the client.
168      */

169     public void restart()
170     {
171         // This action normally will not return, so launch it in a background
172
// thread giving JMX a chance to return a response to its client.
173
new Thread JavaDoc()
174         {
175             public void run()
176             {
177                 try
178                 {
179                     Thread.sleep( 1000 );
180                 }
181                 catch ( InterruptedException JavaDoc e )
182                 {
183                 }
184                 
185                 org.tanukisoftware.wrapper.WrapperManager.restart();
186             }
187         }.start();
188     }
189     
190     /**
191      * Tells the native wrapper that the JVM wants to shut down, then informs
192      * all listeners that the JVM is about to shutdown before killing the JVM.
193      * <p>
194      * The stop is actually performed in a background thread allowing JMX
195      * a chance to respond to the client.
196      *
197      * @param exitCode The exit code that the Wrapper will return when it exits.
198      */

199     public void stop( final int exitCode )
200     {
201         // This action normally will not return, so launch it in a background
202
// thread giving JMX a chance to return a response to its client.
203
new Thread JavaDoc()
204         {
205             public void run()
206             {
207                 try
208                 {
209                     Thread.sleep( 1000 );
210                 }
211                 catch ( InterruptedException JavaDoc e )
212                 {
213                 }
214                 
215                 org.tanukisoftware.wrapper.WrapperManager.stop( exitCode );
216             }
217         }.start();
218     }
219     
220     /**
221      * Returns true if the ShutdownHook for the JVM has already been triggered.
222      * Some code needs to know whether or not the system is shutting down.
223      *
224      * @return True if the ShutdownHook for the JVM has already been triggered.
225      */

226     public boolean getHasShutdownHookBeenTriggered()
227     {
228         return org.tanukisoftware.wrapper.WrapperManager.hasShutdownHookBeenTriggered();
229     }
230 }
231
Popular Tags