1 23 24 package com.sun.enterprise.web.stats; 25 26 import java.util.ArrayList ; 27 import java.util.logging.Logger ; 28 import java.util.logging.Level ; 29 import java.text.MessageFormat ; 30 import javax.management.ObjectName ; 31 import javax.management.MBeanServerFactory ; 32 import javax.management.MBeanServer ; 33 import javax.management.j2ee.statistics.CountStatistic ; 34 import javax.management.j2ee.statistics.Statistic ; 35 import com.sun.logging.LogDomains; 36 import com.sun.enterprise.admin.monitor.stats.PWCConnectionQueueStats; 37 import com.sun.enterprise.admin.monitor.stats.MutableCountStatistic; 38 import com.sun.enterprise.admin.monitor.stats.MutableCountStatisticImpl; 39 import com.sun.enterprise.admin.monitor.stats.GenericStatsImpl; 40 import com.sun.enterprise.admin.monitor.stats.CountStatisticImpl; 41 import com.sun.enterprise.admin.monitor.stats.StringStatistic; 42 import com.sun.enterprise.admin.monitor.stats.StringStatisticImpl; 43 44 47 public class PWCConnectionQueueStatsImpl implements PWCConnectionQueueStats { 48 49 private static Logger _logger 50 = LogDomains.getLogger(LogDomains.WEB_LOGGER); 51 52 private GenericStatsImpl baseStatsImpl; 53 54 private MBeanServer server; 55 private ObjectName connectionQueueName; 56 57 private StringStatistic id; 58 private MutableCountStatistic countTotalConnections; 59 private MutableCountStatistic countQueued; 60 private MutableCountStatistic peakQueued; 61 private MutableCountStatistic maxQueued; 62 private MutableCountStatistic countOverflows; 63 private MutableCountStatistic countTotalQueued; 64 private MutableCountStatistic ticksTotalQueued; 65 private MutableCountStatistic countQueued1MinuteAverage; 66 private MutableCountStatistic countQueued5MinuteAverage; 67 private MutableCountStatistic countQueued15MinuteAverage; 68 69 70 75 public PWCConnectionQueueStatsImpl(String domain) { 76 77 baseStatsImpl = new GenericStatsImpl( 78 com.sun.enterprise.admin.monitor.stats.PWCConnectionQueueStats.class, 79 this); 80 81 ArrayList servers = MBeanServerFactory.findMBeanServer(null); 83 if(!servers.isEmpty()) 84 server = (MBeanServer )servers.get(0); 85 else 86 server = MBeanServerFactory.createMBeanServer(); 87 88 String objNameStr = domain + ":type=PWCConnectionQueue,*"; 89 try { 90 connectionQueueName = new ObjectName (objNameStr); 91 } catch (Throwable t) { 92 String msg = _logger.getResourceBundle().getString( 93 "webcontainer.objectNameCreationError"); 94 msg = MessageFormat.format(msg, new Object [] { objNameStr }); 95 _logger.log(Level.SEVERE, msg, t); 96 } 97 98 initializeStatistics(); 100 } 101 102 103 108 public StringStatistic getId() { 109 return id; 110 } 111 112 113 118 public CountStatistic getCountTotalConnections() { 119 countTotalConnections.setCount( 120 StatsUtil.getAggregateStatistic(server, connectionQueueName, 121 "countTotalConnections")); 122 return (CountStatistic )countTotalConnections.unmodifiableView(); 123 } 124 125 126 131 public CountStatistic getCountQueued() { 132 countQueued.setCount( 133 StatsUtil.getAggregateStatistic(server, connectionQueueName, 134 "countQueued")); 135 return (CountStatistic )countQueued.unmodifiableView(); 136 } 137 138 139 146 public CountStatistic getPeakQueued() { 147 peakQueued.setCount( 148 StatsUtil.getAggregateStatistic(server, connectionQueueName, 149 "peakQueued")); 150 return (CountStatistic )peakQueued.unmodifiableView(); 151 } 152 153 154 159 public CountStatistic getMaxQueued() { 160 maxQueued.setCount( 161 StatsUtil.getConstant(server, connectionQueueName, "maxQueued")); 162 return (CountStatistic )maxQueued.unmodifiableView(); 163 } 164 165 166 173 public CountStatistic getCountOverflows() { 174 countOverflows.setCount( 175 StatsUtil.getAggregateStatistic(server, connectionQueueName, 176 "countOverflows")); 177 return (CountStatistic )countOverflows.unmodifiableView(); 178 } 179 180 181 190 public CountStatistic getCountTotalQueued() { 191 countTotalQueued.setCount( 192 StatsUtil.getAggregateStatistic(server, connectionQueueName, 193 "countTotalQueued")); 194 return (CountStatistic )countTotalQueued.unmodifiableView(); 195 } 196 197 198 207 public CountStatistic getTicksTotalQueued() { 208 ticksTotalQueued.setCount( 209 StatsUtil.getAverageStatistic(server, connectionQueueName, 210 "ticksTotalQueued")); 211 return (CountStatistic )ticksTotalQueued.unmodifiableView(); 212 } 213 214 215 220 public CountStatistic getCountQueued1MinuteAverage() { 221 countQueued1MinuteAverage.setCount( 222 StatsUtil.getAverageStatistic(server, connectionQueueName, 223 "countQueued1MinuteAverage")); 224 return (CountStatistic )countQueued1MinuteAverage.unmodifiableView(); 225 } 226 227 228 233 public CountStatistic getCountQueued5MinuteAverage() { 234 countQueued5MinuteAverage.setCount( 235 StatsUtil.getAverageStatistic(server, connectionQueueName, 236 "countQueued5MinuteAverage")); 237 return (CountStatistic )countQueued5MinuteAverage.unmodifiableView(); 238 } 239 240 241 246 public CountStatistic getCountQueued15MinuteAverage() { 247 countQueued15MinuteAverage.setCount( 248 StatsUtil.getAverageStatistic(server, connectionQueueName, 249 "countQueued15MinuteAverage")); 250 return (CountStatistic )countQueued15MinuteAverage.unmodifiableView(); 251 } 252 253 254 259 public Statistic [] getStatistics() { 260 return baseStatsImpl.getStatistics(); 261 } 262 263 264 271 public Statistic getStatistic(String name) { 272 return baseStatsImpl.getStatistic(name); 273 } 274 275 276 282 public String [] getStatisticNames() { 283 return baseStatsImpl.getStatisticNames(); 284 } 285 286 287 private void initializeStatistics() { 288 289 long startTime = System.currentTimeMillis(); 290 id = new StringStatisticImpl("", 291 "Id", 292 "String", 293 "ID of the connection queue", 294 startTime, 295 startTime); 296 297 CountStatistic c = new CountStatisticImpl("CountTotalConnections"); 298 countTotalConnections = new MutableCountStatisticImpl(c); 299 300 c = new CountStatisticImpl("CountQueued"); 301 countQueued = new MutableCountStatisticImpl(c); 302 303 c = new CountStatisticImpl("PeakQueued"); 304 peakQueued = new MutableCountStatisticImpl(c); 305 306 c = new CountStatisticImpl("MaxQueued"); 307 maxQueued = new MutableCountStatisticImpl(c); 308 309 c = new CountStatisticImpl("CountOverflows"); 310 countOverflows = new MutableCountStatisticImpl(c); 311 312 c = new CountStatisticImpl("CountTotalQueued"); 313 countTotalQueued = new MutableCountStatisticImpl(c); 314 315 c = new CountStatisticImpl("TicksTotalQueued"); 316 ticksTotalQueued = new MutableCountStatisticImpl(c); 317 318 c = new CountStatisticImpl("CountQueued1MinuteAverage"); 319 countQueued1MinuteAverage = new MutableCountStatisticImpl(c); 320 321 c = new CountStatisticImpl("CountQueued5MinuteAverage"); 322 countQueued5MinuteAverage = new MutableCountStatisticImpl(c); 323 324 c = new CountStatisticImpl("CountQueued15MinuteAverage"); 325 countQueued15MinuteAverage = new MutableCountStatisticImpl(c); 326 } 327 328 } 329 | Popular Tags |