KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > wings > session > WingsStatistics


1 /*
2  * $Id: WingsStatistics.java,v 1.4 2004/12/01 07:54:27 hengels Exp $
3  * Copyright 2000,2005 wingS development team.
4  *
5  * This file is part of wingS (http://www.j-wings.org).
6  *
7  * wingS is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU Lesser General Public License
9  * as published by the Free Software Foundation; either version 2.1
10  * of the License, or (at your option) any later version.
11  *
12  * Please see COPYING for the complete licence.
13  */

14 package org.wings.session;
15
16 import java.text.DateFormat JavaDoc;
17 import java.util.Date JavaDoc;
18
19 /**
20  * @author <a HREF="mailto:@mueller.de">armin</a>
21  * @version $Revision: 1.4 $
22  */

23 public class WingsStatistics {
24
25     private static final WingsStatistics STATISTICS = new WingsStatistics();
26
27     public static final WingsStatistics getStatistics() {
28         return STATISTICS;
29     }
30
31     private int sessionCounter = 0;
32     private int activeSessionCounter = 0;
33     private int allocatedSessionCounter = 0;
34     private final long birthDay = System.currentTimeMillis();
35
36     private int requestCounter = 0;
37     private long requestDuration = 0;
38
39
40     public final int getRequestCount() {
41         return requestCounter;
42     }
43
44     public final long getRequestDuration() {
45         return requestDuration;
46     }
47
48     public final long getUptime() {
49         return System.currentTimeMillis() - birthDay;
50     }
51
52     synchronized final void incrementRequestCount(long duration) {
53         requestCounter++;
54         requestDuration += duration;
55     }
56
57     synchronized final void incrementSessionCount() {
58         sessionCounter++;
59     }
60
61     synchronized final void incrementActiveSessionCount() {
62         activeSessionCounter++;
63     }
64
65     synchronized final void incrementAllocatedSessionCount() {
66         allocatedSessionCounter++;
67     }
68
69     synchronized final void decrementActiveSessionCount() {
70         activeSessionCounter--;
71     }
72
73     synchronized final void decrementAllocatedSessionCount() {
74         allocatedSessionCounter--;
75     }
76
77
78     public final int getOverallSessionCount() {
79         return sessionCounter;
80     }
81
82     public final int getActiveSessionCount() {
83         return activeSessionCounter;
84     }
85
86     public final int getAllocatedSessionCount() {
87         return allocatedSessionCounter;
88     }
89
90
91     private int dispatchCounter = 0;
92     private long dispatchDuration = 0;
93
94     private int deliverCounter = 0;
95     private long deliverDuration = 0;
96
97
98     synchronized final void incrementDispatchCount(long duration) {
99         dispatchCounter++;
100         dispatchDuration += duration;
101     }
102
103     synchronized final void incrementDeliverCount(long duration) {
104         deliverCounter++;
105         deliverDuration += duration;
106     }
107
108
109     public final int getDispatchCount() {
110         return dispatchCounter;
111     }
112
113     public final long getDispatchDuration() {
114         return dispatchDuration;
115     }
116
117     public final int getDeliverCount() {
118         return deliverCounter;
119     }
120
121     public final long getDeliverDuration() {
122         return deliverDuration;
123     }
124
125     public final String JavaDoc toString() {
126         StringBuffer JavaDoc tResult = new StringBuffer JavaDoc();
127
128         tResult.append("birthday: ").append(DateFormat.getDateTimeInstance().format(new Date JavaDoc(birthDay))).append("\n")
129                 .append("sessions: ").append(sessionCounter).append(" / ").append(activeSessionCounter).append(" / ").append(allocatedSessionCounter).append("\n")
130                 .append("requests: ").append(requestCounter).append(" / ").append(requestCounter == 0 ? 0 : requestDuration / requestCounter).append(" ms\n")
131                 .append("dispatch: ").append(dispatchCounter).append(" / ").append(dispatchCounter == 0 ? 0 : dispatchDuration / dispatchCounter).append(" ms\n")
132                 .append("deliver: ").append(deliverCounter).append(" / ").append(deliverCounter == 0 ? 0 : deliverDuration / deliverCounter).append(" ms\n");
133
134         return tResult.toString();
135
136     }
137 }
138
Popular Tags