KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > connectors > work > monitor > ConnectorWorkMgmtStatsImpl


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.enterprise.connectors.work.monitor;
25
26 import com.sun.enterprise.admin.monitor.stats.ConnectorWorkMgmtStats;
27 import com.sun.enterprise.admin.monitor.stats.CountStatisticImpl;
28 import com.sun.enterprise.admin.monitor.stats.GenericStatsImpl;
29 import com.sun.enterprise.admin.monitor.stats.MutableCountStatistic;
30 import com.sun.enterprise.admin.monitor.stats.MutableCountStatisticImpl;
31 import com.sun.enterprise.admin.monitor.stats.RangeStatisticImpl;
32 import com.sun.enterprise.connectors.ActiveInboundResourceAdapter;
33 import com.sun.enterprise.resource.monitor.AbstractStatsImpl;
34
35 import com.sun.logging.LogDomains;
36
37 import java.util.logging.Level JavaDoc;
38 import java.util.logging.Logger JavaDoc;
39
40 import javax.management.j2ee.statistics.CountStatistic JavaDoc;
41 import javax.management.j2ee.statistics.RangeStatistic JavaDoc;
42
43 /**
44  * This class provides an implementation of the JDBCConnectionPoolStats
45  * interface. The implementations of the interface methods primarily delegate the
46  * task of statistic gathering to the work-manager of the inbound resource
47  * adapter
48  * @author Sivakumar Thyagarajan
49  */

50 public class ConnectorWorkMgmtStatsImpl extends AbstractStatsImpl
51                                         implements ConnectorWorkMgmtStats {
52
53     private static Logger JavaDoc _logger =
54                 LogDomains.getLogger( LogDomains.RSR_LOGGER );
55     private GenericStatsImpl gsImpl;
56     
57     private RangeStatistic JavaDoc activeWorkCount;
58     private RangeStatistic JavaDoc waitQueueLength;
59     private RangeStatistic JavaDoc workRequestWaitTime;
60     private MutableCountStatistic submittedWorkCount;
61     private MutableCountStatistic rejectedWorkCount;
62     private MutableCountStatistic completedWorkCount;
63     private MonitorableWorkManager workManager;
64     
65     public ConnectorWorkMgmtStatsImpl( ActiveInboundResourceAdapter inboundRA ) {
66         this.workManager = (MonitorableWorkManager)inboundRA.
67                                     getBootStrapContext().getWorkManager();
68         initializeStatistics();
69         try {
70             gsImpl = new GenericStatsImpl(
71             this.getClass().getInterfaces()[0].getName(), this );
72             } catch( ClassNotFoundException JavaDoc cnfe ) {
73             //@todo:add to reosurces file
74
_logger.log( Level.INFO, "workmgmtmon.cnfe", "GenericStatsImpl" );
75             }
76     }
77     
78
79     private void initializeStatistics() {
80         long time = System.currentTimeMillis();
81         CountStatistic cs = null;
82     
83         cs = new CountStatisticImpl(0,
84             "SubmittedWorkCount", "",
85         "Number of work objects submitted by a connector module for execution"
86         + "WorkQueue before executing",time, time);
87         submittedWorkCount = new MutableCountStatisticImpl( cs );
88
89         cs = new CountStatisticImpl(0,
90             "RejectedWorkCount", "",
91         "Number of work objects rejected by the application server",time, time);
92         rejectedWorkCount = new MutableCountStatisticImpl( cs );
93
94         cs = new CountStatisticImpl(0,
95             "CompletedWorkCount", "",
96         "Number of work objects completed execution",time, time);
97         completedWorkCount = new MutableCountStatisticImpl( cs );
98
99         //the low water mark is set with a seed value of 1 to
100
//ensure that the comparison with currentVal returns
101
//the correct low water mark the first time around
102
//the least number of connections that we can use is always 1
103
activeWorkCount = new RangeStatisticImpl(0, 0,
104             1, "ActiveWorkCount", "",
105         "Number of active work objects",
106         time, time);
107
108         waitQueueLength = new RangeStatisticImpl(0, 0,
109             1, "WaitQueueLength", "",
110         "Number of work objects waiting in the queue for execution",
111         time, time);
112
113         workRequestWaitTime = new RangeStatisticImpl(0, 0,
114                         1, "workRequestWaitTime", "",
115                     "Number of work objects waiting in the queue for execution",
116                     time, time);
117     }
118
119     public RangeStatistic JavaDoc getActiveWorkCount() {
120         activeWorkCount = getUpdatedRangeStatistic(activeWorkCount,
121                         workManager.getCurrentActiveWorkCount(),
122                         workManager.getMaxActiveWorkCount(),
123                         workManager.getMinActiveWorkCount());
124         return activeWorkCount;
125     }
126
127     public RangeStatistic JavaDoc getWaitQueueLength() {
128         waitQueueLength = getUpdatedRangeStatistic(waitQueueLength, 0,
129                         workManager.getMaxWaitQueueLength(),
130                         workManager.getMinWaitQueueLength());
131         return waitQueueLength;
132     }
133     
134     public RangeStatistic JavaDoc getWorkRequestWaitTime() {
135         workRequestWaitTime = getUpdatedRangeStatistic(workRequestWaitTime, 0,
136                         workManager.getMaxWorkRequestWaitTime(),
137                         workManager.getMinWorkRequestWaitTime());
138         return workRequestWaitTime;
139     }
140
141     public CountStatistic getSubmittedWorkCount() {
142         submittedWorkCount.setCount( workManager.getSubmittedWorkCount());
143         return (CountStatistic) submittedWorkCount.unmodifiableView();
144     }
145
146     public CountStatistic getRejectedWorkCount() {
147         rejectedWorkCount.setCount( workManager.getRejectedWorkCount());
148         return (CountStatistic) rejectedWorkCount.unmodifiableView();
149     }
150
151     public CountStatistic getCompletedWorkCount() {
152         completedWorkCount.setCount( workManager.getCompletedWorkCount());
153         return (CountStatistic) completedWorkCount.unmodifiableView();
154     }
155 }
156
Popular Tags