KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > admin > common > ServerInstanceStatus


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 package com.sun.enterprise.admin.common;
25
26 // i18n import
27
import com.sun.enterprise.admin.util.SOMLocalStringsManager;
28
29 /**
30     A class that represents the status of a Server Instance.
31 */

32 public class ServerInstanceStatus extends Status
33 {
34     /* javac 1.3 generated serialVersionUID */
35     public static final long serialVersionUID = 7309765796199182533L;
36
37     private boolean mDebug = false;
38     private int mDebugPort = -1;
39     // i18n SOMLocalStringsManager
40
private static SOMLocalStringsManager localizedStrMgr =
41         SOMLocalStringsManager.getManager( ServerInstanceStatus.class );
42
43     /**
44         Creates new Status that represents state of a running Server Instance.
45     */

46     public ServerInstanceStatus ()
47     {
48         super(Status.kInstanceRunningCode, Status.kInstanceRunningMsg);
49     }
50
51     /**
52      * Create new status that represents specified status. If specified status
53      * code is invalid the method throws an IllegalArgumentException
54      * @param statusCode status code, one of <code>Status.kInstanceStartingCode,
55      * Status.kInstanceRunningCode, Status.kInstanceStoppingCode and
56      * Status.kInstanceNotRunningCode</code>.
57      * @throws IllegalArgumentException if specified status code is invalid.
58      */

59     public ServerInstanceStatus (int statusCode)
60     {
61         super();
62         setStatusCodeAndStr(statusCode);
63     }
64
65     public ServerInstanceStatus(int code, String JavaDoc str)
66     {
67         super(code, str);
68     }
69
70     public boolean isRunning ()
71     {
72         return (mStatusCode == Status.kInstanceRunningCode);
73     }
74
75     /**
76      * Convenience method for setting the current status code
77      * to running.
78      */

79     public void setRunning()
80     {
81         mStatusCode = kInstanceRunningCode;
82         mStatusString = kInstanceRunningMsg;
83     }
84
85     /**
86      * Returns true if the status code is set to kInstanceStartingCode,
87      * false otherwise.
88      */

89     public boolean isStarting()
90     {
91         return (mStatusCode == kInstanceStartingCode);
92     }
93
94     /**
95      * Convenience method for setting the current status code
96      * to starting.
97      */

98     public void setStarting()
99     {
100         mStatusCode = kInstanceStartingCode;
101         mStatusString = kInstanceStartingMsg;
102     }
103
104     /**
105      * Returns true if the status code is set to kInstanceStoppingCode,
106      * false otherwise.
107      */

108     public boolean isStopping()
109     {
110         return (mStatusCode == kInstanceStoppingCode);
111     }
112
113     /**
114      * Convenience method for setting the current status code
115      * to stopping.
116      */

117     public void setStopping()
118     {
119         mStatusCode = kInstanceStoppingCode;
120         mStatusString = kInstanceStoppingMsg;
121     }
122
123     /**
124      * Returns true if the status code is set to kInstanceNotRunning, false
125      * otherwise.
126      */

127     public boolean isNotRunning()
128     {
129         return (mStatusCode == Status.kInstanceNotRunningCode);
130     }
131
132     /**
133      * Convenience method for setting the current status code
134      * to not running.
135      */

136     public void setNotRunning()
137     {
138         mStatusCode = kInstanceNotRunningCode;
139         mStatusString = kInstanceNotRunningMsg;
140     }
141
142     /**
143      * Returns true if the instance is set to run in debug mode,
144      * false otherwise.
145      */

146     public boolean isDebug()
147     {
148         return mDebug;
149     }
150
151     /**
152      */

153     public void setDebug(boolean debug)
154     {
155         mDebug = debug;
156     }
157     
158     /**
159      * Returns the port on which JPDA port in admin-server JVM listens.
160      * Returns -1 in case the debug flag is not enabled.
161     */

162     public int getDebugPort()
163     {
164         return ( mDebugPort );
165     }
166     /**
167      * Sets the JPDA debugger port. This is the port to which the debuggers can
168      * connect in case the JVM is to be debugged.
169      * @param port integer representing port
170     */

171     public void setDebugPort(int port)
172     {
173         mDebugPort = port;
174     }
175
176     /**
177      * Set status code and string to appropriate values using specified status
178      * code. An IllegalArgumentException is thrown if status code is invalid
179      * for server instance.
180      */

181     private void setStatusCodeAndStr(int statusCode) {
182         switch (statusCode) {
183           case Status.kInstanceStartingCode:
184             this.mStatusCode = statusCode;
185             this.mStatusString = Status.kInstanceStartingMsg;
186             break;
187           case Status.kInstanceRunningCode:
188             this.mStatusCode = statusCode;
189             this.mStatusString = Status.kInstanceRunningMsg;
190             break;
191           case Status.kInstanceStoppingCode:
192             this.mStatusCode = statusCode;
193             this.mStatusString = Status.kInstanceStoppingMsg;
194             break;
195           case Status.kInstanceNotRunningCode:
196             this.mStatusCode = statusCode;
197             this.mStatusString = Status.kInstanceNotRunningMsg;
198             break;
199           default:
200             String JavaDoc msg = localizedStrMgr.getString( "admin.common.invalid_server_instance_status_code", new String JavaDoc( statusCode + "" ) );
201             throw new IllegalArgumentException JavaDoc( msg );
202         }
203     }
204 }
205
Popular Tags