001 /** 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017 018 package org.apache.geronimo.management.stats; 019 020 import javax.management.j2ee.statistics.CountStatistic; 021 import javax.management.j2ee.statistics.TimeStatistic; 022 023 import org.apache.geronimo.management.geronimo.stats.WebModuleStats; 024 025 /** 026 * Geronimo implementation of the JSR-77 style WebModule interface. This 027 * is not required by JSR-77, but provides useful statistics for a web app 028 * 029 * @version $Revison$ $Date: 2007-02-04 09:48:10 -0500 (Sun, 04 Feb 2007) $ 030 */ 031 public class WebModuleStatsImpl extends StatsImpl implements WebModuleStats { 032 // Static data 033 034 private CountStatisticImpl processingTime; 035 036 private CountStatisticImpl startupTime; 037 038 private CountStatisticImpl tldScanTime; 039 040 // transient data 041 private TimeStatisticImpl sessionAliveTime; // total, max, count 042 043 private CountStatisticImpl sessionCount; 044 045 private CountStatisticImpl activeSessionCount; 046 047 private CountStatisticImpl rejectedSessionCount; 048 049 private CountStatisticImpl expiredSessionCount; 050 051 public WebModuleStatsImpl() { 052 processingTime = new CountStatisticImpl("Processing Time", StatisticImpl.UNIT_TIME_MILLISECOND, 053 "Time to process all the requests ", 0); 054 startupTime = new CountStatisticImpl("Startup Time", StatisticImpl.UNIT_TIME_MILLISECOND, 055 "Time to start this application", 0); 056 tldScanTime = new CountStatisticImpl("TLD Scan Time", StatisticImpl.UNIT_TIME_MILLISECOND, 057 "Time to scan TLDs ", 0); 058 sessionAliveTime = new TimeStatisticImpl("Session Alive Time", StatisticImpl.UNIT_TIME_SECOND, 059 "The time for session"); 060 sessionCount = new CountStatisticImpl("Session Count", StatisticImpl.UNIT_COUNT, 061 "total number of sessions created ", 0); 062 activeSessionCount = new CountStatisticImpl("Active Session Count", StatisticImpl.UNIT_COUNT, 063 "currently active sessions ", 0); 064 rejectedSessionCount = new CountStatisticImpl("Rejected Session Count", StatisticImpl.UNIT_COUNT, 065 "rejected sessions ", 0); 066 expiredSessionCount = new CountStatisticImpl("Expired Session Count", StatisticImpl.UNIT_COUNT, 067 "expired sessions ", 0); 068 addStat("processingTime", processingTime); 069 addStat("startupTime", startupTime); 070 addStat("tldScanTime", tldScanTime); 071 addStat("sessionAliveTime", sessionAliveTime); // better name 072 addStat("sessionCount", sessionCount); 073 addStat("activeSessionCount", activeSessionCount); 074 addStat("rejectedSessionCount", rejectedSessionCount); 075 addStat("expiredSessionCount", expiredSessionCount); 076 } 077 078 public CountStatistic getProcessingTime() { 079 return processingTime; 080 } 081 082 public CountStatistic getStartupTime() { 083 return startupTime; 084 } 085 086 public CountStatistic getTldScanTime() { 087 return tldScanTime; 088 } 089 090 public TimeStatistic getSessionAliveTime() { 091 return sessionAliveTime; 092 } 093 094 public CountStatistic getSessionCount() { 095 return sessionCount; 096 } 097 098 public CountStatistic getActiveSessionCount() { 099 return activeSessionCount; 100 } 101 102 public CountStatistic getExpiredSessionCount() { 103 return expiredSessionCount; 104 } 105 106 public CountStatistic getRejectedSessionCount() { 107 return rejectedSessionCount; 108 } 109 110 /** 111 * These setters are used by native implementation 112 */ 113 114 public void setProcessingTime(long processingTime) { 115 this.processingTime.setCount(processingTime); 116 } 117 118 // This is static data, need not be refreshed 119 public void setStartupTime(long startupTime) { 120 this.startupTime.setCount(startupTime); 121 } 122 123 public void setTldScanTime(long tldScanTime) { 124 this.tldScanTime.setCount(tldScanTime); 125 } 126 127 public void setSessionAliveTime(int count, long minTime, long maxTime, long totalTime) { 128 this.sessionAliveTime.setCount(count); 129 this.sessionAliveTime.setMinTime(minTime); 130 this.sessionAliveTime.setMaxTime(maxTime); 131 this.sessionAliveTime.setTotalTime(totalTime); 132 } 133 134 public void setSessionCount(int sessionCount) { 135 this.sessionCount.setCount(sessionCount); 136 } 137 138 public void setActiveSessionCount(int activeSessionCount) { 139 this.activeSessionCount.setCount(activeSessionCount); 140 } 141 142 public void setExpiredSessionCount(int expiredSessionCount) { 143 this.expiredSessionCount.setCount(expiredSessionCount); 144 } 145 146 public void setRejectedSessionCount(int rejectedSessionCount) { 147 this.rejectedSessionCount.setCount(rejectedSessionCount); 148 } 149 150 // Is this needed ? 151 public void setLastSampleTime(long time) { 152 sessionAliveTime.setLastSampleTime(time); 153 activeSessionCount.setLastSampleTime(time); 154 expiredSessionCount.setLastSampleTime(time); 155 rejectedSessionCount.setLastSampleTime(time); 156 } 157 158 }