[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[aspectj-users] Met [org.aspectj.lang.NoAspectBoundException] while running a post-compile woven (bytecode woven) apache thrift library

Hi,

Problem

I have some aspects trying to insert an ID for every class that implements Runnable.

My aspects (provided below) works fine for a simple test in which 1) I wrote my own MyRunnable class implementing Runnable, 2) I have a simple main function that creates and runs a thread using MyRunnable.

However, when I use it to instrument apache thrift library, it gives me org.aspectj.lang.NoAspectBoundException exception.

I use compile-time weaving. The compile-time weaving finishes successfully, and the instrumented .class code shows the aspects was woven. However, running the instrumented apache thrift lib gives this excetpion:

(MyServer is my simple server implementation using thrift. TThreadPoolServer is the server class in apache thrift lib.)

org.aspectj.lang.NoAspectBoundException
    at EpredPerRunnable.aspectOf(EpredPerRunnable.aj:1)
    at EpredRunnablesCallables.ajc$afterReturning$EpredRunnablesCallables$1$8a935d86(EpredRunnablesCallables.aj:55)
    at org.apache.thrift.server.TThreadPoolServer.serve(TThreadPoolServer.java:168)
    at MyServer.StartsimpleServer(MyServer.java:21)
    at MyServer.main(MyServer.java:28)

My Aspects

Here are the aspects I wrote:

1) I have a counter for each class implements Runnable using pertypewithin.

privileged aspect PerRunnable
    pertypewithin(java.lang.Runnable+)
{
  public long counter = 0;

  public long getCounter() {
    return counter;
  }

  public void incrementCounter() {
    counter++;
  }
}

2) I insert an id into each class that implements Runnable using interface.

privileged aspect MyRunnables {

  public interface InstrumentedRunnable {}

  private long InstrumentedRunnable.myid = -1;

  public long InstrumentedRunnable.getMyid() {
    return myid;
  }
   
  public void InstrumentedRunnable.setMyid(long id) {
    myid = id;
  }


  declare parents: (Runnable)+ implements InstrumentedRunnable;

  after() returning(InstrumentedRunnable r):
      call(java.lang.Runnable+.new(..)) {

      long id = PerRunnable.aspectOf(r.getClass()).getCounter();
      r.setMyid(id);

      PerRunnable.aspectOf(r.getClass()).incrementCounter();

  }

}

3) Part of my scripts that only instruments thrift:

CLASSPATH=$CLASSPATH:~/aspectj1.9/lib/aspectjtools.jar
CLASSPATH=$CLASSPATH:~/aspectj1.9/lib/aspectjrt.jar
AJC=~/aspectj1.9/bin/ajc

echo "Compiling Aspects ..."
$AJC -classpath $CLASSPATH:./lib/libthrift-0.11.0.jar -source 1.8 asp/*.aj

echo "Weaving aspect into thrift lib..."
$AJC -classpath $CLASSPATH:./lib/servlet-api-2.5.jar:./lib/httpcore-4.4.1.jar:./lib/slf4j-api-1.7.12.jar:./lib/httpclient-4.4.1.jar -source 1.8 -inpath ./lib/libthrift-0.11.0.jar -aspectpath ./asp/ -outjar ./my-libthrift-0.11.0.jar

4) Part of my scripts that starts the thrift server:

CLASSPATH=$CLASSPATH:~/aspectj1.9/lib/aspectjtools.jar
CLASSPATH=$CLASSPATH:~/aspectj1.9/lib/aspectjrt.jar

java -cp $CLASSPATH:./asp:./my-add-server.jar:./my-libthrift-0.11.0.jar:./lib/slf4j-api-1.7.12.jar MyServer

Need Help

  1. Has anyone met such problem before? Any guess? Note that these aspects works for my own Runnable but not for thrift lib. (I can send more code needed including my test classes and my scripts, but they donât fit within an emailâ)
  2. Is there a way to get all aspect instances and what they are matched to at runtime?
  3. Does aspectj has this feature: given 1) a pointcut, 2) the signature of a target (class/method) I want the pointcut to match, tell me whether they matched, and if not why.

Thank you for your time and help!