1 23 24 package com.sun.enterprise.web.stats; 25 26 import java.util.HashMap ; 27 import java.util.logging.Level ; 28 import java.util.logging.Logger ; 29 import java.util.StringTokenizer ; 30 import javax.management.j2ee.statistics.Statistic ; 31 import javax.management.j2ee.statistics.CountStatistic ; 32 import com.sun.logging.LogDomains; 33 import com.sun.enterprise.web.MonitorStatsCapable; 34 import com.sun.enterprise.admin.monitor.stats.WebModuleStats; 35 import com.sun.enterprise.admin.monitor.stats.MutableCountStatistic; 36 import com.sun.enterprise.admin.monitor.stats.MutableCountStatisticImpl; 37 import com.sun.enterprise.admin.monitor.stats.GenericStatsImpl; 38 import com.sun.enterprise.admin.monitor.stats.CountStatisticImpl; 39 import com.sun.enterprise.admin.monitor.stats.StringStatistic; 40 import com.sun.enterprise.admin.monitor.stats.StringStatisticImpl; 41 import com.sun.enterprise.web.monitor.PwcWebModuleStats; 42 import org.apache.catalina.Manager; 43 44 45 48 public class WebModuleStatsImpl implements WebModuleStats { 49 50 private static Logger _logger 51 = LogDomains.getLogger(LogDomains.WEB_LOGGER); 52 53 protected Manager sessionManager; 54 protected GenericStatsImpl baseStatsImpl; 55 56 private PwcWebModuleStats pwcWebStats; 57 private long initTime; 58 59 62 protected MutableCountStatistic jspCount; 63 protected MutableCountStatistic jspReloadCount; 64 protected MutableCountStatistic jspErrorCount; 65 66 69 protected MutableCountStatistic sessionsTotal; 70 protected MutableCountStatistic activeSessionsCurrent; 71 protected MutableCountStatistic activeSessionsHigh; 72 protected MutableCountStatistic rejectedSessionsTotal; 73 protected MutableCountStatistic expiredSessionsTotal; 74 protected MutableCountStatistic processingTimeMillis; 75 76 77 80 public WebModuleStatsImpl() { 81 this(com.sun.enterprise.admin.monitor.stats.WebModuleStats.class); 82 } 83 84 90 protected WebModuleStatsImpl(Class inter) { 91 baseStatsImpl = new GenericStatsImpl(inter, this); 92 93 initializeStatistics(); 95 } 96 97 98 104 public void setSessionManager(Manager manager) { 105 if (manager == null) { 106 throw new IllegalArgumentException ("Null session manager"); 107 } 108 this.sessionManager = manager; 109 } 110 111 112 118 public void setPwcWebModuleStats(PwcWebModuleStats pwcWebStats) { 119 if (pwcWebStats == null) { 120 throw new IllegalArgumentException ("Null PwcWebModuleStats"); 121 } 122 this.pwcWebStats = pwcWebStats; 123 } 124 125 126 132 public CountStatistic getJspCount() { 133 if (pwcWebStats == null) { 134 throw new IllegalArgumentException ("Null PwcWebModuleStats"); 135 } 136 jspCount.setCount(pwcWebStats.getJspCount()); 137 return (CountStatistic ) jspCount.unmodifiableView(); 138 } 139 140 141 147 public CountStatistic getJspReloadCount() { 148 if (pwcWebStats == null) { 149 throw new IllegalArgumentException ("Null PwcWebModuleStats"); 150 } 151 jspReloadCount.setCount(pwcWebStats.getJspReloadCount()); 152 return (CountStatistic ) jspReloadCount.unmodifiableView(); 153 } 154 155 156 161 public CountStatistic getJspErrorCount() { 162 if (pwcWebStats == null) { 163 throw new IllegalArgumentException ("Null PwcWebModuleStats"); 164 } 165 jspErrorCount.setCount(pwcWebStats.getJspErrorCount()); 166 return (CountStatistic ) jspErrorCount.unmodifiableView(); 167 } 168 169 170 176 public CountStatistic getSessionsTotal() { 177 if (pwcWebStats == null) { 178 throw new IllegalArgumentException ("Null PwcWebModuleStats"); 179 } 180 sessionsTotal.setCount(pwcWebStats.getSessionsTotal()); 181 return (CountStatistic ) sessionsTotal.unmodifiableView(); 182 } 183 184 185 191 public CountStatistic getActiveSessionsCurrent() { 192 if (pwcWebStats == null) { 193 throw new IllegalArgumentException ("Null PwcWebModuleStats"); 194 } 195 activeSessionsCurrent.setCount(pwcWebStats.getActiveSessionsCurrent()); 196 return (CountStatistic ) activeSessionsCurrent.unmodifiableView(); 197 } 198 199 200 206 public CountStatistic getActiveSessionsHigh() { 207 if (pwcWebStats == null) { 208 throw new IllegalArgumentException ("Null PwcWebModuleStats"); 209 } 210 activeSessionsHigh.setCount(pwcWebStats.getActiveSessionsHigh()); 211 return (CountStatistic ) activeSessionsHigh.unmodifiableView(); 212 } 213 214 215 224 public CountStatistic getRejectedSessionsTotal() { 225 if (pwcWebStats == null) { 226 throw new IllegalArgumentException ("Null PwcWebModuleStats"); 227 } 228 rejectedSessionsTotal.setCount(pwcWebStats.getRejectedSessionsTotal()); 229 return (CountStatistic ) rejectedSessionsTotal.unmodifiableView(); 230 } 231 232 233 239 public CountStatistic getExpiredSessionsTotal() { 240 if (pwcWebStats == null) { 241 throw new IllegalArgumentException ("Null PwcWebModuleStats"); 242 } 243 expiredSessionsTotal.setCount(pwcWebStats.getExpiredSessionsTotal()); 244 return (CountStatistic ) expiredSessionsTotal.unmodifiableView(); 245 } 246 247 248 255 public CountStatistic getServletProcessingTimes() { 256 if (pwcWebStats == null) { 257 throw new IllegalArgumentException ("Null PwcWebModuleStats"); 258 } 259 processingTimeMillis.setCount( 260 pwcWebStats.getServletProcessingTimesMillis()); 261 return (CountStatistic ) processingTimeMillis.unmodifiableView(); 262 } 263 264 265 272 public StringStatistic getSessions() { 273 274 StringBuffer sb = null; 275 276 if (pwcWebStats == null) { 277 throw new IllegalArgumentException ("Null PwcWebModuleStats"); 278 } 279 280 String sessionIds = pwcWebStats.getSessionIds(); 281 if (sessionIds != null) { 282 sb = new StringBuffer (); 283 StringTokenizer tokenizer = new StringTokenizer (sessionIds, " "); 284 boolean first = true; 285 while (tokenizer.hasMoreTokens()) { 286 if (!first) { 287 sb.append(", "); 288 } else { 289 first = false; 290 } 291 String sessionId = tokenizer.nextToken(); 292 sb.append(sessionId); 293 HashMap map = pwcWebStats.getSession(sessionId); 294 if (map != null) { 295 sb.append(":"); 296 sb.append(map); 297 } 298 } 299 } 300 301 return new StringStatisticImpl( 302 sb != null ? sb.toString(): null, 303 "Sessions", 304 "String", 305 "List of currently active sessions", 306 initTime, 307 System.currentTimeMillis()); 308 } 309 310 311 314 public void reset() { 315 316 if (sessionManager instanceof MonitorStatsCapable) { 318 ((MonitorStatsCapable)sessionManager).resetMonitorStats(); 319 } 320 321 if (pwcWebStats != null) { 322 pwcWebStats.reset(); 323 } 324 } 325 326 327 333 public Statistic [] getStatistics() { 334 return baseStatsImpl.getStatistics(); 335 } 336 337 338 345 public Statistic getStatistic(String name) { 346 return baseStatsImpl.getStatistic(name); 347 } 348 349 350 357 public String [] getStatisticNames() { 358 return baseStatsImpl.getStatisticNames(); 359 } 360 361 362 private void initializeStatistics() { 363 364 jspCount = new MutableCountStatisticImpl( 365 new CountStatisticImpl("JspCount")); 366 jspReloadCount = new MutableCountStatisticImpl( 367 new CountStatisticImpl("JspReloadCount")); 368 jspErrorCount = new MutableCountStatisticImpl( 369 new CountStatisticImpl("JspErrorCount")); 370 sessionsTotal = new MutableCountStatisticImpl( 371 new CountStatisticImpl("SessionsTotal")); 372 activeSessionsCurrent = new MutableCountStatisticImpl( 373 new CountStatisticImpl("ActiveSessionsCurrent")); 374 activeSessionsHigh = new MutableCountStatisticImpl( 375 new CountStatisticImpl("ActiveSessionsHigh")); 376 rejectedSessionsTotal = new MutableCountStatisticImpl( 377 new CountStatisticImpl("RejectedSessionsTotal")); 378 expiredSessionsTotal = new MutableCountStatisticImpl( 379 new CountStatisticImpl("ExpiredSessionsTotal")); 380 processingTimeMillis = new MutableCountStatisticImpl( 381 new CountStatisticImpl("ServletProcessingTimes")); 382 initTime = System.currentTimeMillis (); 383 } 384 385 } 386 | Popular Tags |