001: //========================================================================
002: //$Id: TimeStatisticImpl.java 1195 2006-11-12 23:02:51Z janb $
003: //Copyright 200-2004 Mort Bay Consulting Pty. Ltd.
004: //------------------------------------------------------------------------
005: //Licensed under the Apache License, Version 2.0 (the "License");
006: //you may not use this file except in compliance with the License.
007: //You may obtain a copy of the License at
008: //http://www.apache.org/licenses/LICENSE-2.0
009: //Unless required by applicable law or agreed to in writing, software
010: //distributed under the License is distributed on an "AS IS" BASIS,
011: //WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012: //See the License for the specific language governing permissions and
013: //limitations under the License.
014: //========================================================================
015: package org.mortbay.jetty.servlet.jsr77;
016:
017: /**
018: * @author janb
019: *
020: * To change the template for this generated type comment go to
021: * Window - Preferences - Java - Code Generation - Code and Comments
022: */
023: public class TimeStatisticImpl implements
024: javax.management.j2ee.statistics.TimeStatistic {
025:
026: private static final String HOUR = "HOUR";
027: private static final String MICROSECOND = "MICROSECOND";
028: private static final String MILLISECONDS = "MILLISECONDS";
029: private static final String MINUTE = "MINUTE";
030: private static final String NANOSECOND = "NANOSECOND";
031: private static final String SECOND = "SECOND";
032: private ServletStatsImpl servletStats = null;
033: private long count = 0;
034: private long maxTime = 0;
035: private long minTime = 0;
036: private long totalTime = 0;
037: private long startTime = 0;
038: private long lastSampleTime = 0;
039: private String name = null;
040: private String description = null;
041: private String units = null;
042:
043: public TimeStatisticImpl(ServletStatsImpl servletStats,
044: String name, String description, String unit) {
045: setServletStats(servletStats);
046: setName(name);
047: setDescription(description);
048: setUnit(unit);
049: }
050:
051: /** Return number of times statistic has been gathered.
052: * @see javax.management.j2ee.statistics.TimeStatistic#getCount()
053: */
054: public long getCount() {
055: return count;
056: }
057:
058: /** Return max value of statistic.
059: * @see javax.management.j2ee.statistics.TimeStatistic#getMaxTime()
060: */
061: public long getMaxTime() {
062: return maxTime;
063: }
064:
065: /** Return min value of statistic.
066: * @see javax.management.j2ee.statistics.TimeStatistic#getMinTime()
067: */
068: public long getMinTime() {
069: return minTime;
070: }
071:
072: /** Return total time of statistic
073: * @see javax.management.j2ee.statistics.TimeStatistic#getTotalTime()
074: */
075: public long getTotalTime() {
076: return totalTime;
077: }
078:
079: /** Return name of statistic
080: * @see javax.management.j2ee.statistics.Statistic#getName()
081: */
082: public String getName() {
083: return name;
084: }
085:
086: public void setName(String n) {
087: name = n;
088: }
089:
090: /** Return units of statistic
091: * @see javax.management.j2ee.statistics.Statistic#getUnit()
092: */
093: public String getUnit() {
094: return units;
095: }
096:
097: public void setUnit(String u) {
098: units = u;
099: }
100:
101: /** Human readable description of statistic
102: * @see javax.management.j2ee.statistics.Statistic#getDescription()
103: */
104: public String getDescription() {
105: return description;
106: }
107:
108: public void setDescription(String s) {
109: description = s;
110: }
111:
112: /** Get the time the statistic began to be gathered.
113: * As milliseconds since the last epoch.
114: * @see javax.management.j2ee.statistics.Statistic#getStartTime()
115: */
116: public long getStartTime() {
117: return startTime;
118: }
119:
120: public void setStartTime() {
121: startTime = System.currentTimeMillis();
122: }
123:
124: /** Get the time of the last sample.
125: * As milliseconds since the epoch.
126: * @see javax.management.j2ee.statistics.Statistic#getLastSampleTime()
127: */
128: public long getLastSampleTime() {
129: return lastSampleTime;
130: }
131:
132: public void setServletStats(ServletStatsImpl stats) {
133: servletStats = stats;
134: }
135:
136: public synchronized void addSample(long sample, long time) {
137: count++;
138: if (sample > maxTime)
139: maxTime = sample;
140: if ((sample < minTime) || (minTime == 0))
141: minTime = sample;
142: lastSampleTime = time;
143: totalTime = totalTime + sample;
144: }
145:
146: public String toString() {
147: return "Name=" + getName() + ", Description="
148: + getDescription() + ", Units=" + getUnit()
149: + ", StartTime=" + getStartTime() + ", Count="
150: + getCount() + ", MinTime=" + getMinTime()
151: + ", MaxTime=" + getMaxTime() + ", TotalTime="
152: + getTotalTime() + ", LastSampleTime="
153: + getLastSampleTime();
154: }
155:
156: }
|