Presentation is loading. Please wait.

Presentation is loading. Please wait.

Aspect-Oriented Refactoring of the Apache Cocoon Shared-Object Resource Allocation System Jeff Dalton February 28th, 2003 Advisor: David G. Hannay Client:

Similar presentations


Presentation on theme: "Aspect-Oriented Refactoring of the Apache Cocoon Shared-Object Resource Allocation System Jeff Dalton February 28th, 2003 Advisor: David G. Hannay Client:"— Presentation transcript:

1 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

2 Agenda AOP & Cocoon Background Refactoring Goals & Process Challenges and Obstacles The Future

3 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

4 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.

5 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.

6 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”

7 Cocoon Caching Architecture Caching happens at the pipeline level with each different phase of the transformation being cached, if possible. Caching

8 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();

9 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)

10 AOP Adoption Value Development Support for Existing Code 15 minutes 30 lines unpluggable testing tracing performance measurement limited use design error handling standards & contracts monitoring Add Auxiliary Functionality Re-factor Core Functionality Reusable Libraries Aspect-Oriented Architecture module design persistence management security feature variations aspect libraries design patterns enterprise, department standards new services, programming model product lines extend J2EE Web services, mobile, P2P...

11 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.

12 Process: Approach 1. Used AspectJ to define a compiler warning in order to identify locations in Cocoon that implement the CacheableProcessingComponent abstract interface. 2. Wrote aspects to encapsulate the functionality. 3. Removed the code encapsulated into aspects from the base classes identified in step 1. 4. Wove the aspects into Cocoon using AspectJ compiler.

13 Step 1: Identify Locations public aspect ExploreCaching { declare warning: staticinitialization(org.apache.cocoon.caching.CacheableProcessingComponent+) && !within(org.apache.cocoon.caching..*): "Class implements cacheable"; }

14 Step 2: Write Caching Aspects Excerpt: privileged public aspect CachingAspect { /* Ascii art generator */ declare parents: org.apache.cocoon.generation.asciiart.AsciiArtSVGGenerator implements CacheableProcessingComponent; public Serializable org.apache.cocoon.generation.asciiart.AsciiArtSVGGenerator.generateKey() { return this.inputSource.getURI(); } public SourceValidity org.apache.cocoon.generation.asciiart.AsciiArtSVGGenerator.generateValidity() { return this.inputSource.getValidity(); } …. Introduce Interface Introduce Methods

15 Step 3 & 4: Remove References & Weave Code Removed

16 Testing & Verification Finished: – Cocoon without caching deployed In process – Integrating AspectJ Compiler into build process

17 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

18 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

19 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/ 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

20 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!

21 Results II Summary: Abstracted 39 implementations of CacheableProcessingComponent. Used AOP to condense and remove 24 methods from the base implementation. Example: Duplicate code: public Serializable org.apache.cocoon.transformation.LexicalTransformer.generateKey() { return this.lexiconSource.getURI(); } public Serializable org.apache.cocoon.transformation.ParserTransformer.generateKey() { return this.grammarSource.getURI(); }

22 Questions Oliver the Octopus Concept and name credited to: AspectJ team, IBM Hursley, UK AOP: The here, the now, and the future!


Download ppt "Aspect-Oriented Refactoring of the Apache Cocoon Shared-Object Resource Allocation System Jeff Dalton February 28th, 2003 Advisor: David G. Hannay Client:"

Similar presentations


Ads by Google