1 package org.apache.fulcrum.yaafi.interceptor.jamon;
2
3 /*
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
19 * under the License.
20 */
21
22 import java.lang.reflect.Method;
23
24 import com.jamonapi.Monitor;
25 import com.jamonapi.MonitorFactory;
26 import org.apache.fulcrum.yaafi.interceptor.util.MethodToStringBuilderImpl;
27
28 /**
29 * Ecapsulating the JAMon 1.x related API calls
30 *
31 * @deprecated JAMon 1.x is ancient so it is a good idea to upgrade to 2.x
32 * @author <a href="mailto:siegfried.goeschl@it20one.at">Siegfried Goeschl</a>
33 */
34
35 public class Jamon1PerformanceMonitorImpl implements JamonPerformanceMonitor
36 {
37 /** is monitoring enabled */
38 private boolean isActive;
39
40 /** the method currenty monitored */
41 private Method method;
42
43 /** the global JAMON monitor */
44 private Monitor monitor;
45
46 /**
47 * Constructor.
48 *
49 * @param serviceName the service name of the service being monitored
50 * @param method the method to be monitored
51 * @param isActive is this an active monitor
52 */
53 public Jamon1PerformanceMonitorImpl(String serviceName, Method method, Boolean isActive) {
54 this.method = method;
55 this.isActive = isActive.booleanValue();
56 }
57
58 /**
59 * Start the monitor.
60 */
61 public void start()
62 {
63 if(this.isActive)
64 {
65 MethodToStringBuilderImpl methodToStringBuilder = new MethodToStringBuilderImpl(this.method, 0);
66 String methodSignature = methodToStringBuilder.toString();
67 this.monitor = MonitorFactory.start(methodSignature);
68 }
69 }
70
71 /**
72 * Start the monitor.
73 */
74 public void stop()
75 {
76 if(this.isActive)
77 {
78 this.monitor.stop();
79 }
80 }
81
82 /**
83 * Stop the monitor based on an Throwable.
84 */
85 public void stop(Throwable throwable)
86 {
87 this.stop();
88 }
89
90 /**
91 * Create a performance report
92 */
93 public String createReport() throws Exception
94 {
95 return MonitorFactory.getRootMonitor().getReport();
96 }
97 }