Helping ordinary people create extraordinary websites!
GET OUR NEWSLETTER
Your Email:
 

Using Aspects to Autonomic-Enable Legacy Applications

By Brian Temple
2005-05-13


How to use and extend the example Aspect framework

When examining the set of correlated logs for a particular software solution, it might be very useful to understand what exactly is being executed during points of interest. A point of interest in this case might be an application crash or inappropriately high usage of a CPU. The CommonTraceLogger Aspect implements most of the action events defined in CommonBase and simply invokes the CommonEventHandler helper class to generate Common Base Events. To make your application generate these Common Base Event trace events, simply create a concrete Aspect that subclasses CommonTraceLogger, as shown in Listing 6 and recompile the application.

Listing 6. Concrete Aspect that subclasses CommonTraceLogger

import com.ibm.developerworks.autonomicenablement.aspect.CommonTraceLogger;


public aspect MyAppTraceLogger extends CommonTraceLogger {
public pointcut classScope() : within(com.mycompany.myapp..*);

public String getApplicationName() {
return "My Application";
}
}
Another point of interest that might exist is simply what the original application used to log or debug. In the context of the example application, no logs are ever written; all information is simply printed to the screen using System.out. One way to capture this information is to create a subclass of the CommonWrappingLogger Aspect that inspects every PrintStream.print command, ensures it is the System.out PrintStream, and then generates a Common Base Event. The implementation of this is shown in Listing 7.

Listing 7. Capturing System.out calls

package com.ibm.developerworks.autonomicenablement.aspect;


import java.io.PrintStream;
import org.aspectj.lang.JoinPoint;

public abstract aspect SystemOutWrappingLogger extends CommonWrappingLogger {
public pointcut methodScope() : call(* PrintStream.print*(..)) &&
classScope();

public void beforeMethodCalledAction(JoinPoint joinPoint) {
if (joinPoint.getTarget() == System.out) {
super.beforeMethodCalledAction(joinPoint);
}
}
}
After this new Aspect has been created, simply create another concrete Aspect as shown in Listing 8 and recompile the application.

Listing 8. Concrete Aspect that subclasses SystemOutWrappingLogger

import com.ibm.developerworks.autonomicenablement.aspect.SystemOutWrappingLogger;


public aspect MyAppSystemOutWrappingLogger extends SystemOutWrappingLogger {
public pointcut classScope() : within(com.mycompany.myapp..*);

public String getApplicationName() {
return "My Application";
}
}


Tutorial Pages:
» Using Aspects to autonomic-enable legacy applications
» Introduction
» Example legacy application
» Incorporating Aspects
» An example Aspect framework to generate Common Base Events
» How to use and extend the example Aspect framework
» Next steps
» Resources


First published by IBM DeveloperWorks


 | Bookmark
Related Tutorials:
» All about JAXP, Part 1
» Make Database Queries Without the Database
» Load List Values for Improved Efficiency
» 2 Ways To Implement Session Tracking
» A Simple Way to Read an XML File in Java
» Develop Aspect-Oriented Java Applications with Eclipse and AJDT

Advertise with Us!


Tutorials Scripts Web Hosting Developer Manuals
Resources