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