KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > admin > wsmgmt > stats > impl > StatsImpl


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 package com.sun.enterprise.admin.wsmgmt.stats.impl;
24
25 import javax.management.j2ee.statistics.Stats JavaDoc;
26 import javax.management.j2ee.statistics.Statistic JavaDoc;
27 import javax.management.j2ee.statistics.CountStatistic JavaDoc;
28 import javax.management.j2ee.statistics.BoundedRangeStatistic JavaDoc;
29
30 import com.sun.enterprise.admin.monitor.registry.MonitoringRegistry;
31 import com.sun.enterprise.admin.monitor.registry.MonitoringLevelListener;
32 import com.sun.enterprise.admin.monitor.registry.MonitoringLevel;
33 import com.sun.enterprise.admin.monitor.registry.MonitoringRegistrationException;
34
35 import com.sun.enterprise.server.ApplicationServer;
36
37 import com.sun.enterprise.admin.monitor.stats.GenericStatsImpl;
38
39 import java.util.logging.Logger JavaDoc;
40 import com.sun.enterprise.log.Log;
41 import com.sun.logging.LogDomains;
42
43 /**
44  * Base class for all the StatsImpl. Also provides a couple
45  * of methods for MonitorListener
46  *
47  * @author Satish Viswanatham
48  */

49 public abstract class StatsImpl
50     implements Stats JavaDoc
51 {
52     protected static Logger JavaDoc _logger =
53         LogDomains.getLogger(LogDomains.EJB_LOGGER);
54
55     private GenericStatsImpl genericStatsDelegate;
56     protected boolean monitorOn = false;
57     protected boolean registered = true;
58     private MonitoringLevel currentMonitoringLevel;
59
60     protected StatsImpl() {
61     }
62     
63     protected void initialize(String JavaDoc statInterfaceName) {
64     try {
65         genericStatsDelegate = new GenericStatsImpl(statInterfaceName, this);
66     } catch(ClassNotFoundException JavaDoc cnfEx) {
67         throw new RuntimeException JavaDoc(statInterfaceName + " not found", cnfEx);
68     }
69     }
70
71     public Statistic JavaDoc getStatistic(String JavaDoc statName) {
72     return genericStatsDelegate.getStatistic(statName);
73     }
74
75     public String JavaDoc[] getStatisticNames() {
76     return genericStatsDelegate.getStatisticNames();
77     }
78
79     public Statistic JavaDoc[] getStatistics() {
80     return genericStatsDelegate.getStatistics();
81     }
82
83     public String JavaDoc statToString() {
84     StringBuffer JavaDoc sbuf = new StringBuffer JavaDoc();
85     Statistic JavaDoc[] stats = getStatistics();
86     int sz = stats.length;
87     for (int i=0; i<sz; i++) {
88         if (stats[i] instanceof CountStatistic JavaDoc) {
89         CountStatistic JavaDoc stat = (CountStatistic JavaDoc) stats[i];
90         sbuf.append(stat.getName()).append("=")
91             .append(stat.getCount()).append("; ");
92         } else if (stats[i] instanceof BoundedRangeStatistic JavaDoc) {
93         BoundedRangeStatistic JavaDoc stat = (BoundedRangeStatistic JavaDoc) stats[i];
94         sbuf.append(stat.getName()).append("=")
95             .append(stat.getCurrent()).append("; ");
96         } else {
97         sbuf.append(stats[i].getName()).append("=?");
98         }
99     }
100
101     return sbuf.toString();
102     }
103 }
104
Popular Tags