001: /*
002: * Copyright 1999-2004 The Apache Software Foundation
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016:
017: package org.apache.coyote;
018:
019: import java.util.ArrayList;
020:
021: /** This can be moved to top level ( eventually with a better name ).
022: * It is currently used only as a JMX artifact, to agregate the data
023: * collected from each RequestProcessor thread.
024: */
025: public class RequestGroupInfo {
026: ArrayList processors = new ArrayList();
027: private long deadMaxTime = 0;
028: private long deadProcessingTime = 0;
029: private int deadRequestCount = 0;
030: private int deadErrorCount = 0;
031: private long deadBytesReceived = 0;
032: private long deadBytesSent = 0;
033:
034: public synchronized void addRequestProcessor(RequestInfo rp) {
035: processors.add(rp);
036: }
037:
038: public synchronized void removeRequestProcessor(RequestInfo rp) {
039: if (rp != null) {
040: if (deadMaxTime < rp.getMaxTime())
041: deadMaxTime = rp.getMaxTime();
042: deadProcessingTime += rp.getProcessingTime();
043: deadRequestCount += rp.getRequestCount();
044: deadErrorCount += rp.getErrorCount();
045: deadBytesReceived += rp.getBytesReceived();
046: deadBytesSent += rp.getBytesSent();
047:
048: processors.remove(rp);
049: }
050: }
051:
052: public synchronized long getMaxTime() {
053: long maxTime = deadMaxTime;
054: for (int i = 0; i < processors.size(); i++) {
055: RequestInfo rp = (RequestInfo) processors.get(i);
056: if (maxTime < rp.getMaxTime())
057: maxTime = rp.getMaxTime();
058: }
059: return maxTime;
060: }
061:
062: // Used to reset the times
063: public synchronized void setMaxTime(long maxTime) {
064: deadMaxTime = maxTime;
065: for (int i = 0; i < processors.size(); i++) {
066: RequestInfo rp = (RequestInfo) processors.get(i);
067: rp.setMaxTime(maxTime);
068: }
069: }
070:
071: public synchronized long getProcessingTime() {
072: long time = deadProcessingTime;
073: for (int i = 0; i < processors.size(); i++) {
074: RequestInfo rp = (RequestInfo) processors.get(i);
075: time += rp.getProcessingTime();
076: }
077: return time;
078: }
079:
080: public synchronized void setProcessingTime(long totalTime) {
081: deadProcessingTime = totalTime;
082: for (int i = 0; i < processors.size(); i++) {
083: RequestInfo rp = (RequestInfo) processors.get(i);
084: rp.setProcessingTime(totalTime);
085: }
086: }
087:
088: public synchronized int getRequestCount() {
089: int requestCount = deadRequestCount;
090: for (int i = 0; i < processors.size(); i++) {
091: RequestInfo rp = (RequestInfo) processors.get(i);
092: requestCount += rp.getRequestCount();
093: }
094: return requestCount;
095: }
096:
097: public synchronized void setRequestCount(int requestCount) {
098: deadRequestCount = requestCount;
099: for (int i = 0; i < processors.size(); i++) {
100: RequestInfo rp = (RequestInfo) processors.get(i);
101: rp.setRequestCount(requestCount);
102: }
103: }
104:
105: public synchronized int getErrorCount() {
106: int requestCount = deadErrorCount;
107: for (int i = 0; i < processors.size(); i++) {
108: RequestInfo rp = (RequestInfo) processors.get(i);
109: requestCount += rp.getErrorCount();
110: }
111: return requestCount;
112: }
113:
114: public synchronized void setErrorCount(int errorCount) {
115: deadErrorCount = errorCount;
116: for (int i = 0; i < processors.size(); i++) {
117: RequestInfo rp = (RequestInfo) processors.get(i);
118: rp.setErrorCount(errorCount);
119: }
120: }
121:
122: public synchronized long getBytesReceived() {
123: long bytes = deadBytesReceived;
124: for (int i = 0; i < processors.size(); i++) {
125: RequestInfo rp = (RequestInfo) processors.get(i);
126: bytes += rp.getBytesReceived();
127: }
128: return bytes;
129: }
130:
131: public synchronized void setBytesReceived(long bytesReceived) {
132: deadBytesReceived = bytesReceived;
133: for (int i = 0; i < processors.size(); i++) {
134: RequestInfo rp = (RequestInfo) processors.get(i);
135: rp.setBytesReceived(bytesReceived);
136: }
137: }
138:
139: public synchronized long getBytesSent() {
140: long bytes = deadBytesSent;
141: for (int i = 0; i < processors.size(); i++) {
142: RequestInfo rp = (RequestInfo) processors.get(i);
143: bytes += rp.getBytesSent();
144: }
145: return bytes;
146: }
147:
148: public synchronized void setBytesSent(long bytesSent) {
149: deadBytesSent = bytesSent;
150: for (int i = 0; i < processors.size(); i++) {
151: RequestInfo rp = (RequestInfo) processors.get(i);
152: rp.setBytesSent(bytesSent);
153: }
154: }
155:
156: public void resetCounters() {
157: this .setBytesReceived(0);
158: this .setBytesSent(0);
159: this .setRequestCount(0);
160: this .setProcessingTime(0);
161: this .setMaxTime(0);
162: this .setErrorCount(0);
163: }
164: }
|