001: /*
002: * This software is released under a licence similar to the Apache Software Licence.
003: * See org.logicalcobwebs.proxool.package.html for details.
004: * The latest version is available at http://proxool.sourceforge.net
005: */
006: package org.logicalcobwebs.proxool.admin;
007:
008: import java.util.Date;
009:
010: /**
011: * Implementation of StatisticsIF
012: *
013: * @version $Revision: 1.2 $, $Date: 2003/03/03 11:11:59 $
014: * @author bill
015: * @author $Author: billhorsman $ (current maintainer)
016: * @since Proxool 0.7
017: */
018: class Statistics implements StatisticsIF {
019:
020: private Date startDate;
021:
022: private Date stopDate;
023:
024: private long servedCount;
025:
026: private long refusedCount;
027:
028: private long totalActiveTime;
029:
030: /**
031: * @param startDate see {@link org.logicalcobwebs.proxool.admin.StatisticsIF#getStartDate}
032: */
033: protected Statistics(Date startDate) {
034: this .startDate = startDate;
035: }
036:
037: /**
038: * @see org.logicalcobwebs.proxool.admin.Admin#connectionReturned
039: */
040: protected void connectionReturned(long activeTime) {
041: totalActiveTime += activeTime;
042: servedCount++;
043: }
044:
045: /**
046: * @see org.logicalcobwebs.proxool.admin.Admin#connectionRefused
047: */
048: protected void connectionRefused() {
049: refusedCount++;
050: }
051:
052: /**
053: * @see org.logicalcobwebs.proxool.admin.StatisticsIF#getStopDate
054: */
055: protected void setStopDate(Date stopDate) {
056: this .stopDate = stopDate;
057: }
058:
059: /**
060: * @see org.logicalcobwebs.proxool.admin.StatisticsIF#getStartDate
061: */
062: public Date getStartDate() {
063: return startDate;
064: }
065:
066: /**
067: * @see org.logicalcobwebs.proxool.admin.StatisticsIF#getStopDate
068: */
069: public Date getStopDate() {
070: return stopDate;
071: }
072:
073: /**
074: * @see org.logicalcobwebs.proxool.admin.StatisticsIF#getPeriod
075: */
076: public long getPeriod() {
077: if (stopDate != null) {
078: return stopDate.getTime() - startDate.getTime();
079: } else {
080: return System.currentTimeMillis() - startDate.getTime();
081: }
082: }
083:
084: /**
085: * @see org.logicalcobwebs.proxool.admin.StatisticsIF#getAverageActiveTime
086: */
087: public double getAverageActiveTime() {
088: if (servedCount > 0) {
089: return ((double) totalActiveTime / (double) servedCount);
090: } else {
091: return 0.0;
092: }
093: }
094:
095: /**
096: * @see org.logicalcobwebs.proxool.admin.StatisticsIF#getAverageActiveCount
097: */
098: public double getAverageActiveCount() {
099: return (double) totalActiveTime / (double) getPeriod();
100: }
101:
102: /**
103: * @see org.logicalcobwebs.proxool.admin.StatisticsIF#getServedPerSecond
104: */
105: public double getServedPerSecond() {
106: return (double) servedCount / ((double) getPeriod() / 1000.0);
107: }
108:
109: /**
110: * @see org.logicalcobwebs.proxool.admin.StatisticsIF#getRefusedPerSecond
111: */
112: public double getRefusedPerSecond() {
113: return (double) refusedCount / ((double) getPeriod() / 1000.0);
114: }
115:
116: /**
117: * @see org.logicalcobwebs.proxool.admin.StatisticsIF#getServedCount
118: */
119: public long getServedCount() {
120: return servedCount;
121: }
122:
123: /**
124: * @see org.logicalcobwebs.proxool.admin.StatisticsIF#getRefusedCount
125: */
126: public long getRefusedCount() {
127: return refusedCount;
128: }
129:
130: }
131:
132: /*
133: Revision history:
134: $Log: Statistics.java,v $
135: Revision 1.2 2003/03/03 11:11:59 billhorsman
136: fixed licence
137:
138: Revision 1.1 2003/02/19 23:36:51 billhorsman
139: renamed monitor package to admin
140:
141: Revision 1.3 2003/01/31 16:53:22 billhorsman
142: checkstyle
143:
144: Revision 1.2 2003/01/31 16:38:53 billhorsman
145: doc (and removing public modifier for classes where possible)
146:
147: Revision 1.1 2003/01/31 11:35:57 billhorsman
148: improvements to servlet (including connection details)
149:
150: Revision 1.1 2003/01/30 17:20:13 billhorsman
151: fixes, improvements and doc
152:
153: */
|