220 likes | 359 Views
Aspect-Oriented Refactoring of the Apache Cocoon Shared-Object Resource Allocation System. Jeff Dalton February 28th, 2003 Advisor: David G. Hannay Client: Robert Berry, IBM UK. Arthur Octopus The AspectJ Mascot. Agenda. AOP & Cocoon Background Refactoring Goals & Process
E N D
Aspect-Oriented Refactoring of the Apache Cocoon Shared-Object Resource Allocation System Jeff Dalton February 28th, 2003 Advisor: David G. Hannay Client: Robert Berry, IBM UK Arthur Octopus The AspectJ Mascot
Agenda • AOP & Cocoon Background • Refactoring Goals & Process • Challenges and Obstacles • The Future
What is Aspect Oriented Programming? • Concern – “a specific requirement or consideration that must be addressed in order to satisfy the overall system goal.” • AOP introduces a new unit of modularization—an aspect–that crosscuts other modules. • Aspect = pointcut + advice + intertype declaration • intertype declaration Fields and methods that the aspect manages on behalf of other types - The Java AOP implementation
A Cross-cutting concern • Logging in org.Apache.Tomcat • Red shows lines of code that handles logging • Not in one place. Not in a small number of places.
Apache Cocoon:Dynamic multi-channel web publishing • “Apache Cocoon is a web development framework built around the concepts of separation of concerns and component-based web development.” – Cocoon website Usage example: • Take data from a database and publish the content onto a web portal in HTML, PDF, Office format, and text format all simultaneously.
Performance as crosscutting concern • Performance optimizations: Caching & Pooling • Effective techniques to improve performance • Caching – recycling of resources that are expensive to create and discard where more than one user can use a single object • “Read only” • A.K.A. – “Shared Object Resource Allocation”
Cocoon Caching Architecture • Caching happens at the pipeline level with each different phase of the transformation being cached, if possible. Caching
Cocoon Caching Architecture • SAX events and caching management is done in a central location: CacheManager • However, to be cached the classes must implement the abstract interface ...cocoon.caching.CacheableProcessingComponent • Two methods to be implemented: • Serializable generateKey(); • SourceValdity generateValidity();
Refactoring Cocoon Caching • The Challenge: • Implementing the CacheableProcessingComponent and its methods is the crosscutting concern, we need to abstract it. • Accomplished through • Introductions – in AspectJ “Intertype Declarations” • The addition of methods, fields, interfaces, or inheritance information that does not directly affect the class’s behavior • Simple in concept, not trivial in practice. • Large, complex web application (~4600 class files with all blocks)
AOP Adoption • new services, programming model • product lines • extend J2EE • Web services, mobile, P2P... • aspect libraries • design patterns • enterprise, department standards • module design • persistence • management • security • feature variations • limited use • design • error handling • standards & contracts • monitoring Value • 15 minutes • 30 lines • unpluggable • testing • tracing • performance measurement Development Support forExisting Code AddAuxiliaryFunctionality Re-factor CoreFunctionality ReusableLibraries Aspect-OrientedArchitecture
Goals Project Task • Refactor the caching system in Cocoon Goals • Gain experience with application of AOP to a large scale, well structured application environment. • Identify and quantify opportunities for using AOP to simplify an already modular code base. • Use AOP to enhance modularity/componentization of Cocoon.
Process: Approach • Used AspectJ to define a compiler warning in order to identify locations in Cocoon that implement the CacheableProcessingComponent abstract interface. • Wrote aspects to encapsulate the functionality. • Removed the code encapsulated into aspects from the base classes identified in step 1. • Wove the aspects into Cocoon using AspectJ compiler.
Step 1: Identify Locations publicaspectExploreCaching{ declarewarning:staticinitialization(org.apache.cocoon.caching.CacheableProcessingComponent+)&&!within(org.apache.cocoon.caching..*):"Class implements cacheable"; }
Step 2: Write Caching Aspects Excerpt: privilegedpublicaspectCachingAspect{ /* Ascii art generator */ declareparents: org.apache.cocoon.generation.asciiart.AsciiArtSVGGenerator implements CacheableProcessingComponent; public Serializable org.apache.cocoon.generation.asciiart.AsciiArtSVGGenerator.generateKey() { returnthis.inputSource.getURI(); } public SourceValidity org.apache.cocoon.generation.asciiart.AsciiArtSVGGenerator.generateValidity(){ returnthis.inputSource.getValidity(); } …. Introduce Interface Introduce Methods
Step 3 & 4: Remove References & Weave Code Removed
Testing & Verification • Finished: • Cocoon without caching deployed • In process • Integrating AspectJ Compiler into build process
Challenges & Obstacles • Domain knowledge is the biggest challenge • Ex. Cache (external pipeline cache) vs. Store (Internal Object cache) • Eclipse AspectJ Development Tools (1.1.4) • Scalability issues: over 4600 classes in Cocoon • Bug: Memory Leak (Fix coming in 1.2 – ‘Lancaster’) • Bug: Abstract class that extend abstract class with concrete subclasses are woven too early - (Fixed in 1.1.6) • Ongoing modifications to cocoon caching system
Future work • Use AOP to refactor the ‘internal cache’ • Refactor other non-performance crosscutting concerns into aspects • Object Recycling, Logging, etc… • An event-aware AOP caching system • Use AOP to catch SAX events and perform cache invalidations
The Future: AOP • New versions, better tools • AspectJ 1.2 – “Lancaster” for Eclipse 3.0 • “Aspect Mining” – Better ways towards aspect discovery • Concern Modeling Environment • http://www.eclipse.org/cme/ • “To general software developers it offers a suite of tools for use in creating, manipulating, and evolving aspect-oriented software, across the full software lifecycle” • IBM Watson Lab – Yorktown Heights • Aspect Mining Tool • More work to be done: AI and pattern recognition • AOSD 2004 in Lancaster, UK, March 22-25th
Results I Question • How should you structure your application to simplify AO extendibility? Answer • Good coding practice makes AO adoption easier • Standard variable naming • Standard accessor methods Question • How can we improve the AO implementation? Answer • Refactor ‘similar’ code to remove differences Question • How should aspects be viewed on a design level? Answer • Still open!
Results II Summary: • Abstracted 39 implementations of CacheableProcessingComponent. • Used AOP to condense and remove 24 methods from the base implementation. Example: Duplicate code: publicSerializableorg.apache.cocoon.transformation.LexicalTransformer.generateKey(){ returnthis.lexiconSource.getURI(); } publicSerializableorg.apache.cocoon.transformation.ParserTransformer.generateKey(){ returnthis.grammarSource.getURI(); }
Questions AOP: The here, the now, and the future! Oliver the Octopus Concept and name credited to: AspectJ team, IBM Hursley, UK