001/*002 * Copyright 2002-2017 the original author or authors.003 *004 * Licensed under the Apache License, Version 2.0 (the "License");005 * you may not use this file except in compliance with the License.006 * You may obtain a copy of the License at007 *008 * https://www.apache.org/licenses/LICENSE-2.0009 *010 * Unless required by applicable law or agreed to in writing, software011 * distributed under the License is distributed on an "AS IS" BASIS,012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.013 * See the License for the specific language governing permissions and014 * limitations under the License.015 */016017package org.springframework.aop.interceptor;018019import com.jamonapi.MonKey;020import com.jamonapi.MonKeyImp;021import com.jamonapi.Monitor;022import com.jamonapi.MonitorFactory;023import com.jamonapi.utils.Misc;024import org.aopalliance.intercept.MethodInvocation;025import org.apache.commons.logging.Log;026027/**028 * Performance monitor interceptor that uses <b>JAMon</b> library to perform the029 * performance measurement on the intercepted method and output the stats.030 * In addition, it tracks/counts exceptions thrown by the intercepted method.031 * The stack traces can be viewed in the JAMon web application.032 *033 * <p>This code is inspired by Thierry Templier's blog.034 *035 * @author Dmitriy Kopylenko036 * @author Juergen Hoeller037 * @author Rob Harrop038 * @author Steve Souza039 * @since 1.1.3040 * @see com.jamonapi.MonitorFactory041 * @see PerformanceMonitorInterceptor042 */043@SuppressWarnings("serial")044public class JamonPerformanceMonitorInterceptor extends AbstractMonitoringInterceptor {045046 private boolean trackAllInvocations = false;047048049 /**050 * Create a new JamonPerformanceMonitorInterceptor with a static logger.051 */052 public JamonPerformanceMonitorInterceptor() {053 }054055 /**056 * Create a new JamonPerformanceMonitorInterceptor with a dynamic or static logger,057 * according to the given flag.058 * @param useDynamicLogger whether to use a dynamic logger or a static logger059 * @see #setUseDynamicLogger060 */061 public JamonPerformanceMonitorInterceptor(boolean useDynamicLogger) {062 setUseDynamicLogger(useDynamicLogger);063 }064065 /**066 * Create a new JamonPerformanceMonitorInterceptor with a dynamic or static logger,067 * according to the given flag.068 * @param useDynamicLogger whether to use a dynamic logger or a static logger069 * @param trackAllInvocations whether to track all invocations that go through070 * this interceptor, or just invocations with trace logging enabled071 * @see #setUseDynamicLogger072 */073 public JamonPerformanceMonitorInterceptor(boolean useDynamicLogger, boolean trackAllInvocations) {074 setUseDynamicLogger(useDynamicLogger);075 setTrackAllInvocat