puniverse / quasar

Fibers, Channels and Actors for the JVM

Home Page:http://docs.paralleluniverse.co/quasar/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to co-work with cglib

yanxinyuan opened this issue · comments

commented

Dears,
As far as i know, Quasar rely on bytecode instrumentation. This can be done at class loading time via a Java Agent, or at compilation time with an Ant task.

But now i have a class which is generated by cglib and i want one of its method can suspend the fiber.
Is it possible ? And how should i do?

The code is something like this:

// This class and method is generated by cglib
class Xxx {
    public void yyy() throws SuspendExecution {
        for (int i = 0; i < 10; i++) {
		System.out.println(i);
		Fiber.park();
	}
     }
}

public static void main(String[] args) {
   // using cglib generated 'Xxx' class and 'yyy' method
   Fiber<Void> fiber = new Fiber<Void>() {
	@Override
	protected Void run() throws SuspendExecution, InterruptedException {
                Class<?> clazz = Class.forName("Xxx");
		Object obj = clazz.newInstance();
		Method method = clazz.getMethod("yyy");
		method.invoke(obj);
         	return null;
	}	
    }.start();

     while(!fiber.isDone()) {
	 Strand.sleep(2000);
	 Fiber.unpark(fiber);
     }  
}

And the result should be:

java -jar target\Quasar-Cglib-0.0.1-SNAPSHOT.jar
QUASAR WARNING: Quasar Java Agent isn't running. If you're using another instrumentation method you can ignore this message; otherwise, please refer to the Getting Started section in the Quasar documentation.
0
1
2
commented

I've created a minimal example project to demonstrate.

commented

Ok , after i change the cglib Interceptor to throw SuspendExecution, this issue has gone.

commented

Supplementary explanation, cglib can also co-work with quasar by using java agent instrument and SuspendableClassifier, here is an example.