/* * 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 java.util.concurrent.TimeUnit;
import javax.management.ObjectName;
/** * Structure holding the Request and Response objects. It also holds statistical information about request processing * and provide management information 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 ). * * @author Costin Manolache
*/ publicclass RequestInfo { private RequestGroupInfo global = null;
public String getRemoteAddr() {
req.action(ActionCode.REQ_HOST_ADDR_ATTRIBUTE, null); return req.remoteAddr().toString();
}
public String getPeerAddr() {
req.action(ActionCode.REQ_PEER_ADDR_ATTRIBUTE, null); return req.peerAddr().toString();
}
/** * Obtain the remote address for this connection as reported by an intermediate proxy (if any). * * @return The remote address for the this connection
*/ public String getRemoteAddrForwarded() {
String remoteAddrProxy = (String) req.getAttribute(Constants.REMOTE_ADDR_ATTRIBUTE); if (remoteAddrProxy == null) { return getRemoteAddr();
} return remoteAddrProxy;
}
publiclong getRequestProcessingTime() { // Not perfect, but good enough to avoid returning strange values due to // concurrent updates. long startTime = req.getStartTimeNanos(); if (getStage() == Constants.STAGE_ENDED || startTime < 0) { return 0;
} else { return TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - startTime);
}
}
// -------------------- Statistical data -------------------- // Collected at the end of each request. privatelong bytesSent; privatelong bytesReceived;
// Total time = divide by requestCount to get average. privatelong processingTime; // The longest response time for a request privatelong maxTime; // URI of the request that took maxTime private String maxRequestUri;
privateint requestCount; // number of response codes >= 400 privateint errorCount;
// the time of the last request privatelong 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 time = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - req.getStartTimeNanos()); this.lastRequestProcessingTime = time;
processingTime += time; if (maxTime < time) {
maxTime = time;
maxRequestUri = req.requestURI().toString();
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.