[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] StackOverflow error

You are right! I could have done it far easier using around advice:

    @Around("call(@com.plexibus.util.annotation.RunMultiple * *.*(..))")
    public Object tryAgain(ProceedingJoinPoint jp) throws Throwable {
        Method method = ((MethodSignature) jp.getSignature()).getMethod();

        RunMultiple rmAnnotation = method.getAnnotation(RunMultiple.class);

        Throwable err = null;

        for (int i = 0; i < rmAnnotation.counter(); i++) {

            if (logger.isTraceEnabled()) {
                logger.trace("i: " + i);
            try {
                method.invoke(obj, jp.getArgs());
            } catch (Throwable t) {
                // do something with err...might need to resubmit job...
                throw err;
        if (logger.isTraceEnabled()) {
            logger.trace("Finished Around advice");
        return jp.proceed();

This eliminates all other methods (the other pointcuts and advices included) in the RunMultipleAspect!

Thanks for refactoring suggestion, Holger :) Geez, now I feel like an idiot!


On Thu, Jul 3, 2008 at 2:16 PM, Holger Hoffstätte <holger@xxxxxxxxxx> wrote:
Jack Jill wrote:
Your advice :) worked like a charm!

Showing only relevant changes to code (RunMultipleAspect.java)

*@After("execution(@com.xxxx.util.annotation.RunMultiple * *.*(..)) && !within(RunMultipleAspect) && !cflow(adviceexecution())")*
public void repeat(JoinPoint jp) throws ClassNotFoundException,
           IllegalArgumentException, IllegalAccessException,
           InvocationTargetException, InstantiationException {
*         //        if (++count < rmAnnotation.counter()) {

Hey :)

I quickly read through your example and was wondering if you couldn't just use "around" to call proceed() n times in your loop. This should work the same but without all the hand-made reflection stuff and (as far as I can see?) no need for cflowbelow, no stack overflow etc. Would this work too?


aspectj-users mailing list