Leifo (5) [Avatar] Offline
#1
//Listing 8.7 SynchronousExecutionAspect.java

import pattern.worker.*;

public abstract aspect SynchronousExecutionAspect {
public abstract pointcut syncOperations();

Object around() : syncOperations() {
RunnableWithReturn worker = new RunnableWithReturn() {
public void run() {
_returnValue = proceed();
}};
System.out.println("About to run " + worker);
// worker.run();
Thread syncExecThread = new Thread(worker);//replace above
syncExecThread.start(); //end
return worker.getReturnValue();
}
}


(As in Listing 8.4)
Leifo (5) [Avatar] Offline
#2
Re: errate page 254, Listing 8.7
Or am I wrong?
ramnivas (171) [Avatar] Offline
#3
Re: errate page 254, Listing 8.7
The source code in the book is correct. The point being illustrated there is routing a call synchronously through a worker object. As mentioned in the note following the code, such a routing is useful in implementing JASS authorization and transaction management etc.

-Ramnivas
Leifo (5) [Avatar] Offline
#4
Re: errate page 254, Listing 8.7
Ok, but why does the RunnableWithReturn class implement Runnable?
Couldn't it just have an abstract method (which could be public abstract run())?

-Leifo
ramnivas (171) [Avatar] Offline
#5
Re: errate page 254, Listing 8.7
Yes, it could have not implemented Runnable. But implementing Runnable allows the worker object to be used in places where a Runnable is expected (for example, passing to a new thread) without any change to object creation itself -- it mostly boils down to making a design choice.

-Ramnivas