Hello,
I have been using AspectJ for 3 days now and
it is great. I would like to introduce it to our project immediatelly. Please
could anybody verify my design since I am new to this cool stuff.
I would like to use AspectJ for managing logging,
exception handling, singletons and .....
We are developing middleware application that gets
correlation id from client for logging. We need different instance of the logger
for each transaction. Entry point for the application is a stateless session
bean that delegates to POJO Facade (singleton). I thought to use
Per-control-flow aspect which would be instantiated when any of the Facade
methods are called. Then there would be one aspect holding the logger per
thread available for the whole execution. Each concurrent transaction executing
in different thread would have its own logger. Please see below the aspect
code.
Questions:
1) Are my assumtions about Per-control-flow aspect
correct? Or should it be done in different way?
2) Do I need to specify cflow() in the
facadeExceptions() pointcut?
Thank you,
Pavel
******************************************** ASPECT
*****************************************************************
package aspekty;
import org.aspectj.lang.*;
public aspect LoggerAspect percflow
(expCall()){
Logger logger;
pointcut expCall() :
target(Facade)
&&
(call(public void executeFirst(int))
||
call(public void executeSecond(int))
||
call(public void executeThird(int)));
before (int par):
expCall() && args(par){
Container container
= new Container();
LoggerFactory factory =
container.getLoggerFactory();
logger =
factory.getLogger(par);
}
//Log exception and let it go to
ExceptionHandlerAspect to process
pointcut facadeExceptions():
call(public void Facade.*(..))
||
call(private void
ServiceAccess.disconnect());
after() throwing(Throwable
ex): facadeExceptions() {
logger.log(ex);
}
//Log entry to facade methods
pointcut facadeEntry(Facade facade): target(facade)
&&
execution (public void *(..));
before(Facade facade): facadeEntry(facade) {
Signature sig =
thisJoinPointStaticPart.getSignature();
String context = "[" +
sig.getDeclaringType().getName() + "." + sig.getName() +
"]";
logger.logEntry(context);
}
}