KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.io.Serializable JavaDoc;
35 import java.util.ArrayList JavaDoc;
36
37 /**
38  * This class holds a list of runtime status objects which corresponds to a list of server
39  * instances (e.g. in a cluster) or a list of node agents.
40  * @author kebbs
41  */

42 public class RuntimeStatusList extends ArrayList JavaDoc implements Serializable JavaDoc {
43        
44     public RuntimeStatusList() {
45         super();
46     }
47         
48     public RuntimeStatusList(int capacity)
49     {
50         super(capacity);
51     }
52     
53     /**
54      * Return the RuntimeStatus at the specified index
55      * @param index
56      * @throws IndexOutOfBoundsException
57      * @return
58      */

59     public RuntimeStatus getStatus(int index) throws IndexOutOfBoundsException JavaDoc
60     {
61         return (RuntimeStatus)super.get(index);
62     }
63     
64     
65     /**
66      *
67      * @return true if at least one of the servers / node agents in the list is in a running state.
68      */

69     public boolean anyRunning()
70     {
71         return numRunning() > 0 ? true : false;
72     }
73     
74     /**
75      *
76      * @return true if all of the server or node agents in the list is in a running state.
77      * Note that there must be at least one server or node agent in the list.
78      */

79     public boolean allRunning()
80     {
81         if (isEmpty()) {
82             return false;
83         } else {
84             return numRunning() == size() ? true : false;
85         }
86     }
87        
88     /**
89      *
90      * @return the number of running instances / node agents.
91      */

92     public int numRunning()
93     {
94         int count = 0;
95         for (int i = 0; i < size(); i++) {
96             if (((RuntimeStatus)get(i)).isRunning()) {
97                 count++;
98             }
99         }
100         return count;
101     }
102     
103     /**
104      *
105      * @return the number of instances / node agents needing a restart. Note that
106      * stopped instances (i.e. not running) will not be counted.
107      */

108     public int numNeedingRestart()
109     {
110         int count = 0;
111         for (int i = 0; i < size(); i++) {
112             //Only running instances are considered for restart required
113
if (((RuntimeStatus)get(i)).isRunning() &&
114                 ((RuntimeStatus)get(i)).isRestartNeeded())
115             {
116                 count++;
117             }
118         }
119         return count;
120     }
121         
122     /**
123      *
124      * @return the number of stopped (not running) server instances
125      */

126     public int numStopped()
127     {
128         return size() - numRunning();
129     }
130     
131     /**
132      *
133      * @return true if there are no instances / agents in the list
134      */

135     public boolean isEmpty()
136     {
137         return size() == 0 ? true : false;
138     }
139     
140     
141     /**
142      *
143      * @return a string version of the list which can be: "running" if allRunning(),
144      * "partially running" if anyRunning(), or "stopped" everywhere else.
145      */

146     public String JavaDoc toString()
147     {
148        if (allRunning()) {
149            return Status.getStatusString(Status.kInstanceRunningCode);
150        } else if (anyRunning()) {
151            return Status.getStatusString(Status.kClusterPartiallyRunningCode);
152        } else {
153            return Status.getStatusString(Status.kInstanceNotRunningCode);
154        }
155     }
156 }
157     
158
Popular Tags