1 23 package com.sun.enterprise.web.stats; 24 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.PWCFileCacheStats; 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 42 43 48 public class PWCFileCacheStatsImpl implements PWCFileCacheStats { 49 private final static Logger logger 50 = LogDomains.getLogger(LogDomains.WEB_LOGGER); 51 52 private GenericStatsImpl baseStatsImpl; 53 private ObjectName fileCacheName; 54 private MBeanServer server; 55 56 private MutableCountStatistic flagEnabled; 57 private MutableCountStatistic secondsMaxAge; 58 private MutableCountStatistic countEntries; 59 private MutableCountStatistic maxEntries; 60 private MutableCountStatistic countOpenEntries; 61 private MutableCountStatistic maxOpenEntries; 62 private MutableCountStatistic sizeHeapCache; 63 private MutableCountStatistic maxHeapCacheSize; 64 private MutableCountStatistic sizeMmapCache; 65 private MutableCountStatistic maxMmapCacheSize; 66 private MutableCountStatistic countHits; 67 private MutableCountStatistic countMisses; 68 private MutableCountStatistic countInfoHits; 69 private MutableCountStatistic countInfoMisses; 70 private MutableCountStatistic countContentHits; 71 private MutableCountStatistic countContentMisses; 72 73 74 public PWCFileCacheStatsImpl(String domain) { 75 76 baseStatsImpl = new GenericStatsImpl( 77 com.sun.enterprise.admin.monitor.stats.PWCFileCacheStats.class, 78 this); 79 80 ArrayList servers = MBeanServerFactory.findMBeanServer(null); 82 if(!servers.isEmpty()) 83 server = (MBeanServer )servers.get(0); 84 else 85 server = MBeanServerFactory.createMBeanServer(); 86 87 String objNameStr = domain + ":type=PWCFileCache,*"; 88 try { 89 fileCacheName = new ObjectName (objNameStr); 90 } catch (Throwable t) { 91 String msg = logger.getResourceBundle().getString( 92 "webcontainer.objectNameCreationError"); 93 msg = MessageFormat.format(msg, new Object [] { objNameStr }); 94 logger.log(Level.SEVERE, msg, t); 95 } 96 97 initializeStatistics(); 99 } 100 101 102 106 public CountStatistic getFlagEnabled() { 107 flagEnabled.setCount( 108 StatsUtil.getMaxStatistic(server, fileCacheName,"flagEnabled")); 109 return (CountStatistic )flagEnabled.unmodifiableView(); 110 } 111 112 113 117 public CountStatistic getSecondsMaxAge() { 118 secondsMaxAge.setCount( 119 StatsUtil.getMaxStatistic(server, fileCacheName,"secondsMaxAge")); 120 return (CountStatistic )secondsMaxAge.unmodifiableView(); 121 } 122 123 124 127 public CountStatistic getCountEntries() { 128 countEntries.setCount(getAggregateLong("countEntries")); 129 return (CountStatistic )countEntries.unmodifiableView(); 130 } 131 132 133 136 public CountStatistic getMaxEntries() { 137 maxEntries.setCount( 138 StatsUtil.getMaxStatistic(server, fileCacheName,"maxEntries")); 139 return (CountStatistic )maxEntries.unmodifiableView(); 140 } 141 142 143 147 public CountStatistic getCountOpenEntries() { 148 countOpenEntries.setCount(getAggregateLong("countOpenEntries")); 149 return (CountStatistic )countOpenEntries.unmodifiableView(); 150 } 151 152 153 156 public CountStatistic getMaxOpenEntries() { 157 maxOpenEntries.setCount( 158 StatsUtil.getMaxStatistic(server, fileCacheName,"maxOpenEntries")); 159 return (CountStatistic )maxOpenEntries.unmodifiableView(); 160 } 161 162 163 167 public CountStatistic getSizeHeapCache() { 168 sizeHeapCache.setCount( 169 StatsUtil.getMaxLongStatistic(server, 170 fileCacheName,"sizeHeapCache")); 171 return (CountStatistic )sizeHeapCache.unmodifiableView(); 172 } 173 174 175 178 public CountStatistic getMaxHeapCacheSize() { 179 maxHeapCacheSize.setCount( 180 StatsUtil.getMaxLongStatistic(server, 181 fileCacheName,"maxHeapCacheSize")); 182 return (CountStatistic )maxHeapCacheSize.unmodifiableView(); 183 } 184 185 186 189 public CountStatistic getSizeMmapCache() { 190 sizeMmapCache.setCount( 191 StatsUtil.getMaxLongStatistic(server, 192 fileCacheName,"sizeMmapCache")); 193 return (CountStatistic )sizeMmapCache.unmodifiableView(); 194 } 195 196 197 200 public CountStatistic getMaxMmapCacheSize() { 201 maxMmapCacheSize.setCount( 202 StatsUtil.getMaxLongStatistic(server, 203 fileCacheName,"maxMmapCacheSize")); 204 return (CountStatistic )maxMmapCacheSize.unmodifiableView(); 205 } 206 207 208 211 public CountStatistic getCountHits() { 212 countHits.setCount(getAggregateLong("countHits")); 213 return (CountStatistic )countHits.unmodifiableView(); 214 } 215 216 217 220 public CountStatistic getCountMisses() { 221 countMisses.setCount(getAggregateLong("countMisses")); 222 return (CountStatistic )countMisses.unmodifiableView(); 223 } 224 225 226 229 public CountStatistic getCountInfoHits() { 230 countInfoHits.setCount(getAggregateLong("countInfoHits")); 231 return (CountStatistic )countInfoHits.unmodifiableView(); 232 } 233 234 235 239 public CountStatistic getCountInfoMisses() { 240 countInfoMisses.setCount(getAggregateLong("countInfoMisses")); 241 return (CountStatistic )countInfoMisses.unmodifiableView(); 242 } 243 244 245 248 public CountStatistic getCountContentHits() { 249 countContentHits.setCount(getAggregateLong("countContentHits")); 250 return (CountStatistic )countContentHits.unmodifiableView(); 251 } 252 253 254 257 public CountStatistic getCountContentMisses() { 258 countContentMisses.setCount(getAggregateLong("countContentMisses")); 259 return (CountStatistic )countContentMisses.unmodifiableView(); 260 } 261 262 263 269 public Statistic [] getStatistics() { 270 return baseStatsImpl.getStatistics(); 271 } 272 273 274 public Statistic getStatistic( String str ) { 275 return baseStatsImpl.getStatistic( str ); 276 } 277 278 279 public String [] getStatisticNames() { 280 return baseStatsImpl.getStatisticNames(); 281 } 282 283 284 287 private void initializeStatistics() { 288 CountStatistic cs = null; 289 290 cs = new CountStatisticImpl("FlagEnabled"); 292 flagEnabled = new MutableCountStatisticImpl( cs ); 293 294 cs = new CountStatisticImpl("SecondsMaxAge"); 296 secondsMaxAge = new MutableCountStatisticImpl( cs ); 297 298 cs = new CountStatisticImpl("CountEntries"); 300 countEntries = new MutableCountStatisticImpl( cs ); 301 302 cs = new CountStatisticImpl("MaxEntries"); 304 maxEntries = new MutableCountStatisticImpl( cs ); 305 306 cs = new CountStatisticImpl("CountOpenEntries"); 308 countOpenEntries = new MutableCountStatisticImpl( cs ); 309 310 cs = new CountStatisticImpl("MaxOpenEntries"); 312 maxOpenEntries = new MutableCountStatisticImpl( cs ); 313 314 cs = new CountStatisticImpl("SizeHeapCache"); 316 sizeHeapCache = new MutableCountStatisticImpl( cs ); 317 318 cs = new CountStatisticImpl("MaxHeapCacheSize"); 320 maxHeapCacheSize = new MutableCountStatisticImpl( cs ); 321 322 cs = new CountStatisticImpl("SizeMmapCache"); 324 sizeMmapCache = new MutableCountStatisticImpl( cs ); 325 326 cs = new CountStatisticImpl("MaxMmapCacheSize"); 328 maxMmapCacheSize = new MutableCountStatisticImpl( cs ); 329 330 cs = new CountStatisticImpl("CountHits"); 332 countHits = new MutableCountStatisticImpl( cs ); 333 334 cs = new CountStatisticImpl("CountMisses"); 336 countMisses = new MutableCountStatisticImpl( cs ); 337 338 cs = new CountStatisticImpl("CountInfoHits"); 340 countInfoHits = new MutableCountStatisticImpl( cs ); 341 342 cs = new CountStatisticImpl("CountInfoMisses"); 344 countInfoMisses = new MutableCountStatisticImpl( cs ); 345 346 cs = new CountStatisticImpl("CountContentHits"); 348 countContentHits = new MutableCountStatisticImpl( cs ); 349 350 cs = new CountStatisticImpl("CountContentMisses"); 352 countContentMisses = new MutableCountStatisticImpl( cs ); 353 354 } 355 356 357 360 private final int getAggregateInt(String attribute){ 361 return StatsUtil.getAggregateStatistic(server,fileCacheName,attribute); 362 } 363 364 365 368 private final long getAggregateLong(String attribute){ 369 return StatsUtil. 370 getAggregateLongStatistic(server,fileCacheName,attribute); 371 } 372 } 373 | Popular Tags |