KickJava   Java API By Example, From Geeks To Geeks.

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


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 LoadBalancerStats
26  * matches the schema element 'load-balancer-stats'.
27  *
28  * Generated on Fri Aug 19 00:43:43 IST 2005
29  *
30  * This class matches the root element of the DTD,
31  * and is the root of the bean graph.
32  *
33  * load-balancer-stats : LoadBalancerStats
34  * cluster-stats : ClusterStats[0,n]
35  * [attr: id CDATA #REQUIRED ]
36  * instance-stats : InstanceStats[0,n]
37  * [attr: id CDATA #REQUIRED ]
38  * [attr: health CDATA #REQUIRED ]
39  * [attr: num-total-requests CDATA #REQUIRED ]
40  * [attr: num-active-requests CDATA #REQUIRED ]
41  * application-stats : Boolean[0,n]
42  * [attr: id CDATA #REQUIRED ]
43  * [attr: average-response-time CDATA #REQUIRED ]
44  * [attr: min-response-time CDATA #REQUIRED ]
45  * [attr: max-response-time CDATA #REQUIRED ]
46  * [attr: num-failover-requests CDATA #REQUIRED ]
47  * [attr: num-error-requests CDATA #REQUIRED ]
48  * [attr: num-active-requests CDATA #REQUIRED ]
49  * [attr: num-idempotent-url-requests CDATA #REQUIRED ]
50  * [attr: num-total-requests CDATA #REQUIRED ]
51  * EMPTY : String
52  *
53  */

54
55 package com.sun.enterprise.admin.monitor.stats.lb;
56
57 public class LoadBalancerStats implements com.sun.enterprise.admin.monitor.stats.lb.LoadBalancerStatsInterface, com.sun.enterprise.admin.monitor.stats.lb.CommonBean {
58     private java.util.List JavaDoc _ClusterStats = new java.util.ArrayList JavaDoc(); // List<ClusterStats>
59

60     public LoadBalancerStats() {
61     }
62
63     // Deep copy
64
public LoadBalancerStats(com.sun.enterprise.admin.monitor.stats.lb.LoadBalancerStats source) {
65         for (java.util.Iterator JavaDoc it = source._ClusterStats.iterator();
66             it.hasNext(); ) {
67             _ClusterStats.add(new com.sun.enterprise.admin.monitor.stats.lb.ClusterStats((com.sun.enterprise.admin.monitor.stats.lb.ClusterStats)it.next()));
68         }
69     }
70
71     // This attribute is an array, possibly empty
72
public void setClusterStats(com.sun.enterprise.admin.monitor.stats.lb.ClusterStats[] value) {
73         if (value == null)
74             value = new ClusterStats[0];
75         _ClusterStats.clear();
76         for (int i = 0; i < value.length; ++i) {
77             _ClusterStats.add(value[i]);
78         }
79     }
80
81     public void setClusterStats(int index, com.sun.enterprise.admin.monitor.stats.lb.ClusterStats value) {
82         _ClusterStats.set(index, value);
83     }
84
85     public com.sun.enterprise.admin.monitor.stats.lb.ClusterStats[] getClusterStats() {
86         ClusterStats[] arr = new ClusterStats[_ClusterStats.size()];
87         return (ClusterStats[]) _ClusterStats.toArray(arr);
88     }
89
90     public java.util.List JavaDoc fetchClusterStatsList() {
91         return _ClusterStats;
92     }
93
94     public com.sun.enterprise.admin.monitor.stats.lb.ClusterStats getClusterStats(int index) {
95         return (ClusterStats)_ClusterStats.get(index);
96     }
97
98     // Return the number of clusterStats
99
public int sizeClusterStats() {
100         return _ClusterStats.size();
101     }
102
103     public int addClusterStats(com.sun.enterprise.admin.monitor.stats.lb.ClusterStats value) {
104         _ClusterStats.add(value);
105         return _ClusterStats.size()-1;
106     }
107
108     // Search from the end looking for @param value, and then remove it.
109
public int removeClusterStats(com.sun.enterprise.admin.monitor.stats.lb.ClusterStats value) {
110         int pos = _ClusterStats.indexOf(value);
111         if (pos >= 0) {
112             _ClusterStats.remove(pos);
113         }
114         return pos;
115     }
116
117     public void write(java.io.OutputStream JavaDoc out) throws java.io.IOException JavaDoc {
118         write(out, null);
119     }
120
121     public void write(java.io.OutputStream JavaDoc out, String JavaDoc encoding) throws java.io.IOException JavaDoc {
122         java.io.Writer JavaDoc w;
123         if (encoding == null) {
124             encoding = "UTF-8"; // NOI18N
125
}
126         w = new java.io.BufferedWriter JavaDoc(new java.io.OutputStreamWriter JavaDoc(out, encoding));
127         write(w, encoding);
128         w.flush();
129     }
130
131     // Print this Java Bean to @param out including an XML header.
132
// @param encoding is the encoding style that @param out was opened with.
133
public void write(java.io.Writer JavaDoc out, String JavaDoc encoding) throws java.io.IOException JavaDoc {
134         out.write("<?xml version='1.0'"); // NOI18N
135
if (encoding != null)
136             out.write(" encoding='"+encoding+"'"); // NOI18N
137
out.write(" ?>\n"); // NOI18N
138
writeNode(out, "load-balancer-stats", ""); // NOI18N
139
}
140
141     public void writeNode(java.io.Writer JavaDoc out, String JavaDoc nodeName, String JavaDoc indent) throws java.io.IOException JavaDoc {
142         out.write(indent);
143         out.write("<");
144         out.write(nodeName);
145         out.write(">\n");
146         String JavaDoc nextIndent = indent + " ";
147         for (java.util.Iterator JavaDoc it = _ClusterStats.iterator();
148             it.hasNext(); ) {
149             com.sun.enterprise.admin.monitor.stats.lb.ClusterStats element = (com.sun.enterprise.admin.monitor.stats.lb.ClusterStats)it.next();
150             if (element != null) {
151                 element.writeNode(out, "cluster-stats", nextIndent);
152             }
153         }
154         out.write(indent);
155         out.write("</"+nodeName+">\n");
156     }
157
158     public static LoadBalancerStats read(java.io.InputStream JavaDoc in) throws javax.xml.parsers.ParserConfigurationException JavaDoc, org.xml.sax.SAXException JavaDoc, java.io.IOException JavaDoc {
159         return read(new org.xml.sax.InputSource JavaDoc(in), false, null, null);
160     }
161
162     // Warning: in readNoEntityResolver character and entity references will
163
// not be read from any DTD in the XML source.
164
// However, this way is faster since no DTDs are looked up
165
// (possibly skipping network access) or parsed.
166
public static LoadBalancerStats readNoEntityResolver(java.io.InputStream JavaDoc in) throws javax.xml.parsers.ParserConfigurationException JavaDoc, org.xml.sax.SAXException JavaDoc, java.io.IOException JavaDoc {
167         return read(new org.xml.sax.InputSource JavaDoc(in), false,
168             new org.xml.sax.EntityResolver JavaDoc() {
169             public org.xml.sax.InputSource JavaDoc resolveEntity(String JavaDoc publicId, String JavaDoc systemId) {
170                 java.io.ByteArrayInputStream JavaDoc bin = new java.io.ByteArrayInputStream JavaDoc(new byte[0]);
171                 return new org.xml.sax.InputSource JavaDoc(bin);
172             }
173         }
174             , null);
175     }
176
177     public static LoadBalancerStats read(org.xml.sax.InputSource JavaDoc in, boolean validate, org.xml.sax.EntityResolver JavaDoc er, org.xml.sax.ErrorHandler JavaDoc eh) throws javax.xml.parsers.ParserConfigurationException JavaDoc, org.xml.sax.SAXException JavaDoc, java.io.IOException JavaDoc {
178         javax.xml.parsers.DocumentBuilderFactory JavaDoc dbf = javax.xml.parsers.DocumentBuilderFactory.newInstance();
179         dbf.setValidating(validate);
180         javax.xml.parsers.DocumentBuilder JavaDoc db = dbf.newDocumentBuilder();
181         if (er != null) db.setEntityResolver(er);
182         if (eh != null) db.setErrorHandler(eh);
183         org.w3c.dom.Document JavaDoc doc = db.parse(in);
184         return read(doc);
185     }
186
187     public static LoadBalancerStats read(org.w3c.dom.Document JavaDoc document) {
188         LoadBalancerStats aLoadBalancerStats = new LoadBalancerStats();
189         aLoadBalancerStats.readNode(document.getDocumentElement());
190         return aLoadBalancerStats;
191     }
192
193     public void readNode(org.w3c.dom.Node JavaDoc node) {
194         org.w3c.dom.NodeList JavaDoc children = node.getChildNodes();
195         for (int i = 0, size = children.getLength(); i < size; ++i) {
196             org.w3c.dom.Node JavaDoc childNode = children.item(i);
197             String JavaDoc childNodeName = (childNode.getLocalName() == null ? childNode.getNodeName().intern() : childNode.getLocalName().intern());
198             String JavaDoc childNodeValue = "";
199             if (childNode.getFirstChild() != null) {
200                 childNodeValue = childNode.getFirstChild().getNodeValue();
201             }
202             if (childNodeName == "cluster-stats") {
203                 ClusterStats aClusterStats = new com.sun.enterprise.admin.monitor.stats.lb.ClusterStats();
204                 aClusterStats.readNode(childNode);
205                 _ClusterStats.add(aClusterStats);
206             }
207             else {
208                 // Found extra unrecognized childNode
209
}
210         }
211     }
212
213     // Takes some text to be printed into an XML stream and escapes any
214
// characters that might make it invalid XML (like '<').
215
public static void writeXML(java.io.Writer JavaDoc out, String JavaDoc msg) throws java.io.IOException JavaDoc {
216         writeXML(out, msg, true);
217     }
218
219     public static void writeXML(java.io.Writer JavaDoc out, String JavaDoc msg, boolean attribute) throws java.io.IOException JavaDoc {
220         if (msg == null)
221             return;
222         int msgLength = msg.length();
223         for (int i = 0; i < msgLength; ++i) {
224             char c = msg.charAt(i);
225             writeXML(out, c, attribute);
226         }
227     }
228
229     public static void writeXML(java.io.Writer JavaDoc out, char msg, boolean attribute) throws java.io.IOException JavaDoc {
230         if (msg == '&')
231             out.write("&amp;");
232         else if (msg == '<')
233             out.write("&lt;");
234         else if (msg == '>')
235             out.write("&gt;");
236         else if (attribute && msg == '"')
237             out.write("&quot;");
238         else if (attribute && msg == '\'')
239             out.write("&apos;");
240         else if (attribute && msg == '\n')
241             out.write("&#xA;");
242         else if (attribute && msg == '\t')
243             out.write("&#x9;");
244         else
245             out.write(msg);
246     }
247
248     public static class ValidateException extends Exception JavaDoc {
249         private com.sun.enterprise.admin.monitor.stats.lb.CommonBean failedBean;
250         private String JavaDoc failedPropertyName;
251         public ValidateException(String JavaDoc msg, String JavaDoc failedPropertyName, com.sun.enterprise.admin.monitor.stats.lb.CommonBean failedBean) {
252             super(msg);
253             this.failedBean = failedBean;
254             this.failedPropertyName = failedPropertyName;
255         }
256         public String JavaDoc getFailedPropertyName() {return failedPropertyName;}
257         public com.sun.enterprise.admin.monitor.stats.lb.CommonBean getFailedBean() {return failedBean;}
258     }
259
260     public void validate() throws com.sun.enterprise.admin.monitor.stats.lb.LoadBalancerStats.ValidateException {
261         boolean restrictionFailure = false;
262         // Validating property clusterStats
263
for (int _index = 0; _index < sizeClusterStats(); ++_index) {
264             com.sun.enterprise.admin.monitor.stats.lb.ClusterStats element = getClusterStats(_index);
265             if (element != null) {
266                 element.validate();
267             }
268         }
269     }
270
271     public void changePropertyByName(String JavaDoc name, Object JavaDoc value) {
272         if (name == null) return;
273         name = name.intern();
274         if (name == "clusterStats")
275             addClusterStats((ClusterStats)value);
276         else if (name == "clusterStats[]")
277             setClusterStats((ClusterStats[]) value);
278         else
279             throw new IllegalArgumentException JavaDoc(name+" is not a valid property name for LoadBalancerStats");
280     }
281
282     public Object JavaDoc fetchPropertyByName(String JavaDoc name) {
283         if (name == "clusterStats[]")
284             return getClusterStats();
285         throw new IllegalArgumentException JavaDoc(name+" is not a valid property name for LoadBalancerStats");
286     }
287
288     // Return an array of all of the properties that are beans and are set.
289
public com.sun.enterprise.admin.monitor.stats.lb.CommonBean[] childBeans(boolean recursive) {
290         java.util.List JavaDoc children = new java.util.LinkedList JavaDoc();
291         childBeans(recursive, children);
292         com.sun.enterprise.admin.monitor.stats.lb.CommonBean[] result = new com.sun.enterprise.admin.monitor.stats.lb.CommonBean[children.size()];
293         return (com.sun.enterprise.admin.monitor.stats.lb.CommonBean[]) children.toArray(result);
294     }
295
296     // Put all child beans into the beans list.
297
public void childBeans(boolean recursive, java.util.List JavaDoc beans) {
298         for (java.util.Iterator JavaDoc it = _ClusterStats.iterator();
299             it.hasNext(); ) {
300             com.sun.enterprise.admin.monitor.stats.lb.ClusterStats element = (com.sun.enterprise.admin.monitor.stats.lb.ClusterStats)it.next();
301             if (element != null) {
302                 if (recursive) {
303                     element.childBeans(true, beans);
304                 }
305                 beans.add(element);
306             }
307         }
308     }
309
310     public boolean equals(Object JavaDoc o) {
311         if (o == this)
312             return true;
313         if (!(o instanceof com.sun.enterprise.admin.monitor.stats.lb.LoadBalancerStats))
314             return false;
315         com.sun.enterprise.admin.monitor.stats.lb.LoadBalancerStats inst = (com.sun.enterprise.admin.monitor.stats.lb.LoadBalancerStats) o;
316         if (sizeClusterStats() != inst.sizeClusterStats())
317             return false;
318         // Compare every element.
319
for (java.util.Iterator JavaDoc it = _ClusterStats.iterator(), it2 = inst._ClusterStats.iterator();
320             it.hasNext() && it2.hasNext(); ) {
321             com.sun.enterprise.admin.monitor.stats.lb.ClusterStats element = (com.sun.enterprise.admin.monitor.stats.lb.ClusterStats)it.next();
322             com.sun.enterprise.admin.monitor.stats.lb.ClusterStats element2 = (com.sun.enterprise.admin.monitor.stats.lb.ClusterStats)it2.next();
323             if (!(element == null ? element2 == null : element.equals(element2)))
324                 return false;
325         }
326         return true;
327     }
328
329     public int hashCode() {
330         int result = 17;
331         result = 37*result + (_ClusterStats == null ? 0 : _ClusterStats.hashCode());
332         return result;
333     }
334
335     public String JavaDoc toString() {
336         java.io.StringWriter JavaDoc sw = new java.io.StringWriter JavaDoc();
337         try {
338             writeNode(sw, "LoadBalancerStats", "");
339         } catch (java.io.IOException JavaDoc e) {
340             // How can we actually get an IOException on a StringWriter?
341
// We'll just ignore it.
342
}
343         return sw.toString();
344     }
345 }
346
347
348 /*
349         The following schema file has been used for generation:
350
351 <?xml version="1.0" encoding="UTF-8"?>
352
353 <!--
354     Document : sun_loadbalancer_stats_1_0.dtd.dtd
355     Created on : August 15, 2005, 3:22 PM
356     Author : hr124446
357     Description:
358         Purpose of the document follows.
359
360     TODO define vocabulary identification data
361     PUBLIC ID : -//Sun Microsystems Inc.//DTD Application Server 9.0 LoadBalancer Stats//EN
362     SYSTEM ID : http://www.sun.com/software/appserver/dtds/sun_loadbalancer_stats_1_0.dtd
363 -->
364
365 <!-- Root element for load balancer. It contains all the statistics -->
366    <!ELEMENT load-balancer-stats (cluster-stats*)>
367
368    <!--
369    Cluster Statistics
370      id Cluster name
371    -->
372
373    <!ELEMENT cluster-stats (instance-stats*)>
374    <!ATTLIST cluster-stats
375      id CDATA #REQUIRED>
376
377    <!--
378    Instance Statistics
379      id Server instance name
380      num-active-requests The number of active requests on this server.
381      num-total-requests The number of total requests on this server.
382    -->
383    <!ELEMENT instance-stats (application-stats*)>
384    <!ATTLIST instance-stats
385      id CDATA #REQUIRED
386      health CDATA #REQUIRED
387      num-total-requests CDATA #REQUIRED
388      num-active-requests CDATA #REQUIRED>
389
390    <!--
391    Application Statistics
392      id web module or web service endpoint's uri.
393      average-response-time Average response time in milli seconds.
394      min-response-time Minimum response time observed in milli seconds.
395      max-response-time Maximum response time observed in milli seconds.
396      num-failover-requests The number of failed-over requests for this context root.
397      num-error-requests The number of failed requests for this context root.
398      num-active-requests The number of active requests for this context root.
399      num-total-requests The number of total requests for this context root.
400      num-idempotent-url-requests The number of times all the idempotent urls in
401     this application are accessesd.
402    -->
403    <!ELEMENT application-stats EMPTY>
404    <!ATTLIST application-stats
405      id CDATA #REQUIRED
406      average-response-time CDATA #REQUIRED
407      min-response-time CDATA #REQUIRED
408      max-response-time CDATA #REQUIRED
409      num-failover-requests CDATA #REQUIRED
410      num-error-requests CDATA #REQUIRED
411      num-active-requests CDATA #REQUIRED
412      num-idempotent-url-requests CDATA #REQUIRED
413      num-total-requests CDATA #REQUIRED>
414
415
416 */

417
Popular Tags