01: package com.jamonapi.http;
02:
03: /**
04: * used to monitor jetty requests via the JAMonJettyHandler.
05: */
06: import com.jamonapi.Monitor;
07: import com.jamonapi.MonitorFactory;
08: import org.mortbay.jetty.Request;
09:
10: class JettyHttpMonItem extends HttpMonItem {
11:
12: JettyHttpMonItem() {
13: }
14:
15: JettyHttpMonItem(String label, HttpMonFactory httpMonFactory) {
16: super (label, httpMonFactory);
17:
18: }
19:
20: /** Jetty Handlers does not let jamon start/stop time them. It seems the request is done by the time jamon gets it. To overcome this use the jetty api
21: * to get the time of a request for a page. If it isn't a jetty request then call the parent.
22: */
23:
24: // Only called if this is a time monitor i.e units are 'ms.'
25: Monitor startTimeMon(HttpMonRequest httpMonBase) {
26: if (httpMonBase.getRequest() instanceof Request)
27: return MonitorFactory.getMonitor(getMonKey(httpMonBase))
28: .start();
29: else
30: return super .startTimeMon(httpMonBase);
31: }
32:
33: // Only called if this is a time monitor i.e units are 'ms.'
34: void stopTimeMon(HttpMonRequest httpMonBase) {
35: if (httpMonBase.getRequest() instanceof Request) {
36: Request request = (Request) httpMonBase.getRequest();
37: Monitor mon = httpMonBase.getNextTimeMon();
38: if (mon != null) {
39: mon.add(
40: System.currentTimeMillis()
41: - request.getTimeStamp()).stop();// figure elapsed time and then decrement active.
42: }
43: } else
44: super.stopTimeMon(httpMonBase);
45: }
46:
47: }
|