Java tutorial
/******************************************************************************* * Educational Online Test Delivery System * Copyright (c) 2013 American Institutes for Research * * Distributed under the AIR Open Source License, Version 1.0 * See accompanying file AIR-License-1_0.txt or at * http://www.smarterapp.org/documents/American_Institutes_for_Research_Open_Source_Software_License.pdf ******************************************************************************/ package org.opentestsystem.shared.mna.client.aop; import org.aspectj.lang.ProceedingJoinPoint; import org.opentestsystem.shared.mna.client.aop.LoggingAdvice; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** * Null client implementation of logging advice interface */ public class NullLoggingAdvice implements LoggingAdvice { /** * Logger */ private static final Logger LOGGER = LoggerFactory.getLogger(NullLoggingAdvice.class); /** * {@inheritDoc} */ @Override public Object timeMethod(final ProceedingJoinPoint inPjp, final Logger inPerformanceLogger) { Object output = null; try { // only do this if debug is enabled if (inPerformanceLogger != null && inPerformanceLogger.isDebugEnabled()) { long start = System.currentTimeMillis(); inPerformanceLogger.debug("Using NullLoggingAdvice: Begin " + inPjp.toShortString()); output = inPjp.proceed(); long stop = System.currentTimeMillis(); long elapsedTime = stop - start; // log out to the appender that is configured inPerformanceLogger.debug("Using NullLoggingAdvice: End " + inPjp.toShortString() + " Elapsed Time: " + elapsedTime + " ms"); } else { output = inPjp.proceed(); } // allow catch of throwable because the AOP proceed call throws Throwable, also allow rethrowing as a generic // RuntimeException } catch (Throwable thr) { // NOPMD if (thr instanceof RuntimeException) { // NOPMD LOGGER.error("Using NullLoggingAdvice: Caught RuntimeException in Around Advice, rethrowing", thr); throw (RuntimeException) thr; } else { LOGGER.error( "Using NullLoggingAdvice: Caught a non-RuntimeException error in AroundAdvice, rethrowing as RuntimeException", thr); throw new RuntimeException( "Using NullLoggingAdvice: Caught a non-RuntimeException error in AroundAdvice, rethrowing as RuntimeException", thr); // NOPMD } } return output; } }