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:
018: import org.wings.util.SStringBuilder;
019:
020: /**
021: * @author <a href="mailto:@mueller.de">armin</a>
022: */
023: public class WingsStatistics {
024:
025: private static final WingsStatistics STATISTICS = new WingsStatistics();
026:
027: public static final WingsStatistics getStatistics() {
028: return STATISTICS;
029: }
030:
031: private int sessionCounter = 0;
032: private int activeSessionCounter = 0;
033: private int allocatedSessionCounter = 0;
034: private final long birthDay = System.currentTimeMillis();
035:
036: private int requestCounter = 0;
037: private long requestDuration = 0;
038:
039: public final int getRequestCount() {
040: return requestCounter;
041: }
042:
043: public final long getRequestDuration() {
044: return requestDuration;
045: }
046:
047: public final long getUptime() {
048: return System.currentTimeMillis() - birthDay;
049: }
050:
051: synchronized final void incrementRequestCount(long duration) {
052: requestCounter++;
053: requestDuration += duration;
054: }
055:
056: synchronized final void incrementSessionCount() {
057: sessionCounter++;
058: }
059:
060: synchronized final void incrementActiveSessionCount() {
061: activeSessionCounter++;
062: }
063:
064: synchronized final void incrementAllocatedSessionCount() {
065: allocatedSessionCounter++;
066: }
067:
068: synchronized final void decrementActiveSessionCount() {
069: activeSessionCounter--;
070: }
071:
072: synchronized final void decrementAllocatedSessionCount() {
073: allocatedSessionCounter--;
074: }
075:
076: public final int getOverallSessionCount() {
077: return sessionCounter;
078: }
079:
080: public final int getActiveSessionCount() {
081: return activeSessionCounter;
082: }
083:
084: public final int getAllocatedSessionCount() {
085: return allocatedSessionCounter;
086: }
087:
088: private int dispatchCounter = 0;
089: private long dispatchDuration = 0;
090:
091: private int deliverCounter = 0;
092: private long deliverDuration = 0;
093:
094: synchronized final void incrementDispatchCount(long duration) {
095: dispatchCounter++;
096: dispatchDuration += duration;
097: }
098:
099: synchronized final void incrementDeliverCount(long duration) {
100: deliverCounter++;
101: deliverDuration += duration;
102: }
103:
104: public final int getDispatchCount() {
105: return dispatchCounter;
106: }
107:
108: public final long getDispatchDuration() {
109: return dispatchDuration;
110: }
111:
112: public final int getDeliverCount() {
113: return deliverCounter;
114: }
115:
116: public final long getDeliverDuration() {
117: return deliverDuration;
118: }
119:
120: public final String toString() {
121: SStringBuilder tResult = new SStringBuilder();
122:
123: tResult.append("birthday: ").append(
124: DateFormat.getDateTimeInstance().format(
125: new Date(birthDay))).append("\n").append(
126: "sessions: ").append(sessionCounter).append(" / ")
127: .append(activeSessionCounter).append(" / ").append(
128: allocatedSessionCounter).append("\n").append(
129: "requests: ").append(requestCounter).append(
130: " / ").append(
131: requestCounter == 0 ? 0 : requestDuration
132: / requestCounter).append(" ms\n")
133: .append("dispatch: ").append(dispatchCounter).append(
134: " / ").append(
135: dispatchCounter == 0 ? 0 : dispatchDuration
136: / dispatchCounter).append(" ms\n")
137: .append("deliver: ").append(deliverCounter).append(
138: " / ").append(
139: deliverCounter == 0 ? 0 : deliverDuration
140: / deliverCounter).append(" ms\n");
141:
142: return tResult.toString();
143:
144: }
145: }
|