KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > ejb > base > stats > EJBMethodStatsImpl


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.CountStatistic JavaDoc;
27 import javax.management.j2ee.statistics.TimeStatistic JavaDoc;
28 import javax.management.j2ee.statistics.BoundedRangeStatistic JavaDoc;
29
30 import com.sun.enterprise.admin.monitor.stats.EJBCacheStats;
31 import com.sun.enterprise.admin.monitor.stats.CountStatisticImpl;
32 import com.sun.enterprise.admin.monitor.stats.MutableCountStatisticImpl;
33 import com.sun.enterprise.admin.monitor.stats.TimeStatisticImpl;
34 import com.sun.enterprise.admin.monitor.stats.MutableTimeStatisticImpl;
35
36 import com.sun.enterprise.admin.monitor.registry.MonitoringRegistry;
37 import com.sun.enterprise.admin.monitor.registry.MonitoringLevelListener;
38 import com.sun.enterprise.admin.monitor.registry.MonitoringLevel;
39 import com.sun.enterprise.admin.monitor.registry.MonitoringRegistrationException;
40
41 import java.util.logging.*;
42 import com.sun.enterprise.log.Log;
43 import com.sun.logging.*;
44
45
46 /**
47  * A Class for providing stats for Bean Methods
48  * Used by both Entity, Stateless and Stateful Container
49  *
50  * @author Mahesh Kannan
51  */

52
53 public class EJBMethodStatsImpl
54     extends StatsImpl
55     implements com.sun.enterprise.admin.monitor.stats.EJBMethodStats
56 {
57     private MethodMonitor delegate;
58
59     private MethodMonitor methodMonitor;
60
61     private MutableCountStatisticImpl executionStat;
62     private MutableCountStatisticImpl errorStat;
63     private MutableTimeStatisticImpl methodStat;
64     private MutableCountStatisticImpl successStat;
65
66     public EJBMethodStatsImpl(MethodMonitor delegate) {
67     this.delegate = delegate;
68
69     initialize();
70     }
71
72     private void initialize() {
73     super.initialize("com.sun.enterprise.admin.monitor.stats.EJBMethodStats");
74
75     executionStat = new MutableCountStatisticImpl(
76         new CountStatisticImpl("ExecutionTime", "Milliseconds" ));
77     errorStat = new MutableCountStatisticImpl(
78         new CountStatisticImpl("TotalNumErrors"));
79
80     long now = System.currentTimeMillis();
81     methodStat = new MutableTimeStatisticImpl(
82         new TimeStatisticImpl(0, 0, 0, 0,
83             "MethodStatistic", "", "", now, now));
84     successStat = new MutableCountStatisticImpl(
85         new CountStatisticImpl("TotalNumSuccess"));
86
87     delegate.setMutableTimeStatisticImpl(methodStat);
88     }
89
90     public CountStatistic JavaDoc getExecutionTime() {
91     executionStat.setCount(delegate.getExecutionTime());
92     return (CountStatistic JavaDoc) executionStat.modifiableView();
93     }
94
95     public CountStatistic JavaDoc getTotalNumErrors() {
96     errorStat.setCount(delegate.getTotalNumErrors());
97     return (CountStatistic JavaDoc) errorStat.modifiableView();
98     }
99
100     public TimeStatistic JavaDoc getMethodStatistic() {
101     return (TimeStatistic JavaDoc) methodStat.modifiableView();
102     }
103
104     public CountStatistic JavaDoc getTotalNumSuccess() {
105     successStat.setCount(delegate.getTotalNumSuccess());
106     return (CountStatistic JavaDoc) successStat.modifiableView();
107     }
108
109     protected void resetAllStats() {
110     //Implementations must override this to reset stat values
111

112     executionStat.reset();
113     errorStat.reset();
114     synchronized (methodStat) {
115         methodStat.reset();
116     }
117     successStat.reset();
118
119     delegate.resetAllStats(monitorOn);
120     }
121
122 }
123
Popular Tags