KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > logicalcobwebs > proxool > admin > Statistics


1 /*
2  * This software is released under a licence similar to the Apache Software Licence.
3  * See org.logicalcobwebs.proxool.package.html for details.
4  * The latest version is available at http://proxool.sourceforge.net
5  */

6 package org.logicalcobwebs.proxool.admin;
7
8 import java.util.Date JavaDoc;
9
10 /**
11  * Implementation of StatisticsIF
12  *
13  * @version $Revision: 1.2 $, $Date: 2003/03/03 11:11:59 $
14  * @author bill
15  * @author $Author: billhorsman $ (current maintainer)
16  * @since Proxool 0.7
17  */

18 class Statistics implements StatisticsIF {
19
20     private Date JavaDoc startDate;
21
22     private Date JavaDoc stopDate;
23
24     private long servedCount;
25
26     private long refusedCount;
27
28     private long totalActiveTime;
29
30     /**
31      * @param startDate see {@link org.logicalcobwebs.proxool.admin.StatisticsIF#getStartDate}
32      */

33     protected Statistics(Date JavaDoc startDate) {
34         this.startDate = startDate;
35     }
36
37     /**
38      * @see org.logicalcobwebs.proxool.admin.Admin#connectionReturned
39      */

40     protected void connectionReturned(long activeTime) {
41         totalActiveTime += activeTime;
42         servedCount++;
43     }
44
45     /**
46      * @see org.logicalcobwebs.proxool.admin.Admin#connectionRefused
47      */

48     protected void connectionRefused() {
49         refusedCount++;
50     }
51
52     /**
53      * @see org.logicalcobwebs.proxool.admin.StatisticsIF#getStopDate
54      */

55     protected void setStopDate(Date JavaDoc stopDate) {
56         this.stopDate = stopDate;
57     }
58
59     /**
60      * @see org.logicalcobwebs.proxool.admin.StatisticsIF#getStartDate
61      */

62     public Date JavaDoc getStartDate() {
63         return startDate;
64     }
65
66     /**
67      * @see org.logicalcobwebs.proxool.admin.StatisticsIF#getStopDate
68      */

69     public Date JavaDoc getStopDate() {
70         return stopDate;
71     }
72
73     /**
74      * @see org.logicalcobwebs.proxool.admin.StatisticsIF#getPeriod
75      */

76     public long getPeriod() {
77         if (stopDate != null) {
78             return stopDate.getTime() - startDate.getTime();
79         } else {
80             return System.currentTimeMillis() - startDate.getTime();
81         }
82     }
83
84     /**
85      * @see org.logicalcobwebs.proxool.admin.StatisticsIF#getAverageActiveTime
86      */

87     public double getAverageActiveTime() {
88         if (servedCount > 0) {
89             return ((double) totalActiveTime / (double) servedCount);
90         } else {
91             return 0.0;
92         }
93     }
94
95     /**
96      * @see org.logicalcobwebs.proxool.admin.StatisticsIF#getAverageActiveCount
97      */

98     public double getAverageActiveCount() {
99         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 /*
134  Revision history:
135  $Log: Statistics.java,v $
136  Revision 1.2 2003/03/03 11:11:59 billhorsman
137  fixed licence
138
139  Revision 1.1 2003/02/19 23:36:51 billhorsman
140  renamed monitor package to admin
141
142  Revision 1.3 2003/01/31 16:53:22 billhorsman
143  checkstyle
144
145  Revision 1.2 2003/01/31 16:38:53 billhorsman
146  doc (and removing public modifier for classes where possible)
147
148  Revision 1.1 2003/01/31 11:35:57 billhorsman
149  improvements to servlet (including connection details)
150
151  Revision 1.1 2003/01/30 17:20:13 billhorsman
152  fixes, improvements and doc
153
154  */
Popular Tags