KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > iiop > ThreadPoolStatsImpl


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.iiop;
25
26 import java.util.Iterator JavaDoc;
27
28 import javax.management.j2ee.statistics.CountStatistic JavaDoc;
29 import javax.management.j2ee.statistics.BoundedRangeStatistic JavaDoc;
30 import javax.management.j2ee.statistics.RangeStatistic JavaDoc;
31
32 import com.sun.enterprise.admin.monitor.stats.BoundedRangeStatisticImpl;
33 import com.sun.enterprise.admin.monitor.stats.CountStatisticImpl;
34 import com.sun.enterprise.admin.monitor.stats.ThreadPoolStats;
35 import com.sun.enterprise.admin.monitor.stats.MutableCountStatisticImpl;
36 import com.sun.enterprise.admin.monitor.stats.MutableBoundedRangeStatisticImpl;
37 import com.sun.enterprise.admin.monitor.stats.StatisticImpl;
38
39 import com.sun.corba.ee.spi.monitoring.MonitoringConstants;
40 import com.sun.corba.ee.spi.monitoring.MonitoringManager;
41 import com.sun.corba.ee.spi.monitoring.MonitoredObject;
42 import com.sun.corba.ee.impl.orbutil.ORBConstants;
43
44 /**
45  * This is the implementation for the ThreadPoolStats
46  * and provides the implementation required to get the statistics
47  * for a threadpool
48  *
49  * @author Pramod Gopinath
50  */

51
52 public class ThreadPoolStatsImpl
53 extends ORBCommonStatsImpl
54 implements ThreadPoolStats
55 {
56
57     private MonitoredObject threadPool;
58     private MonitoredObject workQueue;
59     private String JavaDoc threadPoolName;
60
61     private MutableCountStatisticImpl numberOfBusyThreads;
62     private MutableCountStatisticImpl numberOfAvailableThreads;
63     private MutableBoundedRangeStatisticImpl currentNumberOfThreads;
64     private MutableBoundedRangeStatisticImpl averageWorkCompletionTime;
65     private MutableCountStatisticImpl totalWorkItemsAdded;
66     private MutableCountStatisticImpl numberOfWorkItemsInQueue;
67     private MutableBoundedRangeStatisticImpl averageTimeInQueue;
68
69     private static final String JavaDoc stringNumberOfBusyThreads =
70         MonitoringConstants.THREADPOOL_NUMBER_OF_BUSY_THREADS;
71     private static final String JavaDoc stringNumberOfAvailableThreads =
72         MonitoringConstants.THREADPOOL_NUMBER_OF_AVAILABLE_THREADS;
73     private static final String JavaDoc stringCurrentNumberOfThreads =
74         MonitoringConstants.THREADPOOL_CURRENT_NUMBER_OF_THREADS;
75     private static final String JavaDoc stringAverageWorkCompletionTime =
76         MonitoringConstants.THREADPOOL_AVERAGE_WORK_COMPLETION_TIME;
77     private static final String JavaDoc stringTotalWorkItemsAdded =
78         MonitoringConstants.WORKQUEUE_TOTAL_WORK_ITEMS_ADDED;
79     private static final String JavaDoc stringNumberOfWorkItemsInQueue =
80         MonitoringConstants.WORKQUEUE_WORK_ITEMS_IN_QUEUE;
81     private static final String JavaDoc stringAverageTimeInQueue =
82         MonitoringConstants.WORKQUEUE_AVERAGE_TIME_IN_QUEUE;
83
84
85     public ThreadPoolStatsImpl( MonitoredObject threadPool ) {
86         this.threadPool = threadPool;
87         this.threadPoolName = threadPool.getName();
88
89         getWorkQueueForThreadPool();
90
91         initializeStats();
92     }
93
94     private void getWorkQueueForThreadPool() {
95         Object JavaDoc[] workQueues = threadPool.getChildren().toArray();
96         workQueue = (MonitoredObject) workQueues[ 0 ];
97     }
98
99
100     private void initializeStats() {
101         super.initialize("com.sun.enterprise.admin.monitor.stats.ThreadPoolStats");
102
103         final long time = System.currentTimeMillis();
104
105         numberOfBusyThreads =
106             new MutableCountStatisticImpl(
107                 new CountStatisticImpl( 0, stringNumberOfBusyThreads, "COUNT",
108                     threadPool.getAttribute( stringNumberOfBusyThreads ).
109                     getAttributeInfo().getDescription(),
110                     time, time ));
111
112         numberOfAvailableThreads =
113             new MutableCountStatisticImpl(
114                 new CountStatisticImpl( 0, stringNumberOfAvailableThreads, "count",
115                     threadPool.getAttribute( stringNumberOfAvailableThreads ).
116                     getAttributeInfo().getDescription(),
117                     time, time ));
118
119         currentNumberOfThreads =
120             new MutableBoundedRangeStatisticImpl(
121                 new BoundedRangeStatisticImpl( 0, 0, 0, java.lang.Long.MAX_VALUE, 0,
122                     stringCurrentNumberOfThreads, "count",
123                     threadPool.getAttribute( stringCurrentNumberOfThreads ).
124                     getAttributeInfo().getDescription(),
125                     time, time ));
126
127         averageWorkCompletionTime =
128             new MutableBoundedRangeStatisticImpl(
129                 new BoundedRangeStatisticImpl( 0, 0, 0, java.lang.Long.MAX_VALUE, 0,
130                     stringAverageWorkCompletionTime, "Milliseconds",
131                     threadPool.getAttribute( stringAverageWorkCompletionTime ).
132                     getAttributeInfo().getDescription(),
133                     time, time ));
134
135         MonitoredObject workQueue = threadPool.getChild(
136             ORBConstants.WORKQUEUE_DEFAULT_NAME );
137
138         totalWorkItemsAdded =
139             new MutableCountStatisticImpl(
140                 new CountStatisticImpl( 0, stringTotalWorkItemsAdded, "count",
141                     workQueue.getAttribute( stringTotalWorkItemsAdded ).
142                     getAttributeInfo().getDescription(),
143                     time, time ));
144
145         numberOfWorkItemsInQueue =
146             new MutableCountStatisticImpl(
147                 new CountStatisticImpl( 0, stringNumberOfWorkItemsInQueue, "count",
148                     workQueue.getAttribute( stringNumberOfWorkItemsInQueue ).
149                     getAttributeInfo( ).getDescription(),
150                     time, time ));
151
152         averageTimeInQueue =
153             new MutableBoundedRangeStatisticImpl(
154                 new BoundedRangeStatisticImpl( 0, 0, 0, java.lang.Long.MAX_VALUE, 0,
155                     stringAverageTimeInQueue, "Milliseconds",
156                     workQueue.getAttribute( stringAverageTimeInQueue ).
157                     getAttributeInfo( ).getDescription(),
158                     time, time ));
159
160     }
161
162     public CountStatistic JavaDoc getNumberOfBusyThreads() {
163         long numBusyThreads = ((Long JavaDoc) threadPool.getAttribute(
164             stringNumberOfBusyThreads ).getValue()).longValue();
165
166         numberOfBusyThreads.setCount( numBusyThreads );
167
168         return (CountStatistic JavaDoc) numberOfBusyThreads.modifiableView();
169     }
170
171     public CountStatistic JavaDoc getNumberOfAvailableThreads() {
172         long numAvailableThreads = ((Long JavaDoc) threadPool.getAttribute(
173             stringNumberOfAvailableThreads ).getValue()).longValue();
174
175         numberOfAvailableThreads.setCount( numAvailableThreads );
176
177         return (CountStatistic JavaDoc) numberOfAvailableThreads.modifiableView();
178     }
179
180
181     public BoundedRangeStatistic JavaDoc getCurrentNumberOfThreads() {
182         long numCurrentThreads = ((Long JavaDoc) threadPool.getAttribute(
183             stringCurrentNumberOfThreads ).getValue()).longValue();
184
185         currentNumberOfThreads.setCount( numCurrentThreads );
186
187         return (BoundedRangeStatistic JavaDoc) currentNumberOfThreads.modifiableView();
188     }
189
190
191     public RangeStatistic JavaDoc getAverageWorkCompletionTime() {
192         long avgWorkCompletionTime = ((Long JavaDoc) threadPool.getAttribute(
193         stringAverageWorkCompletionTime ).getValue()).longValue();
194
195         averageWorkCompletionTime.setCount( avgWorkCompletionTime );
196
197         return (RangeStatistic JavaDoc) averageWorkCompletionTime.modifiableView();
198     }
199
200
201     public CountStatistic JavaDoc getTotalWorkItemsAdded() {
202         long totWorkItemsAdded = ((Long JavaDoc) workQueue.getAttribute(
203         stringTotalWorkItemsAdded ).getValue()).longValue();
204
205
206         totalWorkItemsAdded.setCount( totWorkItemsAdded );
207
208         return (CountStatistic JavaDoc) totalWorkItemsAdded.modifiableView();
209     }
210
211             
212     public CountStatistic JavaDoc getNumberOfWorkItemsInQueue() {
213         long totWorkItemsInQueue = ((Long JavaDoc) workQueue.getAttribute(
214         stringNumberOfWorkItemsInQueue ).getValue()).longValue();
215
216         numberOfWorkItemsInQueue.setCount( totWorkItemsInQueue );
217
218         return (CountStatistic JavaDoc) numberOfWorkItemsInQueue.modifiableView();
219     }
220
221
222     public RangeStatistic JavaDoc getAverageTimeInQueue() {
223         long avgTimeInQueue = ((Long JavaDoc) workQueue.getAttribute(
224         stringAverageTimeInQueue ).getValue()).longValue();
225
226         averageTimeInQueue.setCount( avgTimeInQueue );
227
228         return (RangeStatistic JavaDoc) averageTimeInQueue.modifiableView();
229     }
230
231
232 } //ThreadPoolStatsImpl{ }
233
Popular Tags