001: /*
002: * Copyright 2000,2005 wingS development team.
003: *
004: * This file is part of wingS (http://wingsframework.org).
005: *
006: * wingS is free software; you can redistribute it and/or modify
007: * it under the terms of the GNU Lesser General Public License
008: * as published by the Free Software Foundation; either version 2.1
009: * of the License, or (at your option) any later version.
010: *
011: * Please see COPYING for the complete licence.
012: */
013: package org.wings.session;
014:
015: import java.text.DateFormat;
016: import java.util.Date;
017: import java.io.Serializable;
018:
019: import org.wings.util.SStringBuilder;
020:
021: /**
022: * @author <a href="mailto:@mueller.de">armin</a>
023: */
024: public class SessionStatistics implements Serializable {
025:
026: private final long birthDay = System.currentTimeMillis();
027:
028: private long dispatchStartTime = 0;
029: private int dispatchCounter = 0;
030: private long dispatchDuration = 0;
031:
032: private long deliverStartTime = 0;
033: private int deliverCounter = 0;
034: private long deliverDuration = 0;
035:
036: private long requestStartTime = 0;
037: private int requestCounter = 0;
038: private long requestDuration = 0;
039:
040: public final long getBirthDay() {
041: return birthDay;
042: }
043:
044: public final long getUptime() {
045: return System.currentTimeMillis() - birthDay;
046: }
047:
048: final void startRequest() {
049: requestStartTime = System.currentTimeMillis();
050: }
051:
052: final void endRequest() {
053: endDispatching();
054: endDelivering();
055: if (requestStartTime > 0) {
056: long duration = System.currentTimeMillis()
057: - requestStartTime;
058: WingsStatistics.getStatistics().incrementRequestCount(
059: duration);
060:
061: requestCounter++;
062: requestDuration += duration;
063: requestStartTime = -1;
064: }
065: }
066:
067: public final long getRequestCount() {
068: return requestCounter;
069: }
070:
071: public final long getRequestDuration() {
072: return requestDuration;
073: }
074:
075: final void startDispatching() {
076: dispatchStartTime = System.currentTimeMillis();
077: }
078:
079: final void endDispatching() {
080: if (dispatchStartTime > 0) {
081: long duration = System.currentTimeMillis()
082: - dispatchStartTime;
083: WingsStatistics.getStatistics().incrementDispatchCount(
084: duration);
085:
086: dispatchCounter++;
087: dispatchDuration += duration;
088: dispatchStartTime = -1;
089: }
090: }
091:
092: public final int getDispatchCount() {
093: return dispatchCounter;
094: }
095:
096: public final long getDispatchDuration() {
097: return dispatchDuration;
098: }
099:
100: final void startDelivering() {
101: deliverStartTime = System.currentTimeMillis();
102: }
103:
104: final void endDelivering() {
105: if (deliverStartTime > 0) {
106: long duration = System.currentTimeMillis()
107: - deliverStartTime;
108: WingsStatistics.getStatistics().incrementDeliverCount(
109: duration);
110:
111: deliverCounter++;
112: deliverDuration += duration;
113: deliverStartTime = -1;
114: }
115: }
116:
117: public final int getDeliverCount() {
118: return deliverCounter;
119: }
120:
121: public final long getDeliverDuration() {
122: return deliverDuration;
123: }
124:
125: public String toString() {
126: SStringBuilder tResult = new SStringBuilder();
127:
128: tResult.append("birthday: ").append(
129: DateFormat.getDateTimeInstance().format(
130: new Date(birthDay))).append("\n").append(
131: "requests: ").append(requestCounter).append(" / ")
132: .append(
133: requestCounter == 0 ? 0 : requestDuration
134: / requestCounter).append(" ms\n")
135: .append("dispatch: ").append(dispatchCounter).append(
136: " / ").append(
137: dispatchCounter == 0 ? 0 : dispatchDuration
138: / dispatchCounter).append(" ms\n")
139: .append("deliver: ").append(deliverCounter).append(
140: " / ").append(
141: deliverCounter == 0 ? 0 : deliverDuration
142: / deliverCounter).append(" ms\n");
143:
144: return tResult.toString();
145: }
146: }
|