Introduction to Aspect-Oriented Programming. CHUUG - Feb. 24, 2004 Brian Sletten

Similar documents
Aspect-Oriented Programming

Chapter 5 Aspect Oriented Programming

A COMPARISON OF AOP BASED MONITORING TOOLS

Generating Aspect Code from UML Models

Aspect-Oriented Software Development

Using an Aspect Oriented Layer in SOA for Enterprise Application Integration

Glassbox: Open Source and Automated Application Troubleshooting. Ron Bodkin Glassbox Project Leader

Compose*: Language-Independent Aspects for.net

Remote Pointcut - A Language Construct for Distributed AOP

AOSD - Enhancing SoC :: INF5120 :: Mansur Ali Abbasi. AOSD :: Aspect Oriented Software Development SoC :: Separation of Concerns

Aspect Oriented Programming. with. Spring

Unification of AOP and FOP in Model Driven Development

How To Combine Feature-Oriented And Aspect-Oriented Programming To Support Software Evolution

Combining Feature-Oriented and Aspect-Oriented Programming to Support Software Evolution

Encapsulating Crosscutting Concerns in System Software

Progress Report Aspect Oriented Programming meets Design Patterns. Academic Programme MSc in Advanced Computer Science. Guillermo Antonio Toro Bayona

Keywords Aspect-Oriented Modeling, Rule-based graph transformations, Aspect, pointcuts, crosscutting concerns.

The Nature and Importance of a Programming Paradigm

Aspect-oriented Refactoring of a J2EE Framework for Security and Validation Concerns

Decomposition into Parts. Software Engineering, Lecture 4. Data and Function Cohesion. Allocation of Functions and Data. Component Interfaces

Designing an Enterprise Application Framework for Service-Oriented Architecture 1

Aspectual Mixin Layers

Architecture Rules Enforcement and Governance Using Aspects

Composing Concerns with a Framework Approach

Integration of Application Business Logic and Business Rules with DSL and AOP

Smalltalk in Enterprise Applications. ESUG Conference 2010 Barcelona

Aspect-oriented software engineering

Harmless Advice. Daniel S Dantas Princeton University. with David Walker

Aspect-Oriented Web Development in PHP

Security Design Patterns

RE-TRUST Design Alternatives on JVM

OUR COURSES 19 November All prices are per person in Swedish Krona. Solid Beans AB Kungsgatan Göteborg Sweden

ARM-BASED PERFORMANCE MONITORING FOR THE ECLIPSE PLATFORM

How To Create A C++ Web Service

A standards-based approach to application integration

Beginning POJOs. From Novice to Professional. Brian Sam-Bodden

JBS-102: Jboss Application Server Administration. Course Length: 4 days

Component-Based Software Development with Aspect-Oriented Programming

The Service Revolution software engineering without programming languages

Eliminating SQL Injection and Cross-Site Scripting With Aspect Oriented Programming

Aspect-Oriented Multi-Client Chat Application

Oracle WebLogic Foundation of Oracle Fusion Middleware. Lawrence Manickam Toyork Systems Inc

Integration of Application Business Logic and Business Rules with DSL and AOP

New Generation of Software Development

.NET and J2EE Intro to Software Engineering

Case Studies of Running the Platform. NetBeans UML Servlet JSP GlassFish EJB

Software Engineering Techniques

Eclipse Visualization and Performance Monitoring

Kotrappa Sirbi, Prakash Jayanth Kulkarni

language 1 (source) compiler language 2 (target) Figure 1: Compiling a program

JOURNAL OF OBJECT TECHNOLOGY

Post object-oriented paradigms in software development: a comparative analysis

Patterns for Handling Cross-Cutting Concerns in Model-Driven Software Development

Service Oriented Architectures

Introducing a Graduate Course on. called Aspect-Oriented Software Development

Software Engineering and Technology Trends

FUSE-ESB4 An open-source OSGi based platform for EAI and SOA

Aspect Refactoring Verifier

Load balancing using Remote Method Invocation (JAVA RMI)

An Aspect-Oriented Product Line Framework to Support the Development of Software Product Lines of Web Applications

Operations and Monitoring with Spring

Toward Configurable Access Control for. Healthcare Information Systems

How to Model Aspect-Oriented Web Services

Monitoring, Tracing, Debugging (Under Construction)

This presentation is for informational purposes only and may not be incorporated into a contract or agreement.

Component Middleware. Sophie Chabridon. INT - INF Department - Distributed Systems team 2006

Coordinated Visualization of Aspect-Oriented Programs

International Journal of Web & Semantic Technology (IJWesT) Vol.3, No.3, July Vishnuvardhan Mannava 1 and T. Ramesh 2

Java Monitoring. Stuff You Can Get For Free (And Stuff You Can t) Paul Jasek Sales Engineer

Next-Generation ESB. Kevin Conner SOA Platform Architect, Red Hat Keith Babo JBoss ESB Project Lead, Red Hat. June 23rd, 2010

Apache Tomcat. Load-balancing and Clustering. Mark Thomas, 20 November Pivotal Software, Inc. All rights reserved.

Aspect Weaving for OSGi. Martin Lippert (akquinet it-agile GmbH)

SOA REFERENCE ARCHITECTURE: WEB TIER

The Java Series. Java Essentials I What is Java? Basic Language Constructs. Java Essentials I. What is Java?. Basic Language Constructs Slide 1

Converting Java EE Applications into OSGi Applications

Modern Software Development Tools on OpenVMS

Designing with Exceptions. CSE219, Computer Science III Stony Brook University

Architecture Summary. Prepared by Architecture Working Group. Goals and summary: April 4, 2012 Updated recommendation: Nov 7, 2013

Challenges and Opportunities for formal specifications in Service Oriented Architectures

The Concern-Oriented Software Architecture Analysis Method

Crash Course in Java

Developing modular Java applications

BONITA, The Open Source BPM Solution

ActiveVOS Server Architecture. March 2009

Instrumentation Software Profiling

Web Application Access Control with Java SE Security

JBoss Seam Performance and Scalability on Dell PowerEdge 1855 Blade Servers

Implementing COOL in JAMI

On Type Restriction of Around Advice and Aspect Interference

Adaptability in Object-Oriented Software Development Workshop report

GlassFish v3. Building an ex tensible modular Java EE application server. Jerome Dochez and Ludovic Champenois Sun Microsystems, Inc.

Software Architecture & Composition. Guillaume Waignier, Anne-Françoise Le Meur, Laurence Duchien Project-Team U. Lille 1/CNRS-INRIA

Aspects for Testing Aspects?

PHP vs. Java. In this paper, I am not discussing following two issues since each is currently hotly debated in various communities:

SOA Fundamentals For Java Developers. Alexander Ulanov, System Architect Odessa, 30 September 2008

Concern Highlight: A Tool for Concern Exploration and Visualization

Building Java Servlets with Oracle JDeveloper

Clustering with Tomcat. Introduction. O'Reilly Network: Clustering with Tomcat. by Shyam Kumar Doddavula 07/17/2002

Best Practices for Mobile Content Development Using Aspect Oriented Programming

Learn Java - The Application Monitor Aspect Pattern

Transcription:

Introduction to Aspect-Oriented Programming CHUUG - Feb. 24, 2004 Brian Sletten brians@acm.org

What AOP Is Not Brand New A Silver Bullet A Replacement for OOP A Patch For Bad Design Only Good for Academic Navel- Gazing

Agenda Backstory AOP AspectJ Other AOP Systems Summary

Backstory

History Paradigm Procedural Abstraction Functional Object-Oriented Object Design Patterns Design Aspect-Oriented Concern

Separation of Concerns (SOC) Intellectual forebear to AOP Reduction of Code Coupling and Tangling Flexibility and Reuse in Design Pay As You Go

What is a Concern?...A specific requirement or consideration that must be addressed in order to satisfy the overall system goal... AspectJ in Action, p.9

Example Concerns Logging Thread Synchronization Persistence Domain Modeling/Business Logic Security Exception-Handling

Prism Metaphor for SOC Business Logic Thread Synchronization Built System Requirements Persistence Logging Security

Some Non-AOP Solutions Dynamic Proxies Controlled Access to underlying object Servlet Filters XSLT Transformations, Compression Design Patterns Decorator Pattern

Interception Pattern All three approaches demonstrate the notion of interception Could also be Dynamic Proxies or Filters DecoratorClass1 DecoratorClass2 Receiver foo() foo() foo()

AOP

OO is Good For int x int y foo() bar() A Object Abstractions int z bar() baz() B C String name Date dob int id bar() zoo() D

OO Is Not Good For int x int y foo() bar() A int z bar() baz() B C String name Date dob int id bar() zoo() D Concern Abstractions that are Cross-Cutting

What is a Cross-Cutting Concern? A feature or requirement that does not fit into a class-only decomposition Poorly modularized cross-cutting concerns result in Code Tangling Code Scattering

Code Tangling int x int y foo() bar() A Multiple concerns complicate class behavior Reuse is hampered Maintenance is a bear Did security get called before persistence? Did I remember to synchronize after the logging?

Code Scattering Good Modularity Socket Creation in Tomcat Fair modularity Classloading in Tomcat Bad modularity Logging in Tomcat Analysis compliments of Ron Bodkin (http://www.newaspects.com)

Limitations of OO Object-oriented programming is great for modeling object abstractions Suffers from the Tyranny of the Dominant Decomposition * When all you have is a class... No support for cross-cutting concerns *Term from the Hyper/J team

What is an Aspect?...A unit of modularization for cross-cutting concerns

Goals of AOP... to appropriately modularize crosscutting concerns Does not replace class-based decomposition of OOP Promotes architectural flexibility and reduced coupling/tangling

AOP Process Remember the Prism Once the concerns are separated and modularized, they are woven together Compile-time or run-time Production and Development Aspects

Benefits of AOP Each module has a clear definition Simpler to implement Modules know as little about each other as possible Easier to maintain Better chance for reuse Evolution of system architecture Weave features as neded

AspectJ

AspectJ Overview Developed at XEROX PARC Team lead by Gregor Kiczales Designed as an extension to Java Aspects look an awful lot like Classes Requires a separate compiler but emits standard bytecode that can run on any JVM Easy to incorporate into conventional Java build processes

AspectJ Today Spun off to the Eclipse Project Maintained by many of the same people AJDT is a cool plug-in for Eclipse Increasingly in use in development and production systems

What is a Join Point? Any identifiable/describable point in the control flow of a program A method call (caller side) A method execution (callee side) Setting/Getting a variable A constructor

What is a Pointcut? Expressions that select some set of join points and their context arguments Object being called return values variable being referenced

What is Advice? Pieces of code that are associated with one or more pointcuts Executed when the pointcut is reached before advice - executed before pointcut after advice - executed after pointcut around advice - executed around point

Putting it together A join point is where you would like to run some code (before,after,around -advice) when (pointcut) you get there

Finally, Some Code! public class Foo { private int count; public Foo() { } public void sayhello() { System.out.println("Hello, AOP!"); count++; } } public int getcount() { return count; }

A Simple Aspect public aspect FooAspect { before() : call( * sayhello(..) ) { System.out.println("Before the greeting!"); } } The aspect FooAspect has before() advice for the pointcut specifying any call to a method called sayhello no matter how many arguments it takes.

Main method public static void main( String [] args ) { Foo f = new Foo(); f.sayhello(); } FooAspect <<aspect>> before() : call( sayhello ) <<advises>> Foo int count sayhello() main()

Making it happen ajc -classpath.:/usr/local/aspectj1.1/lib/aspectjrt.jar *.java java -cp.:/usr/local/aspectj1.1/lib/aspectjrt.jar Foo Before the greeting! Hello, AOP! ajc is the AspectJ compiler aspectjrt.jar is the runtime support for AspectJ It compiles the Java source files into a standard Java class file

Add Another Pointcut before() : execution( * sayhello(..) ) { System.out.println("Also before the greeting!"); } ajc -classpath.:/usr/local/aspectj1.1/lib/aspectjrt.jar *.java java -cp.:/usr/local/aspectj1.1/lib/aspectjrt.jar Foo Before the greeting! Also before the greeting. Hello, AOP!

call vs. execute Foo Foo main sayhello() call( * sayhello (..) ) execution( * sayhello (..) ) Not conventional UML, Foo treated as two Objects just for clarity

around() advice int around() : execution( * getcount() ) { System.out.println( "Before getcount()" ); int retvalue = proceed(); System.out.println("After getcount()"); if( retvalue == 0 ) { System.out.println("That was the first call!" ); } } return retvalue; Notice the return type specified for the around() advice. proceed() causes the actual method to be called.

Some Ideas for before() advice Ensure a user has the right privileges to make the call in question Assert any precondition Help debug difficult problems like calling Swing code from the wrong thread!

Some Ideas for around() advice Obtain thread locks before calling proceed; release when done Only synchronize when you need it Allow different synchronization policies Catch any exception thrown on any method in an interface

Just the Tip of the Iceberg! AspectJ has so much more to offer Abstract/reusable aspects Pointcut context Exception softening Static cross-cutting

Other AOP Systems

Hyper/J Developed at IBM Harold Osher and Terri Parr Comes out of the Subject-Oriented Programming efforts Multi-dimensional separation of concerns

Hyper/J (cont) Software is configured by files indicating how to assemble concern hyperslices Java-based but could be applied to other languages in theory Doesn t have the activity that AspectJ does but is still supported and used

Composition Filters Developed at the University of Twente Mehmet Aksit and Lodewijk Begmans Interception -based Java implementation Work includes formalisms for composing filters Very compelling but mostly academic

DemeterJ Work done by Dr. Karl Lieberherr and students at Northeastern Univ. Originally as Separation of Concerns (SOC) Based on Adaptive Programming model - special case of AOP Building blocks are graphs and traversals Traversals cross-cut graphs

DemeterJ (cont) Follows Law of Demeter Only talk to your immediate friends that share your concerns Keeps tangling and complication down by cleanly separating concerns as graph traversals

More Java-based AOP JBOSS AOP JAC AspectWerkz Nanning

JBOSS AOP Built around Dynamic Proxies and interceptor stacks Add logging, persistence, replication, remoteness, ACIDity, caching and security to POJOs without changing Java code Smart resolution for method calls Avoid the marshalling penalty if target object lives in the same VM

JAC Based on Renaud Pawlak s Ph.D. Thesis Part of ObjectWeb Middleware Project Adds CMP, clustering, distributed transactions (via JOTM) and access authentication to POJOs Has Rapid Application Development features UMLAF IDE (UML Aspectual Factory)

AspectWerkz Most work by Jonas Bonér and Alexandre Vasseur Supported by BEA Lightweight, runtime bytecode modification via ClassLoader Advice can be modified at runtime XML-configuration or attributes Aspects/advice are written in plain Java

Nanning Most work by Jon Tirsen Simple Interception -based mechanism using Dynamic Proxies Also supports Mixins and Introduction (static cross-cutting) Designed to add EJB and J2EE kinds of features to POJOs

Non-Java AOP Largely unremarkable, inactive and lagging behind Java-based activity.net offers compelling cross-language pointcut vision AspectR and Aspect.pm seem to be dead

AspectC++ Modeled after AspectJ C++ language extensions that require a separate compiler Doesn t presently support get/set join points Commercial support from Pure Systems GmbH Plug-ins for VS.NET ($$) and Eclipse (in dev.)

AspectS Project to add AOP concepts to the Squeak environment Like many other approaches, the goal was not to modify the Smalltalk language or environment

Summary

AOP Today Fairly steep learning curve Learn good OO first Tools are too primitive for average use AJDT is improving this situation AOP augments OO Class-based decomposition works for many situations (i.e. modeling object abstractions)

AOP Today (cont) Folded in gradually in many production systems Very popular as part of development systems (sanity checks, mock objects, etc.) -- compiled out of production LOTS of research to make it easier, unify the approaches, improve aspect weaving and composition

ATrack Open source project to build a proof of concept AOP system from the ground up using AspectJ Bug Tracking system with persistence, transaction, session management, exception handling and logging as aspects Is also developing AJEE, a first cut at a Standard Aspect Library

AOP Consulting AspectMentor http://www.aspectmentor.com/ New Aspects of Software http://www.newaspects.com/

Getting Started Nanning, AspectWerkz and JAC are lightweight but don t have the best conceptual introductions AspectJ is the most commercialized AOP tool (tutorials, etc.) AspectJ in Action by Ramnivas Laddad is a great book (Manning Publications)

Links AspectJ AJDT Hyper/J Composition Filters DemeterJ AOSD JBoss AOP JAC AspectWerkz Nanning AspectC++ AspectS ATrack http://www.eclipse.org/aspectj http://www.eclipse.org/ajdt/ http://www.alphaworks.ibm.com/tech/hyperj http://trese.cs.utwente.nl/ composition_filters/ http://www.ccs.neu.edu/research/demeter/ DemeterJava/ http://www.aosd.net http://www.jboss.org/developers/projects/ jboss/aop http://jac.objectweb.org/ http://aspectwerkz.codehaus.org/ http://nanning.codehaus.org/ http://www.aspectc.org/ http://www.prakinf.tu-ilmenau.de/~hirsch/ Projects/Squeak/AspectS/ https://atrack.dev.java.net/