1 package org.apache.fulcrum.yaafi.interceptor.jamon; 2 3 import com.jamonapi.Monitor; 4 import com.jamonapi.MonitorFactory; 5 import org.apache.fulcrum.yaafi.interceptor.util.MethodToStringBuilderImpl; 6 7 import java.lang.reflect.Method; 8 9 /** 10 * Ecapsulating the JAMon 1.x related API calls 11 * 12 * @author <a href="mailto:siegfried.goeschl@it20one.at">Siegfried Goeschl</a> 13 */ 14 15 public class Jamon1PerformanceMonitorImpl implements JamonPerformanceMonitor 16 { 17 /** is monitoring enabled */ 18 private boolean isActive; 19 20 /** the method currenty monitored */ 21 private Method method; 22 23 /** the global JAMON monitor */ 24 private Monitor monitor; 25 26 /** 27 * Constructor. 28 * 29 * @param serviceName the service name of the service being monitored 30 * @param method the method to be monitored 31 * @param isActive is this an active monitor 32 */ 33 public Jamon1PerformanceMonitorImpl(String serviceName, Method method, Boolean isActive) { 34 this.method = method; 35 this.isActive = isActive.booleanValue(); 36 } 37 38 /** 39 * Start the monitor. 40 */ 41 public void start() 42 { 43 if(this.isActive) 44 { 45 MethodToStringBuilderImpl methodToStringBuilder = new MethodToStringBuilderImpl(this.method, 0); 46 String methodSignature = methodToStringBuilder.toString(); 47 this.monitor = MonitorFactory.start(methodSignature); 48 } 49 } 50 51 /** 52 * Start the monitor. 53 */ 54 public void stop() 55 { 56 if(this.isActive) 57 { 58 this.monitor.stop(); 59 } 60 } 61 62 /** 63 * Stop the monitor based on an Throwable. 64 */ 65 public void stop(Throwable throwable) 66 { 67 this.stop(); 68 } 69 70 /** 71 * Create a performance report 72 */ 73 public String createReport() throws Exception 74 { 75 return MonitorFactory.getRootMonitor().getReport(); 76 } 77 }