1 23 package com.sun.enterprise.web.stats; 24 25 import java.util.ArrayList ; 26 import java.util.logging.Logger ; 27 import java.util.logging.Level ; 28 import java.text.MessageFormat ; 29 import javax.management.ObjectName ; 30 import javax.management.MBeanServerFactory ; 31 import javax.management.MBeanServer ; 32 import javax.management.j2ee.statistics.CountStatistic ; 33 import javax.management.j2ee.statistics.Statistic ; 34 import com.sun.logging.LogDomains; 35 import com.sun.enterprise.admin.monitor.stats.StringStatistic; 36 import com.sun.enterprise.admin.monitor.stats.StringStatisticImpl; 37 import com.sun.enterprise.admin.monitor.stats.PWCThreadPoolStats; 38 import com.sun.enterprise.admin.monitor.stats.MutableCountStatistic; 39 import com.sun.enterprise.admin.monitor.stats.MutableCountStatisticImpl; 40 import com.sun.enterprise.admin.monitor.stats.GenericStatsImpl; 41 import com.sun.enterprise.admin.monitor.stats.CountStatisticImpl; 42 43 46 public class PWCThreadPoolStatsImpl implements PWCThreadPoolStats { 47 48 private static Logger _logger 49 = LogDomains.getLogger(LogDomains.WEB_LOGGER); 50 51 private GenericStatsImpl baseStatsImpl; 52 53 private MBeanServer server; 54 private ObjectName threadPoolName; 55 56 private StringStatistic id; 57 private MutableCountStatistic countThreadsIdle; 58 private MutableCountStatistic countThreads; 59 private MutableCountStatistic maxThreads; 60 private MutableCountStatistic countQueued; 61 private MutableCountStatistic peakQueued; 62 private MutableCountStatistic maxQueued; 63 64 65 public PWCThreadPoolStatsImpl(String domain) { 66 67 baseStatsImpl = new GenericStatsImpl( 68 com.sun.enterprise.admin.monitor.stats.PWCThreadPoolStats.class, 69 this); 70 71 ArrayList servers = MBeanServerFactory.findMBeanServer(null); 73 if(!servers.isEmpty()) 74 server = (MBeanServer )servers.get(0); 75 else 76 server = MBeanServerFactory.createMBeanServer(); 77 78 String objNameStr = domain + ":type=Selector,*"; 79 try { 80 threadPoolName = new ObjectName (objNameStr); 81 } catch (Throwable t) { 82 String msg = _logger.getResourceBundle().getString( 83 "webcontainer.objectNameCreationError"); 84 msg = MessageFormat.format(msg, new Object [] { objNameStr }); 85 _logger.log(Level.SEVERE, msg, t); 86 } 87 88 initializeStatistics(); 90 } 91 92 93 98 public StringStatistic getId() { 99 return id; 100 } 101 102 103 108 public CountStatistic getCountThreadsIdle() { 109 countThreadsIdle.setCount( 110 StatsUtil.getAggregateStatistic(server, threadPoolName, 111 "countThreadsIdleStats")); 112 return (CountStatistic )countThreadsIdle.unmodifiableView(); 113 } 114 115 116 121 public CountStatistic getCountThreads() { 122 countThreads.setCount( 123 StatsUtil.getAggregateStatistic(server, threadPoolName, 124 "countThreadsStats")); 125 return (CountStatistic )countThreads.unmodifiableView(); 126 } 127 128 129 134 public CountStatistic getMaxThreads() { 135 maxThreads.setCount(StatsUtil.getAggregateStatistic(server, 136 threadPoolName, 137 "maxThreadsStats")); 138 return (CountStatistic )maxThreads.unmodifiableView(); 139 } 140 141 142 147 public CountStatistic getCountQueued() { 148 return null; 149 } 150 151 152 159 public CountStatistic getPeakQueued() { 160 return null; 161 } 162 163 164 169 public CountStatistic getMaxQueued() { 170 return null; 171 } 172 173 174 179 public Statistic [] getStatistics() { 180 return baseStatsImpl.getStatistics(); 181 } 182 183 184 191 public Statistic getStatistic(String name) { 192 return baseStatsImpl.getStatistic(name); 193 } 194 195 196 202 public String [] getStatisticNames() { 203 return baseStatsImpl.getStatisticNames(); 204 } 205 206 207 private void initializeStatistics() { 208 209 long startTime = System.currentTimeMillis(); 210 id = new StringStatisticImpl("", 211 "id", 212 "String", 213 "ID of the thread pool", 214 startTime, 215 startTime); 216 217 CountStatistic c = new CountStatisticImpl("CountThreadsIdle"); 218 countThreadsIdle = new MutableCountStatisticImpl(c); 219 220 c = new CountStatisticImpl("CountThreads"); 221 countThreads = new MutableCountStatisticImpl(c); 222 223 c = new CountStatisticImpl("MaxThreads"); 224 maxThreads = new MutableCountStatisticImpl(c); 225 226 c = new CountStatisticImpl("CountQueued"); 227 countQueued = new MutableCountStatisticImpl(c); 228 229 c = new CountStatisticImpl("PeakQueued"); 230 peakQueued = new MutableCountStatisticImpl(c); 231 232 c = new CountStatisticImpl("MaxQueued"); 233 maxQueued = new MutableCountStatisticImpl(c); 234 } 235 236 } 237 | Popular Tags |