org.perf4j.aop
Class AbstractTimingAspect

java.lang.Object
  extended by org.perf4j.aop.AbstractTimingAspect
Direct Known Subclasses:
TimingAspect, TimingAspect, TimingAspect, TimingAspect

public abstract class AbstractTimingAspect
extends Object

This is the base class for TimingAspects. Subclasses just need to implement the newStopWatch(java.lang.String, java.lang.String) method to use their logging framework of choice (e.g. log4j or java.logging) to persist the StopWatch log message.

Author:
Alex Devine

Constructor Summary
AbstractTimingAspect()
           
 
Method Summary
 Object doPerfLogging(org.aspectj.lang.ProceedingJoinPoint pjp, Profiled profiled)
          This advice is used to add the StopWatch logging statements around method executions that have been tagged with the Profiled annotation.
protected  String evaluateJexl(String text, Object[] args, Object annotatedObject, Object returnValue, Throwable exceptionThrown)
          Helper method is used to parse out {expressionLanguage} elements from the text and evaluate the strings using JEXL.
protected  org.apache.commons.jexl.Expression getJexlExpression(String expressionText)
          Helper method gets a compiled JEXL expression for the specified expression text, either from the cache or by creating a new compiled expression.
protected  String getStopWatchMessage(Profiled profiled, org.aspectj.lang.ProceedingJoinPoint pjp, Object returnValue, Throwable exceptionThrown)
          Helper method get the message to use for StopWatch logging.
protected  String getStopWatchTag(Profiled profiled, org.aspectj.lang.ProceedingJoinPoint pjp, Object returnValue, Throwable exceptionThrown)
          Helper method gets the tag to use for StopWatch logging.
protected abstract  LoggingStopWatch newStopWatch(String loggerName, String levelName)
          Subclasses should implement this method to return a LoggingStopWatch that should be used to time the wrapped code block.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractTimingAspect

public AbstractTimingAspect()
Method Detail

doPerfLogging

public Object doPerfLogging(org.aspectj.lang.ProceedingJoinPoint pjp,
                            Profiled profiled)
                     throws Throwable
This advice is used to add the StopWatch logging statements around method executions that have been tagged with the Profiled annotation.

Parameters:
pjp - The ProceedingJoinPoint encapulates the method around which this aspect advice runs.
profiled - The profiled annotation that was attached to the method.
Returns:
The return value from the method that was executed.
Throws:
Throwable - Any exceptions thrown by the underlying method.

getStopWatchTag

protected String getStopWatchTag(Profiled profiled,
                                 org.aspectj.lang.ProceedingJoinPoint pjp,
                                 Object returnValue,
                                 Throwable exceptionThrown)
Helper method gets the tag to use for StopWatch logging. Performs JEXL evaluation if necessary.

Parameters:
profiled - The profiled annotation that was attached to the method.
pjp - The ProceedingJoinPoint encapulates the method around which this aspect advice runs.
returnValue - The value returned from the execution of the profiled method, or null if the method returned void or an exception was thrown.
exceptionThrown - The exception thrown, if any, by the profiled method. Will be null if the method completed normally.
Returns:
The value to use as the StopWatch tag.

getStopWatchMessage

protected String getStopWatchMessage(Profiled profiled,
                                     org.aspectj.lang.ProceedingJoinPoint pjp,
                                     Object returnValue,
                                     Throwable exceptionThrown)
Helper method get the message to use for StopWatch logging. Performs JEXL evaluation if necessary.

Parameters:
profiled - The profiled annotation that was attached to the method.
pjp - The ProceedingJoinPoint encapulates the method around which this aspect advice runs.
returnValue - The value returned from the execution of the profiled method, or null if the method returned void or an exception was thrown.
exceptionThrown - The exception thrown, if any, by the profiled method. Will be null if the method completed normally.
Returns:
The value to use as the StopWatch message.

evaluateJexl

protected String evaluateJexl(String text,
                              Object[] args,
                              Object annotatedObject,
                              Object returnValue,
                              Throwable exceptionThrown)
Helper method is used to parse out {expressionLanguage} elements from the text and evaluate the strings using JEXL.

Parameters:
text - The text to be parsed.
args - The args that were passed to the method to be profiled.
annotatedObject - The value of the object whose method was profiled. Will be null if a class method was profiled.
returnValue - The value returned from the execution of the profiled method, or null if the method returned void or an exception was thrown.
exceptionThrown - The exception thrown, if any, by the profiled method. Will be null if the method completed normally.
Returns:
The evaluated string.
See Also:
Profiled.el()

getJexlExpression

protected org.apache.commons.jexl.Expression getJexlExpression(String expressionText)
                                                        throws Exception
Helper method gets a compiled JEXL expression for the specified expression text, either from the cache or by creating a new compiled expression.

Parameters:
expressionText - The JEXL expression text
Returns:
A compiled JEXL expression representing the expression text
Throws:
Exception - Thrown if there was an error compiling the expression text

newStopWatch

protected abstract LoggingStopWatch newStopWatch(String loggerName,
                                                 String levelName)
Subclasses should implement this method to return a LoggingStopWatch that should be used to time the wrapped code block.

Parameters:
loggerName - The name of the logger to use for persisting StopWatch messages.
levelName - The level at which the message should be logged.
Returns:
The new LoggingStopWatch.


Copyright © 2008-2009 perf4j.org. All Rights Reserved.