org.objectweb.jac.aspects.tracing
Class OptimizedCountingWrapper

java.lang.Object
  |
  +--org.objectweb.jac.core.Wrapper
        |
        +--org.objectweb.jac.aspects.tracing.SimpleCountingWrapper
              |
              +--org.objectweb.jac.aspects.tracing.OptimizedCountingWrapper
All Implemented Interfaces:
Advice, ConstructorInterceptor, Interceptor, MethodInterceptor, Serializable

public class OptimizedCountingWrapper
extends SimpleCountingWrapper

This counter must wrap the methods of which calls have to be counted. It extends the simple counting wrapper to provide 2 optimization methods when client methods call several times the method wrapped by incr. In these cases, the counter is direcly incremented by the number of times the incr method has to be called.

In order to avoid redundancy, incr must not be called if incrWithArg or incrWithField have already been called. To perform this contextual test, use the before and after running wrapper methods of the aspect component.

See Also:
Serialized Form

Field Summary
 
Fields inherited from class org.objectweb.jac.core.Wrapper
ac, cr
 
Constructor Summary
OptimizedCountingWrapper(AspectComponent ac, Counter c, int arg)
          Create the counter and parametrize it regarding the base program shape.
OptimizedCountingWrapper(AspectComponent ac, Counter c, String field)
          Create the counter and parametrize it regarding the base program shape.
 
Method Summary
 Object construct(ConstructorInvocation invocation)
           
 Object incrWithArg(Interaction interaction)
          This wrapping method increments the counter with the argument value when the wrapped method is called.
 Object incrWithField(Interaction interaction)
          This wrapping method increments the counter with the field when the wrapped method is called.
 Object invoke(MethodInvocation invocation)
           
 
Methods inherited from class org.objectweb.jac.aspects.tracing.SimpleCountingWrapper
getCounter, incr, printCounter, setCounter
 
Methods inherited from class org.objectweb.jac.core.Wrapper
attr, attrdef, defines, getAspectComponent, getAspectComponentName, getExceptionHandlers, proceed, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

OptimizedCountingWrapper

public OptimizedCountingWrapper(AspectComponent ac,
                                Counter c,
                                String field)
Create the counter and parametrize it regarding the base program shape.

Parameters:
c - the used counter
field - the field that is used to optimize the counting

OptimizedCountingWrapper

public OptimizedCountingWrapper(AspectComponent ac,
                                Counter c,
                                int arg)
Create the counter and parametrize it regarding the base program shape.

Parameters:
c - the used counter
arg - the argument number that used to optimize the counting
Method Detail

incrWithField

public Object incrWithField(Interaction interaction)
This wrapping method increments the counter with the field when the wrapped method is called. It is an optimization for the incr method.

Returns:
the return value of the wrapped method
See Also:
SimpleCountingWrapper.incr(Interaction)

incrWithArg

public Object incrWithArg(Interaction interaction)
This wrapping method increments the counter with the argument value when the wrapped method is called. It is an optimization for the incr method.

Returns:
the return value of the wrapped method
See Also:
SimpleCountingWrapper.incr(Interaction)

invoke

public Object invoke(MethodInvocation invocation)
              throws Throwable
Specified by:
invoke in interface MethodInterceptor
Overrides:
invoke in class SimpleCountingWrapper
Throwable

construct

public Object construct(ConstructorInvocation invocation)
                 throws Throwable
Specified by:
construct in interface ConstructorInterceptor
Overrides:
construct in class SimpleCountingWrapper
Throwable