1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258
|
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.coyote;
import javax.management.ObjectName;
/**
* Structure holding the Request and Response objects. It also holds statistical
* informations about request processing and provide management informations
* about the requests being processed.
*
* Each thread uses a Request/Response pair that is recycled on each request.
* This object provides a place to collect global low-level statistics - without
* having to deal with synchronization ( since each thread will have it's own
* RequestProcessorMX ).
*
* TODO: Request notifications will be registered here.
*
* @author Costin Manolache
*/
public class RequestInfo {
RequestGroupInfo global=null;
// ----------------------------------------------------------- Constructors
public RequestInfo( Request req) {
this.req=req;
}
public RequestGroupInfo getGlobalProcessor() {
return global;
}
public void setGlobalProcessor(RequestGroupInfo global) {
if( global != null) {
this.global=global;
global.addRequestProcessor( this );
} else {
if (this.global != null) {
this.global.removeRequestProcessor( this );
this.global = null;
}
}
}
// ----------------------------------------------------- Instance Variables
Request req;
int stage = Constants.STAGE_NEW;
String workerThreadName;
ObjectName rpName;
// -------------------- Information about the current request -----------
// This is useful for long-running requests only
public String getMethod() {
return req.method().toString();
}
public String getCurrentUri() {
return req.requestURI().toString();
}
public String getCurrentQueryString() {
return req.queryString().toString();
}
public String getProtocol() {
return req.protocol().toString();
}
public String getVirtualHost() {
return req.serverName().toString();
}
public int getServerPort() {
return req.getServerPort();
}
public String getRemoteAddr() {
req.action(ActionCode.REQ_HOST_ADDR_ATTRIBUTE, null);
return req.remoteAddr().toString();
}
/**
* Obtain the remote address for this connection as reported by an
* intermediate proxy (if any).
*/
public String getRemoteAddrForwarded() {
String remoteAddrProxy = (String) req.getAttribute(Constants.REMOTE_ADDR_ATTRIBUTE);
if (remoteAddrProxy == null) {
return getRemoteAddr();
}
return remoteAddrProxy;
}
public int getContentLength() {
return req.getContentLength();
}
public long getRequestBytesReceived() {
return req.getBytesRead();
}
public long getRequestBytesSent() {
return req.getResponse().getContentWritten();
}
public long getRequestProcessingTime() {
if ( getStage() == org.apache.coyote.Constants.STAGE_ENDED ) return 0;
else return (System.currentTimeMillis() - req.getStartTime());
}
// -------------------- Statistical data --------------------
// Collected at the end of each request.
private long bytesSent;
private long bytesReceived;
// Total time = divide by requestCount to get average.
private long processingTime;
// The longest response time for a request
private long maxTime;
// URI of the request that took maxTime
private String maxRequestUri;
private int requestCount;
// number of response codes >= 400
private int errorCount;
//the time of the last request
private long lastRequestProcessingTime = 0;
/** Called by the processor before recycling the request. It'll collect
* statistic information.
*/
void updateCounters() {
bytesReceived+=req.getBytesRead();
bytesSent+=req.getResponse().getContentWritten();
requestCount++;
if( req.getResponse().getStatus() >=400 )
errorCount++;
long t0=req.getStartTime();
long t1=System.currentTimeMillis();
long time=t1-t0;
this.lastRequestProcessingTime = time;
processingTime+=time;
if( maxTime < time ) {
maxTime=time;
maxRequestUri=req.requestURI().toString();
}
}
public int getStage() {
return stage;
}
public void setStage(int stage) {
this.stage = stage;
}
public long getBytesSent() {
return bytesSent;
}
public void setBytesSent(long bytesSent) {
this.bytesSent = bytesSent;
}
public long getBytesReceived() {
return bytesReceived;
}
public void setBytesReceived(long bytesReceived) {
this.bytesReceived = bytesReceived;
}
public long getProcessingTime() {
return processingTime;
}
public void setProcessingTime(long processingTime) {
this.processingTime = processingTime;
}
public long getMaxTime() {
return maxTime;
}
public void setMaxTime(long maxTime) {
this.maxTime = maxTime;
}
public String getMaxRequestUri() {
return maxRequestUri;
}
public void setMaxRequestUri(String maxRequestUri) {
this.maxRequestUri = maxRequestUri;
}
public int getRequestCount() {
return requestCount;
}
public void setRequestCount(int requestCount) {
this.requestCount = requestCount;
}
public int getErrorCount() {
return errorCount;
}
public void setErrorCount(int errorCount) {
this.errorCount = errorCount;
}
public String getWorkerThreadName() {
return workerThreadName;
}
public ObjectName getRpName() {
return rpName;
}
public long getLastRequestProcessingTime() {
return lastRequestProcessingTime;
}
public void setWorkerThreadName(String workerThreadName) {
this.workerThreadName = workerThreadName;
}
public void setRpName(ObjectName rpName) {
this.rpName = rpName;
}
public void setLastRequestProcessingTime(long lastRequestProcessingTime) {
this.lastRequestProcessingTime = lastRequestProcessingTime;
}
}
|