|
Helping ordinary people create extraordinary websites! |
Using Aspects to Autonomic-Enable Legacy ApplicationsBy Brian Temple2005-05-13
An example Aspect framework to generate Common Base Events To simplify the autonomic enablement of legacy applications, I have created a set of abstract Aspects and utility classes that can be extended to handle most possible event generation situations. (See Resources below for the download link.) Use this abstract Aspect layout to minimize what you have to define when you're ready to include this in your application. Your Aspect would at most contain two pointcut definitions (which simply define the package or call structure the Aspect is applied against) and a method that returns a string representation of the application name. The top-level Aspect for this example framework is CommonBase.aj, and is used to define abstract scope pointcuts and convert certain Aspect actions into methods that can be overriden. Examples of these action methods are enterMethodAction and exitMethodAction, and all are defined to be empty methods. These empty methods ensure that a subclassing Aspect needs only to override the methods that apply in its intended function. There are three abstract items that every concrete child Aspect (or parent below CommonBase) must have defined: classScope(), methodScope(), and getApplicationName(). Figure 1. Aspect framework UML
classScope() The classScope pointcut defines the set of classes that a child Aspect is interested in. Generally, this is just the package of your application and should be used to define all of the points of interest in code that you have written. An example of the classScope pointcut is: Listing 4. classScope pointcut public pointcut classScope() : within(com.mycompany.myapp..*);methodScope() The methodScope pointcut defines any methods that your classes use that you would like to act upon. Generally, these are items like loggers or database calls. An example of the methodScope pointcut is: Listing 5. methodScope pointcut public pointcut methodScope() : call(* PrintStream.print*(..)) &&getApplicationName() The getApplicationName method simply returns a string to be used in the resultant Common Base Event, which defines the application name where the event was generated from. 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 |
|