KickJava   Java API By Example, From Geeks To Geeks.

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

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