1 23 24 package com.sun.enterprise.iiop; 25 26 import java.util.Iterator ; 27 28 import javax.management.j2ee.statistics.CountStatistic ; 29 import javax.management.j2ee.statistics.BoundedRangeStatistic ; 30 import javax.management.j2ee.statistics.RangeStatistic ; 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 51 52 public class ThreadPoolStatsImpl 53 extends ORBCommonStatsImpl 54 implements ThreadPoolStats 55 { 56 57 private MonitoredObject threadPool; 58 private MonitoredObject workQueue; 59 private String 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 stringNumberOfBusyThreads = 70 MonitoringConstants.THREADPOOL_NUMBER_OF_BUSY_THREADS; 71 private static final String stringNumberOfAvailableThreads = 72 MonitoringConstants.THREADPOOL_NUMBER_OF_AVAILABLE_THREADS; 73 private static final String stringCurrentNumberOfThreads = 74 MonitoringConstants.THREADPOOL_CURRENT_NUMBER_OF_THREADS; 75 private static final String stringAverageWorkCompletionTime = 76 MonitoringConstants.THREADPOOL_AVERAGE_WORK_COMPLETION_TIME; 77 private static final String stringTotalWorkItemsAdded = 78 MonitoringConstants.WORKQUEUE_TOTAL_WORK_ITEMS_ADDED; 79 private static final String stringNumberOfWorkItemsInQueue = 80 MonitoringConstants.WORKQUEUE_WORK_ITEMS_IN_QUEUE; 81 private static final String 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 [] 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 getNumberOfBusyThreads() { 163 long numBusyThreads = ((Long ) threadPool.getAttribute( 164 stringNumberOfBusyThreads ).getValue()).longValue(); 165 166 numberOfBusyThreads.setCount( numBusyThreads ); 167 168 return (CountStatistic ) numberOfBusyThreads.modifiableView(); 169 } 170 171 public CountStatistic getNumberOfAvailableThreads() { 172 long numAvailableThreads = ((Long ) threadPool.getAttribute( 173 stringNumberOfAvailableThreads ).getValue()).longValue(); 174 175 numberOfAvailableThreads.setCount( numAvailableThreads ); 176 177 return (CountStatistic ) numberOfAvailableThreads.modifiableView(); 178 } 179 180 181 public BoundedRangeStatistic getCurrentNumberOfThreads() { 182 long numCurrentThreads = ((Long ) threadPool.getAttribute( 183 stringCurrentNumberOfThreads ).getValue()).longValue(); 184 185 currentNumberOfThreads.setCount( numCurrentThreads ); 186 187 return (BoundedRangeStatistic ) currentNumberOfThreads.modifiableView(); 188 } 189 190 191 public RangeStatistic getAverageWorkCompletionTime() { 192 long avgWorkCompletionTime = ((Long ) threadPool.getAttribute( 193 stringAverageWorkCompletionTime ).getValue()).longValue(); 194 195 averageWorkCompletionTime.setCount( avgWorkCompletionTime ); 196 197 return (RangeStatistic ) averageWorkCompletionTime.modifiableView(); 198 } 199 200 201 public CountStatistic getTotalWorkItemsAdded() { 202 long totWorkItemsAdded = ((Long ) workQueue.getAttribute( 203 stringTotalWorkItemsAdded ).getValue()).longValue(); 204 205 206 totalWorkItemsAdded.setCount( totWorkItemsAdded ); 207 208 return (CountStatistic ) totalWorkItemsAdded.modifiableView(); 209 } 210 211 212 public CountStatistic getNumberOfWorkItemsInQueue() { 213 long totWorkItemsInQueue = ((Long ) workQueue.getAttribute( 214 stringNumberOfWorkItemsInQueue ).getValue()).longValue(); 215 216 numberOfWorkItemsInQueue.setCount( totWorkItemsInQueue ); 217 218 return (CountStatistic ) numberOfWorkItemsInQueue.modifiableView(); 219 } 220 221 222 public RangeStatistic getAverageTimeInQueue() { 223 long avgTimeInQueue = ((Long ) workQueue.getAttribute( 224 stringAverageTimeInQueue ).getValue()).longValue(); 225 226 averageTimeInQueue.setCount( avgTimeInQueue ); 227 228 return (RangeStatistic ) averageTimeInQueue.modifiableView(); 229 } 230 231 232 } | Popular Tags |