...
Another logging and tracing facility is available in Tuscany that gives the user a bit of flexibility in what gets logged , and requires no source code modifications to run. This is an Aspect Oriented Programming (AOP) approach that runs via a Java agent at runtime. Just like a debugger can start and stop and inspect a Tuscany Java program, so too can an AOP agent inspect and report on a Tuscany Java program. Tuscany employs the AspectJ implementation, and its runtime agent is contained in the aspectjweaver.jar file. The AOP agent is specified from a command line option or runtime options:
Code Block | ||||
---|---|---|---|---|
| ||||
java -javaagent:"<path to aspectjweaver.jar>" calculator.CalculatorClient
|
The AOP logging and tracing agent can be run with any Tuscany program. No additional calls or log statements need be added to the Tuscany code. The results of running a timing for example, look like this:
Code Block | ||||
---|---|---|---|---|
| ||||
Running org.apache.tuscany.sca.aspectj.TracingTestCase Timing Around timedSection jp=call(void java.util.logging.Logger.info(String)) Oct 21, 2008 9:26:36 AM org.apache.tuscany.sca.aspectj.TracingTestCase info_aroundBody0 Timing Around timedSection Roundtrip is 32ms for jp.getSignature=void java.util.logging.Logger.info(String) |
Full documentation on AspectJ is available at the AspectJ web site. Tuscany provides example usage in the module tracing-aspectj in the build tree and the released code.
Brief Apect Oriented Programming Introduction
In order to understand the aspect oriented approach to logging in Tuscany, one must understand a few basic concepts.
A join point is well defined point in the program flow. An example join point is the entry to a Java method. Another is after an exception is thrown. These join points contain useful information when running a program such as the argument list, the call stack, and the signature of the point that is executing.
A point cut is a subset of all the program join points. For instance, a point cut might be only the join points from exceptions thrown by the Tuscany runtime. Or only the set of calls to a Tuscany API org.apache.tuscany.sca.node.launcher.NodeLauncher.
Advice is the code that is run when a point cut is reached. For instance, your advice might want to print out all the arguments when entering a given method. Or your advice might show the call stack of an exception and print the original cause of the exception.
Finally, an aspect is a module that bundles up a particular set of point cuts and advice. Here is an example aspect that is marked with Java 5 annotations. The name of the aspect is LoggingAspect, there is a point cut defined at Tuscany calls to org.apache.tuscany.sca.* classes (but not inside of Aspect classes), and when the point cut is run, the advice for this point cut prints out the join point signature.
Code Block | ||||
---|---|---|---|---|
| ||||
@Aspect
public class LoggingAspect {
@Pointcut("call(* org.apache.tuscany.sca..*(..)) && (!within(org.apache.tuscany.sca.aspectj.*Aspect))")
public void anyMethodCall() {
}
@Before("anyMethodCall()")
public void before(JoinPoint jp) {
System.out.println("Logging Before anyMethodCall jp.getSignature=" + jp.getSignature());
}
}
|
Full explanation of these concepts are in the AspectJ documents. The purpose here is to provide enough information to allow a user to run or modify the Tuscany aspects to one's liking.
Logging and Tracing in Tuscany
...