Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] AspectJ is not intercepting `collect` call

Hi.

2015-09-09 12:04 GMT+02:00 xeonmailinglist <xeonmailinglist@xxxxxxxxx>:

[2] My mapreduce aspects


package org.apache.hadoop.mapred.aspects;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;

@Aspect
public class MapReduceAspects {
    @Before("execution(* map(..))")
    public void mymap(JoinPoint joinPoint) {
        System.out.println("My Map Execution: " + joinPoint.getArgs() + ":" + joinPoint.getTarget());
        Object[] obj = joinPoint.getArgs();
        for (Object o : obj){
            System.out.println(o.toString());
        }
    }

    @Before("execution(* reduce(..))")
    public void myreduce() { System.out.println("My Reduce Execution"); }

    @Before("execution(* collect(..))")
    public void updatehash(JoinPoint joinPoint) {
        System.out.println("Output collect: Args: " + joinPoint.getArgs());

    }
}

 [...]

I can intercept the map and reduce function calls with AspectJ, but I can’t intercept the collect call in the instruction output.collect(word, one) that is in the map function. Why this happens? Didn`t I configure the Aspects correctly?

No, actually, you're not intercepting the calls (at the call site), but the executions (in the implementing class), as noted in your pointcuts. Which is why you can't intercept collect(): it's not implemented by any of your classes, and you're not weaving the Hadoop classes themselves.

You can intercept the call, by changing the pointcut from execution(...) to call(...), though you probably want to qualify the method with the type to avoid intercepting other calls to methods with the same (generic) name:
  call(* org.apache.hadoop.mapred.OutputCollector+.collect(..))

Regards,
Frank 

Back to the top