1 16 17 package org.springframework.aop.interceptor; 18 19 import com.jamonapi.Monitor; 20 import com.jamonapi.MonitorFactory; 21 import org.aopalliance.intercept.MethodInvocation; 22 import org.apache.commons.logging.Log; 23 24 38 public class JamonPerformanceMonitorInterceptor extends AbstractMonitoringInterceptor { 39 40 private boolean trackAllInvocations = false; 41 42 43 46 public JamonPerformanceMonitorInterceptor() { 47 } 48 49 55 public JamonPerformanceMonitorInterceptor(boolean useDynamicLogger) { 56 setUseDynamicLogger(useDynamicLogger); 57 } 58 59 67 public JamonPerformanceMonitorInterceptor(boolean useDynamicLogger, boolean trackAllInvocations) { 68 setUseDynamicLogger(useDynamicLogger); 69 setTrackAllInvocations(trackAllInvocations); 70 } 71 72 73 80 public void setTrackAllInvocations(boolean trackAllInvocations) { 81 this.trackAllInvocations = trackAllInvocations; 82 } 83 84 85 91 protected boolean isInterceptorEnabled(MethodInvocation invocation, Log logger) { 92 return (this.trackAllInvocations || isLogEnabled(logger)); 93 } 94 95 101 protected Object invokeUnderTrace(MethodInvocation invocation, Log logger) throws Throwable { 102 String name = createInvocationTraceName(invocation); 103 Monitor monitor = MonitorFactory.start(name); 104 try { 105 return invocation.proceed(); 106 } 107 finally { 108 monitor.stop(); 109 if (!this.trackAllInvocations || isLogEnabled(logger)) { 110 logger.trace("JAMon performance statistics for method [" + name + "]:\n" + monitor); 111 } 112 } 113 } 114 115 } 116 | Popular Tags |