1
17 package org.apache.coyote;
18
19 import java.util.ArrayList;
20 import java.util.List;
21
22 import org.apache.tomcat.util.modeler.BaseModelMBean;
23
24
28 public class RequestGroupInfo extends BaseModelMBean {
29 private final List<RequestInfo> processors = new ArrayList<>();
30 private long deadMaxTime = 0;
31 private long deadProcessingTime = 0;
32 private int deadRequestCount = 0;
33 private int deadErrorCount = 0;
34 private long deadBytesReceived = 0;
35 private long deadBytesSent = 0;
36
37 public synchronized void addRequestProcessor( RequestInfo rp ) {
38 processors.add( rp );
39 }
40
41 public synchronized void removeRequestProcessor( RequestInfo rp ) {
42 if( rp != null ) {
43 if( deadMaxTime < rp.getMaxTime() )
44 deadMaxTime = rp.getMaxTime();
45 deadProcessingTime += rp.getProcessingTime();
46 deadRequestCount += rp.getRequestCount();
47 deadErrorCount += rp.getErrorCount();
48 deadBytesReceived += rp.getBytesReceived();
49 deadBytesSent += rp.getBytesSent();
50
51 processors.remove( rp );
52 }
53 }
54
55 public synchronized long getMaxTime() {
56 long maxTime = deadMaxTime;
57 for (RequestInfo rp : processors) {
58 if (maxTime < rp.getMaxTime()) {
59 maxTime=rp.getMaxTime();
60 }
61 }
62 return maxTime;
63 }
64
65
66 public synchronized void setMaxTime(long maxTime) {
67 deadMaxTime = maxTime;
68 for (RequestInfo rp : processors) {
69 rp.setMaxTime(maxTime);
70 }
71 }
72
73 public synchronized long getProcessingTime() {
74 long time = deadProcessingTime;
75 for (RequestInfo rp : processors) {
76 time += rp.getProcessingTime();
77 }
78 return time;
79 }
80
81 public synchronized void setProcessingTime(long totalTime) {
82 deadProcessingTime = totalTime;
83 for (RequestInfo rp : processors) {
84 rp.setProcessingTime( totalTime );
85 }
86 }
87
88 public synchronized int getRequestCount() {
89 int requestCount = deadRequestCount;
90 for (RequestInfo rp : processors) {
91 requestCount += rp.getRequestCount();
92 }
93 return requestCount;
94 }
95
96 public synchronized void setRequestCount(int requestCount) {
97 deadRequestCount = requestCount;
98 for (RequestInfo rp : processors) {
99 rp.setRequestCount( requestCount );
100 }
101 }
102
103 public synchronized int getErrorCount() {
104 int requestCount = deadErrorCount;
105 for (RequestInfo rp : processors) {
106 requestCount += rp.getErrorCount();
107 }
108 return requestCount;
109 }
110
111 public synchronized void setErrorCount(int errorCount) {
112 deadErrorCount = errorCount;
113 for (RequestInfo rp : processors) {
114 rp.setErrorCount( errorCount);
115 }
116 }
117
118 public synchronized long getBytesReceived() {
119 long bytes = deadBytesReceived;
120 for (RequestInfo rp : processors) {
121 bytes += rp.getBytesReceived();
122 }
123 return bytes;
124 }
125
126 public synchronized void setBytesReceived(long bytesReceived) {
127 deadBytesReceived = bytesReceived;
128 for (RequestInfo rp : processors) {
129 rp.setBytesReceived( bytesReceived );
130 }
131 }
132
133 public synchronized long getBytesSent() {
134 long bytes=deadBytesSent;
135 for (RequestInfo rp : processors) {
136 bytes += rp.getBytesSent();
137 }
138 return bytes;
139 }
140
141 public synchronized void setBytesSent(long bytesSent) {
142 deadBytesSent = bytesSent;
143 for (RequestInfo rp : processors) {
144 rp.setBytesSent( bytesSent );
145 }
146 }
147
148 public void resetCounters() {
149 this.setBytesReceived(0);
150 this.setBytesSent(0);
151 this.setRequestCount(0);
152 this.setProcessingTime(0);
153 this.setMaxTime(0);
154 this.setErrorCount(0);
155 }
156 }
157