AspectOriented Refactoring of the Apache Cocoon SharedObject Resource
Aspect-Oriented Refactoring of the Apache Cocoon Shared-Object Resource Allocation System Jeff Dalton Advisor: David G. Hannay, Union College Client: Robert Berry, IBM Java Technology Centre, Hursley, UK Abstract Methodology: The AOP Refactoring Process Aspect-oriented programming (AOP) enables developers to develop and manage 'cross-cutting concerns' unrelated to the primary function of the system component. Using AOP, these concerns can then be introduced to the base component easily and in a structured manner. Other benefits of using AOP include the creation of software that is easier to understand modify. Caching, a common and effective technique to improve the performance of applications and middleware, is such a cross-cutting concern. We explore this by refactoring a complex web application, Apache Cocoon, using AOP to introduce a caching mechanism. The goal is to retain the original external behavior, while removing complexity and adding flexibility in the caching system. The development of the Aspect. J language and compiler allows the application of this methodology on the existing base of Java-based web applications without requiring new infrastructure. This project takes the next step by using Aspect. J to simplify and extend the caching system in a large and complex XML-based website publishing system; it explores the potential difficulties associated with using Aspect. J to accomplish this task and considers the effect that the application architecture has on the aspect-oriented Analysis & Observations Question: How should you structure your application to simplify AO extendibility? Step 1: Identify locations – “Aspect Mining” Used Aspect. J to define a compiler warning in order to identify locations in Cocoon that implement the Cacheable. Processing. Component abstract interface. § Good coding practice makes AO adoption easier -Standard variable naming public aspect Explore. Caching { declare warning: staticinitialization(org. apache. cocoon. caching. Cacheable. Processing. Component+) && !within(org. apache. cocoon. caching. . *): "Class implements cacheable"; § Standard accessor methods are required to reduce } Disparate names: Lexical. Source, Grammar. Source, etc. needed to be refactored to “Input. Source” before they could be used to remove code via AOP. introductions through Mixins. - Example: One case needed get. Input. Source() -But how are we supposed to know we need these when writing the software? - We can’t know. The lesson: In some cases you need to perform Object-Oriented refactoring in order to allow AOP to reduce code duplication. Open Questions In a component architecture, do we define crosscutting concerns? § Do we examine each block individually or the system as a whole? refactoring process. Background: aspectj. & AOP Aspect. J is a small and well-integrated extension to Java that weaves java byte code and outputs. class files compatible with any JVM. § What do you do if it is a crosscutting concern in the system but What is Aspect Oriented Programming? This points to a larger problem not within the block? How should aspects be viewed on a design level? Concern – “a specific requirement or consideration that must be addressed in order to satisfy the overall system goal. ” Step 2: Write Caching Aspects AOP is a programming language mechanism that extends Object. Oriented Programming in order to achieve modularity and the ‘separation of concerns’. privileged public aspect Caching. Aspect { Introduce /* Ascii art generator */ declare parents: org. apache. cocoon. generation. asciiart. Ascii. Art. SVGGenerator implements Cacheable. Processing. Component; AOP introduces a new unit of modularization, an aspect, that captures behaviors that affect multiple classes (a crosscutting concern) into reusable modules. What are aspects? Aspects are: public Source. Validity org. apache. cocoon. generation. asciiart. Ascii. Art. SVGGenerator. generate. Validity() { Introduce return this. input. Source. get. Validity(); }. . [design level] ‘Mixin’ it up: Use AOP design patterns to condense reusable code § a programming construct [implementation level] public interface Shared. Cacher extends Cacheable. Processing. Component { public Source. Validity generate. Validity(); public java. io. Serializable generate. Key(); } public aspect Shared. Cacher. Aspect { declare parents: (org. apache. cocoon. serialization. FOPSerializer|| org. apache. cocoon. serialization. i. Text. Serializer|| org. apache. cocoon. transformation. Fragment. Extractor. Transformer|| org. apache. cocoon. serialization. SVGSerializer|| org. apache. cocoon. serialization. Abstract. Text. Serializer ) implements Shared. Cacher; • Joinpoint: a principle point in the execution of the software system • Pointcut: predicate matching on joinpoints (where) • Advice: behavior that should be triggered at joinpoints, selected using a pointcut (what) • Inter-type Declarations: Fields and methods that the aspect manages on behalf of other types Aspect. J’s goal is to support the programmer in cleanly separating components and aspects from each other by providing mechanisms that make it possible to abstract and compose them to produce the overall system Background: Apache Cocoon public Serializable Shared. Cacher. generate. Key() { return "1"; } public Source. Validity Shared. Cacher. generate. Validity() { return NOPValidity. SHARED_INSTANCE; } } that the AO caching solution can be deployed on a Tomcat web server. § Use AOP to refactor the internal object store within Cocoon. This Methods is an ‘internal cache’ where classes can store objects for later retrieval. This is a very closely related to this project since the caching system is just a thin wrapper around this store. § An event-driven ‘inverted’ AOP caching system Build a caching system that uses AOP to handle ‘Avalon’ events and perform the proper cache invalidations. Specialized reusable class Classes with same caching behavior Step 3: Remove References and Compile A dynamic multi-channel web publishing platform Future Work § Integrate the Aspect. J Compiler into the Cocoon build process so public Serializable org. apache. cocoon. generation. asciiart. Ascii. Art. SVGGenerator. generate. Key() { return this. input. Source. get. URI(); } § concerns that crosscut Aspects = pointcut + advice + inter-type declarations Interface AOP solves the design problem of where to define the caching strategy. Conclusions § Many more opportunities for AOP in Cocoon! § Modifications to the Aspect. J language and implementation would make the process easier, but it is still viable today. Summary: Abstracted 39 implementations of Cacheable. Processing. Component Used AOP to condense and remove 24 methods from the base implementation. Removed all of the caching code into a single AOP package. “Apache Cocoon is a web development framework built around the concepts of separation of concerns and component-based web development. ” – Cocoon Goal: The separation of content, style, logic and management functions in an XML content based web site (and web services). Example: Duplicate code: public Serializable org. apache. cocoon. transformation. Lexical. Transformer. generate. Key() { return this. lexicon. Source. get. URI(); } public Serializable org. apache. cocoon. transformation. Parser. Transformer. generate. Key() { return this. grammar. Source. get. URI(); } Usage example: Take data from a database and publish the content onto a web portal in HTML, PDF, and WHTML formats simultaneously. § AOP is another tool, it not a ‘silver bullet’ and conventional refactoring methodologies and tools are still necessary. Step 4: Testing & Verification Background: Refactoring – a change made to the internal structure of the software to make it easier to understand cheaper to modify without changing its observable behavior In Progress Integrating Aspect. J into Cocoon Ant build process References & Resources § Apache Cocoon Project http: //cocoon. apache. org/ § Aspect. J Project - http: //www. aspectj. com/ § Project website – http: //cs. union. edu/~daltonj/ § Thanks to the Aspect. J team at Hursley for their valuable assistance and for providing some background information on AOP.
- Slides: 1