1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18 package org.apache.coyote;
19
20 import java.util.ArrayList;
21
22 /** This can be moved to top level ( eventually with a better name ).
23 * It is currently used only as a JMX artifact, to agregate the data
24 * collected from each RequestProcessor thread.
25 */
26 public class RequestGroupInfo {
27 ArrayList processors=new ArrayList();
28 private long deadMaxTime = 0;
29 private long deadProcessingTime = 0;
30 private int deadRequestCount = 0;
31 private int deadErrorCount = 0;
32 private long deadBytesReceived = 0;
33 private long deadBytesSent = 0;
34
35 public synchronized void addRequestProcessor( RequestInfo rp ) {
36 processors.add( rp );
37 }
38
39 public synchronized void removeRequestProcessor( RequestInfo rp ) {
40 if( rp != null ) {
41 if( deadMaxTime < rp.getMaxTime() )
42 deadMaxTime = rp.getMaxTime();
43 deadProcessingTime += rp.getProcessingTime();
44 deadRequestCount += rp.getRequestCount();
45 deadErrorCount += rp.getErrorCount();
46 deadBytesReceived += rp.getBytesReceived();
47 deadBytesSent += rp.getBytesSent();
48
49 processors.remove( rp );
50 }
51 }
52
53 public synchronized long getMaxTime() {
54 long maxTime=deadMaxTime;
55 for( int i=0; i<processors.size(); i++ ) {
56 RequestInfo rp=(RequestInfo)processors.get( i );
57 if( maxTime < rp.getMaxTime() ) maxTime=rp.getMaxTime();
58 }
59 return maxTime;
60 }
61
62 // Used to reset the times
63 public synchronized void setMaxTime(long maxTime) {
64 deadMaxTime = maxTime;
65 for( int i=0; i<processors.size(); i++ ) {
66 RequestInfo rp=(RequestInfo)processors.get( i );
67 rp.setMaxTime(maxTime);
68 }
69 }
70
71 public synchronized long getProcessingTime() {
72 long time=deadProcessingTime;
73 for( int i=0; i<processors.size(); i++ ) {
74 RequestInfo rp=(RequestInfo)processors.get( i );
75 time += rp.getProcessingTime();
76 }
77 return time;
78 }
79
80 public synchronized void setProcessingTime(long totalTime) {
81 deadProcessingTime = totalTime;
82 for( int i=0; i<processors.size(); i++ ) {
83 RequestInfo rp=(RequestInfo)processors.get( i );
84 rp.setProcessingTime( totalTime );
85 }
86 }
87
88 public synchronized int getRequestCount() {
89 int requestCount=deadRequestCount;
90 for( int i=0; i<processors.size(); i++ ) {
91 RequestInfo rp=(RequestInfo)processors.get( i );
92 requestCount += rp.getRequestCount();
93 }
94 return requestCount;
95 }
96
97 public synchronized void setRequestCount(int requestCount) {
98 deadRequestCount = requestCount;
99 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 }