1 / 22

Aspect-Oriented Refactoring of the Apache Cocoon Shared-Object Resource Allocation System

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

wood
Télécharger la présentation

Aspect-Oriented Refactoring of the Apache Cocoon Shared-Object Resource Allocation System

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

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 • 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

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

  13. Step 1: Identify Locations publicaspectExploreCaching{ declarewarning:staticinitialization(org.apache.cocoon.caching.CacheableProcessingComponent+)&&!within(org.apache.cocoon.caching..*):"Class implements cacheable"; }

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

  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/ • “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: publicSerializableorg.apache.cocoon.transformation.LexicalTransformer.generateKey(){ returnthis.lexiconSource.getURI(); } publicSerializableorg.apache.cocoon.transformation.ParserTransformer.generateKey(){ returnthis.grammarSource.getURI(); }

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

More Related