KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > admin > servermgmt > RuntimeStatus


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 /*
25  * RuntimeStatus.java
26  *
27  * Created on February 27, 2004, 12:26 PM
28  */

29
30 package com.sun.enterprise.admin.servermgmt;
31
32 import com.sun.enterprise.admin.common.Status;
33
34 import com.sun.enterprise.server.logging.FileandSyslogHandler;
35 import com.sun.enterprise.admin.servermgmt.InstancesManager;
36 import com.sun.enterprise.admin.servermgmt.InstanceException;
37
38 import java.io.Serializable JavaDoc;
39 import java.util.Vector JavaDoc;
40 import com.sun.enterprise.util.LocalStrings;
41 import com.sun.enterprise.util.LocalStringsImpl;
42
43 /**
44  *
45  * @author kebbs
46  */

47 public class RuntimeStatus implements Serializable JavaDoc {
48        
49     private boolean _restartNeeded;
50     private Status _status;
51     private Vector JavaDoc _recentErrorMessages;
52     private String JavaDoc _name;
53     
54     public static RuntimeStatus getRuntimeStatus(
55         String JavaDoc name,
56         InstancesManager manager) throws InstanceException
57     {
58         int status = manager.getInstanceStatus();
59         return new RuntimeStatus(name, manager.isRestartNeeded(),
60             new Status(status, Status.getStatusString(status)),
61             FileandSyslogHandler.getRecentErrorMessages());
62     }
63
64     public static void clearRuntimeStatus()
65     {
66         FileandSyslogHandler.clearRecentErrorMessages();
67     }
68     
69     public RuntimeStatus() {
70         this ("", true, new Status(Status.kInstanceNotRunningCode,
71             Status.kInstanceNotRunningMsg), new Vector JavaDoc());
72     }
73     
74     public RuntimeStatus(String JavaDoc name) {
75         this();
76         _name = name;
77     }
78     
79     public RuntimeStatus(String JavaDoc name, boolean restartNeeded,
80         Status status, Vector JavaDoc recentErrors)
81     {
82         _name = name;
83         _restartNeeded = restartNeeded;
84         _status = status;
85         _recentErrorMessages = recentErrors;
86     }
87     
88     public boolean isRestartNeeded()
89     {
90         return _restartNeeded;
91     }
92     
93     public String JavaDoc getName()
94     {
95         return _name;
96     }
97     
98     public void setStatus(Status status)
99     {
100         _status = status;
101     }
102     
103     public Status getStatus()
104     {
105         return _status;
106     }
107     
108     public Vector JavaDoc getRecentErrorMessages()
109     {
110         return _recentErrorMessages;
111     }
112     
113     
114     public boolean isRunning()
115     {
116         return getStatus().getStatusCode() == Status.kInstanceRunningCode ? true : false;
117     }
118     
119     public boolean isStopped()
120     {
121         return getStatus().getStatusCode() == Status.kInstanceNotRunningCode ? true : false;
122     }
123     
124     public String JavaDoc toShortString()
125     {
126         String JavaDoc result = getStatus().getStatusString();
127         if (isRunning()) {
128             if (isRestartNeeded()) {
129                 result = LocalStrings.get("requiresRestartYes");
130             }
131         }
132         return result;
133     }
134     
135     public String JavaDoc toString()
136     {
137         LocalStringsImpl stringy = new LocalStringsImpl();
138         String JavaDoc result = stringy.get("runtimeStatusToString", getName(), getStatus().getStatusString());
139         if (isRestartNeeded()) {
140             result += ", " + stringy.get("requiresRestartYes");
141         } else {
142             result += ", " + stringy.get("requiresRestartNo");
143         }
144         
145         Vector JavaDoc messages = getRecentErrorMessages();
146         for (int i = 0; i < messages.size(); i++) {
147             result += "\n" + stringy.get("error") + " " + i + " " + (String JavaDoc)messages.get(i);
148         }
149
150         return result;
151     }
152     
153 }
154     
155
Popular Tags