From: Juergen H. <jho...@us...> - 2006-04-21 00:14:24
|
Update of /cvsroot/springframework/spring/src/org/springframework/aop/interceptor In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19629/src/org/springframework/aop/interceptor Modified Files: Tag: mbranch-1-2 AbstractTraceInterceptor.java CustomizableTraceInterceptor.java JamonPerformanceMonitorInterceptor.java Log Message: backported fixes and enhancements from 2.0 M4 (HEAD) Index: AbstractTraceInterceptor.java =================================================================== RCS file: /cvsroot/springframework/spring/src/org/springframework/aop/interceptor/AbstractTraceInterceptor.java,v retrieving revision 1.3.4.2 retrieving revision 1.3.4.3 diff -C2 -d -r1.3.4.2 -r1.3.4.3 *** AbstractTraceInterceptor.java 23 Feb 2006 22:36:42 -0000 1.3.4.2 --- AbstractTraceInterceptor.java 21 Apr 2006 00:13:48 -0000 1.3.4.3 *************** *** 108,112 **** public Object invoke(MethodInvocation invocation) throws Throwable { Log logger = getLoggerForInvocation(invocation); ! if (isLogEnabled(logger)) { return invokeUnderTrace(invocation, logger); } --- 108,112 ---- public Object invoke(MethodInvocation invocation) throws Throwable { Log logger = getLoggerForInvocation(invocation); ! if (isInterceptorEnabled(invocation, logger)) { return invokeUnderTrace(invocation, logger); } *************** *** 154,160 **** /** ! * Is the {@link Log} instance enabled. Default implementation returns ! * <code>true</code> when <code>TRACE</code> level is enabled. Sub-classes ! * can override this to change the level under which 'tracing' occurs. */ protected boolean isLogEnabled(Log logger) { --- 154,176 ---- /** ! * Determine whether the interceptor should kick in, that is, ! * whether the <code>invokeUnderTrace</code> method should be called. ! * <p>Default behavior is to check whether the given <code>Log</code> ! * instance is enabled. Subclasses can override this to apply the ! * interceptor in other cases as well. ! * @param invocation the <code>MethodInvocation</code> being traced ! * @param logger the <code>Log</code> instance to check ! * @see #invokeUnderTrace ! * @see #isLogEnabled ! */ ! protected boolean isInterceptorEnabled(MethodInvocation invocation, Log logger) { ! return isLogEnabled(logger); ! } ! ! /** ! * Determine whether the given {@link Log} instance is enabled. ! * <p>Default is <code>true</code> when the "trace" level is enabled. ! * Subclasses can override this to change the level under which 'tracing' occurs. ! * @param logger the <code>Log</code> instance to check */ protected boolean isLogEnabled(Log logger) { *************** *** 162,165 **** --- 178,182 ---- } + /** * Subclasses must override this method to perform any tracing around the *************** *** 167,176 **** * ensuring that the <code>MethodInvocation</code> actually executes by * calling <code>MethodInvocation.proceed()</code>. ! * <p>The passed-in <code>Log</code> instance will have log level "trace" ! * enabled. Subclasses do not have to check for this again. * @param logger the <code>Log</code> to write trace messages to * @return the result of the call to <code>MethodInvocation.proceed()</code> * @throws Throwable if the call to <code>MethodInvocation.proceed()</code> * encountered any errors */ protected abstract Object invokeUnderTrace(MethodInvocation invocation, Log logger) throws Throwable; --- 184,197 ---- * ensuring that the <code>MethodInvocation</code> actually executes by * calling <code>MethodInvocation.proceed()</code>. ! * <p>By default, the passed-in <code>Log</code> instance will have log level ! * "trace" enabled. Subclasses do not have to check for this again, unless ! * they overwrite the <code>isInterceptorEnabled</code> method to modify ! * the default behavior. * @param logger the <code>Log</code> to write trace messages to * @return the result of the call to <code>MethodInvocation.proceed()</code> * @throws Throwable if the call to <code>MethodInvocation.proceed()</code> * encountered any errors + * @see #isInterceptorEnabled + * @see #isLogEnabled */ protected abstract Object invokeUnderTrace(MethodInvocation invocation, Log logger) throws Throwable; Index: CustomizableTraceInterceptor.java =================================================================== RCS file: /cvsroot/springframework/spring/src/org/springframework/aop/interceptor/CustomizableTraceInterceptor.java,v retrieving revision 1.5 retrieving revision 1.5.4.1 diff -C2 -d -r1.5 -r1.5.4.1 *** CustomizableTraceInterceptor.java 13 Sep 2005 21:23:13 -0000 1.5 --- CustomizableTraceInterceptor.java 21 Apr 2006 00:13:48 -0000 1.5.4.1 *************** *** 1,4 **** /* ! * Copyright 2002-2005 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); --- 1,4 ---- /* ! * Copyright 2002-2006 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); *************** *** 102,106 **** /** * The <code>$[argumentTypes]</code> placeholder. ! * Replaced with a comma seperated list of the argument types for the * method invocation. Argument types are written as short class names. */ --- 102,106 ---- /** * The <code>$[argumentTypes]</code> placeholder. ! * Replaced with a comma-separated list of the argument types for the * method invocation. Argument types are written as short class names. */ *************** *** 272,276 **** catch (Throwable ex) { exitThroughException = true; ! logger.trace(replacePlaceholders(this.exceptionMessage, invocation, null, ex, -1), ex); throw ex; } --- 272,276 ---- catch (Throwable ex) { exitThroughException = true; ! logger.trace(replacePlaceholders(this.exceptionMessage, invocation, null, ex, stopWatch.getTotalTimeMillis()), ex); throw ex; } Index: JamonPerformanceMonitorInterceptor.java =================================================================== RCS file: /cvsroot/springframework/spring/src/org/springframework/aop/interceptor/JamonPerformanceMonitorInterceptor.java,v retrieving revision 1.8.2.1 retrieving revision 1.8.2.2 diff -C2 -d -r1.8.2.1 -r1.8.2.2 *** JamonPerformanceMonitorInterceptor.java 22 Feb 2006 21:28:51 -0000 1.8.2.1 --- JamonPerformanceMonitorInterceptor.java 21 Apr 2006 00:13:48 -0000 1.8.2.2 *************** *** 38,41 **** --- 38,44 ---- public class JamonPerformanceMonitorInterceptor extends AbstractMonitoringInterceptor { + private boolean trackAllInvocations = false; + + /** * Create a new JamonPerformanceMonitorInterceptor with a static logger. *************** *** 54,58 **** --- 57,102 ---- } + /** + * Create a new JamonPerformanceMonitorInterceptor with a dynamic or static logger, + * according to the given flag. + * @param useDynamicLogger whether to use a dynamic logger or a static logger + * @param trackAllInvocations whether to track all invocations that go through + * this interceptor, or just invocations with trace logging enabled + * @see #setUseDynamicLogger + */ + public JamonPerformanceMonitorInterceptor(boolean useDynamicLogger, boolean trackAllInvocations) { + setUseDynamicLogger(useDynamicLogger); + setTrackAllInvocations(trackAllInvocations); + } + + + /** + * Set whether to track all invocations that go through this interceptor, + * or just invocations with trace logging enabled. + * <p>Default is "false": Only invocations with trace logging enabled will + * be monitored. Specify "true" to let JAMon track all invocations, + * gathering statistics even when trace logging is disabled. + */ + public void setTrackAllInvocations(boolean trackAllInvocations) { + this.trackAllInvocations = trackAllInvocations; + } + + + /** + * Always applies the interceptor if the "trackAllInvocations" flag has been set; + * else just kicks in if the log is enabled. + * @see #setTrackAllInvocations + * @see #isLogEnabled + */ + protected boolean isInterceptorEnabled(MethodInvocation invocation, Log logger) { + return (this.trackAllInvocations || isLogEnabled(logger)); + } + /** + * Wraps the invocation with a JAMon Monitor and writes the current + * performance statistics to the log (if enabled). + * @see com.jamonapi.MonitorFactory#start + * @see com.jamonapi.Monitor#stop + */ protected Object invokeUnderTrace(MethodInvocation invocation, Log logger) throws Throwable { String name = createInvocationTraceName(invocation); *************** *** 63,67 **** finally { monitor.stop(); ! logger.trace("JAMon performance statistics for method [" + name + "]:\n" + monitor); } } --- 107,113 ---- finally { monitor.stop(); ! if (!this.trackAllInvocations || isLogEnabled(logger)) { ! logger.trace("JAMon performance statistics for method [" + name + "]:\n" + monitor); ! } } } |