01: //========================================================================
02: //$Id: Jsr77ServletHolder.java 1216 2006-11-14 14:53:40Z janb $
03: //Copyright 2006 Mort Bay Consulting Pty. Ltd.
04: //------------------------------------------------------------------------
05: //Licensed under the Apache License, Version 2.0 (the "License");
06: //you may not use this file except in compliance with the License.
07: //You may obtain a copy of the License at
08: //http://www.apache.org/licenses/LICENSE-2.0
09: //Unless required by applicable law or agreed to in writing, software
10: //distributed under the License is distributed on an "AS IS" BASIS,
11: //WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12: //See the License for the specific language governing permissions and
13: //limitations under the License.
14: //========================================================================
15:
16: package org.mortbay.jetty.servlet.jsr77;
17:
18: import java.io.IOException;
19: import java.util.Map;
20:
21: import javax.servlet.Servlet;
22: import javax.servlet.ServletException;
23: import javax.servlet.ServletRequest;
24: import javax.servlet.ServletResponse;
25: import javax.servlet.UnavailableException;
26:
27: import org.mortbay.jetty.servlet.ServletHolder;
28: import org.mortbay.jetty.webapp.WebAppContext;
29:
30: public class Jsr77ServletHolder extends ServletHolder {
31:
32: private ServletStatsImpl _servletStats = null;
33: private WebAppContext _webAppContext = null;
34:
35: public Jsr77ServletHolder() {
36: }
37:
38: public Jsr77ServletHolder(Servlet servlet) {
39: super (servlet);
40: }
41:
42: public Jsr77ServletHolder(Class servlet) {
43: super (servlet);
44: }
45:
46: public WebAppContext getWebAppContext() {
47: return _webAppContext;
48: }
49:
50: public void setWebAppContext(WebAppContext wac) {
51: _webAppContext = wac;
52: }
53:
54: public void doStart() throws Exception {
55: super .doStart();
56: _servletStats = new ServletStatsImpl(getName());
57: }
58:
59: public void handle(ServletRequest request, ServletResponse response)
60: throws ServletException, UnavailableException, IOException {
61: long startTime = 0L;
62: long endTime = 0L;
63: try {
64: //start statistic gathering - get the name of Servlet for which this filter will apply, and therefore
65: //on whose behalf we are gathering statistics???
66: startTime = System.currentTimeMillis();
67: super .handle(request, response);
68: } finally {
69: //finish statistic gathering
70: endTime = System.currentTimeMillis();
71: TimeStatisticImpl statistic = (TimeStatisticImpl) _servletStats
72: .getServiceTime();
73: statistic.addSample(endTime - startTime, endTime);
74:
75: }
76: }
77:
78: public ServletStatsImpl getServletStats() {
79: return this._servletStats;
80: }
81: }
|