KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > admin > monitor > stats > lb > ClusterStats


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  * This generated bean class ClusterStats
26  * matches the schema element 'cluster-stats'.
27  *
28  * Generated on Fri Aug 19 00:43:43 IST 2005
29  */

30
31 package com.sun.enterprise.admin.monitor.stats.lb;
32
33 public class ClusterStats implements com.sun.enterprise.admin.monitor.stats.lb.ClusterStatsInterface, com.sun.enterprise.admin.monitor.stats.lb.CommonBean {
34     private java.lang.String JavaDoc _Id;
35     private java.util.List JavaDoc _InstanceStats = new java.util.ArrayList JavaDoc(); // List<InstanceStats>
36

37     public ClusterStats() {
38         _Id = "";
39     }
40
41     // Deep copy
42
public ClusterStats(com.sun.enterprise.admin.monitor.stats.lb.ClusterStats source) {
43         _Id = source._Id;
44         for (java.util.Iterator JavaDoc it = source._InstanceStats.iterator();
45             it.hasNext(); ) {
46             _InstanceStats.add(new com.sun.enterprise.admin.monitor.stats.lb.InstanceStats((com.sun.enterprise.admin.monitor.stats.lb.InstanceStats)it.next()));
47         }
48     }
49
50     // This attribute is mandatory
51
public void setId(java.lang.String JavaDoc value) {
52         _Id = value;
53     }
54
55     public java.lang.String JavaDoc getId() {
56         return _Id;
57     }
58
59     // This attribute is an array, possibly empty
60
public void setInstanceStats(com.sun.enterprise.admin.monitor.stats.lb.InstanceStats[] value) {
61         if (value == null)
62             value = new InstanceStats[0];
63         _InstanceStats.clear();
64         for (int i = 0; i < value.length; ++i) {
65             _InstanceStats.add(value[i]);
66         }
67     }
68
69     public void setInstanceStats(int index, com.sun.enterprise.admin.monitor.stats.lb.InstanceStats value) {
70         _InstanceStats.set(index, value);
71     }
72
73     public com.sun.enterprise.admin.monitor.stats.lb.InstanceStats[] getInstanceStats() {
74         InstanceStats[] arr = new InstanceStats[_InstanceStats.size()];
75         return (InstanceStats[]) _InstanceStats.toArray(arr);
76     }
77
78     public java.util.List JavaDoc fetchInstanceStatsList() {
79         return _InstanceStats;
80     }
81
82     public com.sun.enterprise.admin.monitor.stats.lb.InstanceStats getInstanceStats(int index) {
83         return (InstanceStats)_InstanceStats.get(index);
84     }
85
86     // Return the number of instanceStats
87
public int sizeInstanceStats() {
88         return _InstanceStats.size();
89     }
90
91     public int addInstanceStats(com.sun.enterprise.admin.monitor.stats.lb.InstanceStats value) {
92         _InstanceStats.add(value);
93         return _InstanceStats.size()-1;
94     }
95
96     // Search from the end looking for @param value, and then remove it.
97
public int removeInstanceStats(com.sun.enterprise.admin.monitor.stats.lb.InstanceStats value) {
98         int pos = _InstanceStats.indexOf(value);
99         if (pos >= 0) {
100             _InstanceStats.remove(pos);
101         }
102         return pos;
103     }
104
105     public void writeNode(java.io.Writer JavaDoc out, String JavaDoc nodeName, String JavaDoc indent) throws java.io.IOException JavaDoc {
106         out.write(indent);
107         out.write("<");
108         out.write(nodeName);
109         // id is an attribute
110
if (_Id != null) {
111             out.write(" id"); // NOI18N
112
out.write("='"); // NOI18N
113
com.sun.enterprise.admin.monitor.stats.lb.LoadBalancerStats.writeXML(out, _Id, true);
114             out.write("'"); // NOI18N
115
}
116         out.write(">\n");
117         String JavaDoc nextIndent = indent + " ";
118         for (java.util.Iterator JavaDoc it = _InstanceStats.iterator();
119             it.hasNext(); ) {
120             com.sun.enterprise.admin.monitor.stats.lb.InstanceStats element = (com.sun.enterprise.admin.monitor.stats.lb.InstanceStats)it.next();
121             if (element != null) {
122                 element.writeNode(out, "instance-stats", nextIndent);
123             }
124         }
125         out.write(indent);
126         out.write("</"+nodeName+">\n");
127     }
128
129     public void readNode(org.w3c.dom.Node JavaDoc node) {
130         if (node.hasAttributes()) {
131             org.w3c.dom.NamedNodeMap JavaDoc attrs = node.getAttributes();
132             org.w3c.dom.Attr JavaDoc attr;
133             attr = (org.w3c.dom.Attr JavaDoc) attrs.getNamedItem("id");
134             if (attr != null) {
135                 _Id = attr.getValue();
136             }
137         }
138         org.w3c.dom.NodeList JavaDoc children = node.getChildNodes();
139         for (int i = 0, size = children.getLength(); i < size; ++i) {
140             org.w3c.dom.Node JavaDoc childNode = children.item(i);
141             String JavaDoc childNodeName = (childNode.getLocalName() == null ? childNode.getNodeName().intern() : childNode.getLocalName().intern());
142             String JavaDoc childNodeValue = "";
143             if (childNode.getFirstChild() != null) {
144                 childNodeValue = childNode.getFirstChild().getNodeValue();
145             }
146             if (childNodeName == "instance-stats") {
147                 InstanceStats aInstanceStats = new com.sun.enterprise.admin.monitor.stats.lb.InstanceStats();
148                 aInstanceStats.readNode(childNode);
149                 _InstanceStats.add(aInstanceStats);
150             }
151             else {
152                 // Found extra unrecognized childNode
153
}
154         }
155     }
156
157     public void validate() throws com.sun.enterprise.admin.monitor.stats.lb.LoadBalancerStats.ValidateException {
158         boolean restrictionFailure = false;
159         // Validating property id
160
if (getId() == null) {
161             throw new com.sun.enterprise.admin.monitor.stats.lb.LoadBalancerStats.ValidateException("getId() == null", "id", this); // NOI18N
162
}
163         // Validating property instanceStats
164
for (int _index = 0; _index < sizeInstanceStats(); ++_index) {
165             com.sun.enterprise.admin.monitor.stats.lb.InstanceStats element = getInstanceStats(_index);
166             if (element != null) {
167                 element.validate();
168             }
169         }
170     }
171
172     public void changePropertyByName(String JavaDoc name, Object JavaDoc value) {
173         if (name == null) return;
174         name = name.intern();
175         if (name == "id")
176             setId((java.lang.String JavaDoc)value);
177         else if (name == "instanceStats")
178             addInstanceStats((InstanceStats)value);
179         else if (name == "instanceStats[]")
180             setInstanceStats((InstanceStats[]) value);
181         else
182             throw new IllegalArgumentException JavaDoc(name+" is not a valid property name for ClusterStats");
183     }
184
185     public Object JavaDoc fetchPropertyByName(String JavaDoc name) {
186         if (name == "id")
187             return getId();
188         if (name == "instanceStats[]")
189             return getInstanceStats();
190         throw new IllegalArgumentException JavaDoc(name+" is not a valid property name for ClusterStats");
191     }
192
193     // Return an array of all of the properties that are beans and are set.
194
public com.sun.enterprise.admin.monitor.stats.lb.CommonBean[] childBeans(boolean recursive) {
195         java.util.List JavaDoc children = new java.util.LinkedList JavaDoc();
196         childBeans(recursive, children);
197         com.sun.enterprise.admin.monitor.stats.lb.CommonBean[] result = new com.sun.enterprise.admin.monitor.stats.lb.CommonBean[children.size()];
198         return (com.sun.enterprise.admin.monitor.stats.lb.CommonBean[]) children.toArray(result);
199     }
200
201     // Put all child beans into the beans list.
202
public void childBeans(boolean recursive, java.util.List JavaDoc beans) {
203         for (java.util.Iterator JavaDoc it = _InstanceStats.iterator();
204             it.hasNext(); ) {
205             com.sun.enterprise.admin.monitor.stats.lb.InstanceStats element = (com.sun.enterprise.admin.monitor.stats.lb.InstanceStats)it.next();
206             if (element != null) {
207                 if (recursive) {
208                     element.childBeans(true, beans);
209                 }
210                 beans.add(element);
211             }
212         }
213     }
214
215     public boolean equals(Object JavaDoc o) {
216         if (o == this)
217             return true;
218         if (!(o instanceof com.sun.enterprise.admin.monitor.stats.lb.ClusterStats))
219             return false;
220         com.sun.enterprise.admin.monitor.stats.lb.ClusterStats inst = (com.sun.enterprise.admin.monitor.stats.lb.ClusterStats) o;
221         if (!(_Id == null ? inst._Id == null : _Id.equals(inst._Id)))
222             return false;
223         if (sizeInstanceStats() != inst.sizeInstanceStats())
224             return false;
225         // Compare every element.
226
for (java.util.Iterator JavaDoc it = _InstanceStats.iterator(), it2 = inst._InstanceStats.iterator();
227             it.hasNext() && it2.hasNext(); ) {
228             com.sun.enterprise.admin.monitor.stats.lb.InstanceStats element = (com.sun.enterprise.admin.monitor.stats.lb.InstanceStats)it.next();
229             com.sun.enterprise.admin.monitor.stats.lb.InstanceStats element2 = (com.sun.enterprise.admin.monitor.stats.lb.InstanceStats)it2.next();
230             if (!(element == null ? element2 == null : element.equals(element2)))
231                 return false;
232         }
233         return true;
234     }
235
236     public int hashCode() {
237         int result = 17;
238         result = 37*result + (_Id == null ? 0 : _Id.hashCode());
239         result = 37*result + (_InstanceStats == null ? 0 : _InstanceStats.hashCode());
240         return result;
241     }
242
243     public String JavaDoc toString() {
244         java.io.StringWriter JavaDoc sw = new java.io.StringWriter JavaDoc();
245         try {
246             writeNode(sw, "ClusterStats", "");
247         } catch (java.io.IOException JavaDoc e) {
248             // How can we actually get an IOException on a StringWriter?
249
// We'll just ignore it.
250
}
251         return sw.toString();
252     }
253 }
254
255
256 /*
257         The following schema file has been used for generation:
258
259 <?xml version="1.0" encoding="UTF-8"?>
260
261 <!--
262     Document : sun_loadbalancer_stats_1_0.dtd.dtd
263     Created on : August 15, 2005, 3:22 PM
264     Author : hr124446
265     Description:
266         Purpose of the document follows.
267
268     TODO define vocabulary identification data
269     PUBLIC ID : -//Sun Microsystems Inc.//DTD Application Server 9.0 LoadBalancer Stats//EN
270     SYSTEM ID : http://www.sun.com/software/appserver/dtds/sun_loadbalancer_stats_1_0.dtd
271 -->
272
273 <!-- Root element for load balancer. It contains all the statistics -->
274    <!ELEMENT load-balancer-stats (cluster-stats*)>
275
276    <!--
277    Cluster Statistics
278      id Cluster name
279    -->
280
281    <!ELEMENT cluster-stats (instance-stats*)>
282    <!ATTLIST cluster-stats
283      id CDATA #REQUIRED>
284
285    <!--
286    Instance Statistics
287      id Server instance name
288      num-active-requests The number of active requests on this server.
289      num-total-requests The number of total requests on this server.
290    -->
291    <!ELEMENT instance-stats (application-stats*)>
292    <!ATTLIST instance-stats
293      id CDATA #REQUIRED
294      health CDATA #REQUIRED
295      num-total-requests CDATA #REQUIRED
296      num-active-requests CDATA #REQUIRED>
297
298    <!--
299    Application Statistics
300      id web module or web service endpoint's uri.
301      average-response-time Average response time in milli seconds.
302      min-response-time Minimum response time observed in milli seconds.
303      max-response-time Maximum response time observed in milli seconds.
304      num-failover-requests The number of failed-over requests for this context root.
305      num-error-requests The number of failed requests for this context root.
306      num-active-requests The number of active requests for this context root.
307      num-total-requests The number of total requests for this context root.
308      num-idempotent-url-requests The number of times all the idempotent urls in
309     this application are accessesd.
310    -->
311    <!ELEMENT application-stats EMPTY>
312    <!ATTLIST application-stats
313      id CDATA #REQUIRED
314      average-response-time CDATA #REQUIRED
315      min-response-time CDATA #REQUIRED
316      max-response-time CDATA #REQUIRED
317      num-failover-requests CDATA #REQUIRED
318      num-error-requests CDATA #REQUIRED
319      num-active-requests CDATA #REQUIRED
320      num-idempotent-url-requests CDATA #REQUIRED
321      num-total-requests CDATA #REQUIRED>
322
323
324 */

325
Popular Tags