AspectWerkz Dynamic AOP For Java David Rabinowitz.

Slides:



Advertisements
Similar presentations
Introduction to Java 2 Programming Lecture 4 Writing Java Applications, Java Development Tools.
Advertisements

AspectWerkz 2 - and the road to AspectJ 5 Jonas Bonér Senior Software Engineer BEA Systems.
1..28 comparison of the leading aop tools report on February developerWorks articles Mik Kersten University of British Columbia.
Aspect Oriented Programming. AOP Contents 1 Overview 2 Terminology 3 The Problem 4 The Solution 4 Join point models 5 Implementation 6 Terminology Review.
1 JAC : Aspect Oriented Programming in Java An article review by Yuval Nir and Limor Lahiani.
AspectWerkz Plain Java AOP Presented by: Gal Ostfeld January, 2005 Technion, Israel.
Overview of AspectJ Aspect Oriented Software Development Seminar Technion presented by Oren Mishali.
Aspect-Oriented Programming In Eclipse ® Aspect-Oriented Programming in Eclipse with AspectJ Dr Helen Hawkins and Sian January.
University of British Columbia Software Practices Lab Fluid AOP Join Point Models Terry Hon Gregor Kiczales.
George Blank University Lecturer. CS 602 Java and the Web Object Oriented Software Development Using Java Chapter 4.
Review Amit Shabtay. March 3rd, 2004 Object Oriented Design Course 2 Review What have we done during the course? Where to learn more? What is for the.
University of British Columbia Software Practices Lab CAS Seminar 06 Fluid AJ - A Simple Fluid AOP Tool Terry Hon Gregor Kiczales.
Aspect Oriented Programming Written by Michael Beder.
Review David Rabinowitz. March 3rd, 2004 Object Oriented Design Course 2 Review What have we done during the course? Which topics we have not discussed?
1 CMSC 132: Object-Oriented Programming II Java Constructs Department of Computer Science University of Maryland, College Park.
Outline Introduction Problem Statement Object-Oriented Design Aspect-Oriented Design Conclusion Demo.
Aspects in the Real World Applying AOSD techniques in large systems.
Introduction to Object Oriented Programming. Object Oriented Programming Technique used to develop programs revolving around the real world entities In.
Developing Adaptive J2ME Applications Using AspectJ Ayla Débora and Paulo Borba {add, Centro de Informática - UFPE.
Introduction to Aspect Oriented Programming Presented By: Kotaiah Choudary. Ravipati M.Tech IInd Year. School of Info. Tech.
Session 2: AspectJ Mark Stobbe September 13,
Programming in Java Unit 2. Class and variable declaration A class is best thought of as a template from which objects are created. You can create many.
By Nicholas Policelli An Introduction to Java. Basic Program Structure public class ClassName { public static void main(String[] args) { program statements.
1 Module Objective & Outline Module Objective: After completing this Module, you will be able to, appreciate java as a programming language, write java.
CSCE 2013L: Lab 1 Overview  Java Basics The JVM Anatomy of a Java Program  Object-Oriented Programming Overview  Example: Payroll.java JDK Tools and.
The Java Programming Language
Aspect Oriented Programming Sumathie Sundaresan CS590 :: Summer 2007 June 30, 2007.
Aspect-Oriented Refactoring of the Apache Cocoon Shared-Object Resource Allocation System Jeff Dalton February 28th, 2003 Advisor: David G. Hannay Client:
Hello.java Program Output 1 public class Hello { 2 public static void main( String [] args ) 3 { 4 System.out.println( “Hello!" ); 5 } // end method main.
Netprog: Java Intro1 Crash Course in Java. Netprog: Java Intro2 Why Java? Network Programming in Java is very different than in C/C++ –much more language.
Aspect Oriented Programming Gülşah KARADUMAN.
JAVA BASICS Prepared by The Smartpath Information Systems
Joel Phinney March 31, ◦ Concerns  Separation of Concerns, Tangled and Scattered Concerns, Cross-Cutting Concerns, Aspects ◦ Aspect-Oriented Software.
Methodology: The AOP Refactoring Process Aspect-Oriented Refactoring of the Apache Cocoon Shared-Object Resource Allocation System Jeff Dalton Advisor:
A Presentation By V AIBHAV S AHARAN Web-enHanced Information Management COMS E6125.
AOP-1 Aspect Oriented Programming. AOP-2 Aspects of AOP and Related Tools Limitation of OO Separation of Concerns Aspect Oriented programming AspectJ.
Region Pointcut for AspectJ Shumpei Akai Shigeru Chiba Muga Nishizawa.
Inter-Type Declarations in AspectJ Awais Rashid Steffen Zschaler © Awais Rashid, Steffen Zschaler 2009.
AspectJ – AOP for Java Tom Janofsky. Instructor at Penn State Abington Consultant with Chariot Solutions JUG Member.
Course Progress Lecture 1 –Java data binding: Basket example: UML class diagram -> class dictionary without tokens-> language design -> class dictionary.
Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University IWPSE 2003 Program.
Object Oriented Programming
1 Deriving Refactorings for AspectJ Leonardo Cole Paulo Borba Informatics Center Federal University of Pernambuco Brazil.
ODS – Introduction to Web Services and BPEL Vakgroep Informatietechnologie Web Services & BPEL Design of Distributed Software.
1 COS 260 DAY 14 Tony Gauvin. 2 Agenda Questions? 6 th Mini quiz graded  Oct 29 –Chapter 6 Assignment 4 will be posted later Today –First two problems.
CSCE 314 Programming Languages Reflection Dr. Hyunyoung Lee 1.
Kansas City Java User’s Group Jason W. Bedell July 12, 2006
问题 Code scattering Blocks of duplicated code Blocks of complementary code, and different modules implementing complementary parts of the concern Code.
Comparison of Different AOP Approaches Presented by: Xiaojing Wang.
aspectj tools new and noteworthy Mik Kersten University of British Columbia Adrian Colyer IBM Hursley OOPSLA, October
Chapter 6 - More About Problem Domain Classes1 Chapter 6 More About Problem Domain Classes.
Written by: Dr. JJ Shepherd
AOP with AspectJ Awais Rashid, Steffen Zschaler © Awais Rashid, Steffen Zschaler 2009.
Lecture10 Exception Handling Jaeki Song. Introduction Categories of errors –Compilation error The rules of language have not been followed –Runtime error.
AspectJ Development Tools Mik Kersten University of British Columbia October 28, 2003.
Features of AOP languages AOP languages have the following main elements: –a join point model (JPM) wrt base PL –a specification language for expressing.
Leveraging ColdSpring to build a robust Flex applications Chris Scott, Cynergy Systems.
Chengyu Sun California State University, Los Angeles
Aspect-Oriented Programming with the Eclipse AspectJ plug-in
Aspect-Oriented Programming
AspectJ Syntax Basics.
Java Programming Language
ЕВОЛУЦИЈА СОФТВЕРА ПОДРЖАНА АСПЕКТНО-ОРИЈЕНТИСАНИМ ПРОГРАМИРАЊЕМ
Chengyu Sun California State University, Los Angeles
CS520 Web Programming Spring – Aspect Oriented Programming
AspectAda Aspect-Oriented Programming for Ada95
Java Remote Method Invocation
CSCE 314: Programming Languages Dr. Dylan Shell
Aspect Oriented Programming
Presentation transcript:

AspectWerkz Dynamic AOP For Java David Rabinowitz

March 3rd, 2004 Object Oriented Design Course 2 Aspect Oriented Programming Cross-cutting concerns System wide common handling Security, logging, persistence, synchronization Advices The additional code applied to the existing model Point-cuts Where the advice should be applied Aspects Combinations of point-cuts and advices

March 3rd, 2004 Object Oriented Design Course 3 Current AOP Implementations Focusing on Java Other implementations for.NET, C++, Ruby, Smalltalk and more AspectJ Extend the Java language itself Introduce the notion of an aspect is another type of class

March 3rd, 2004 Object Oriented Design Course 4 Java AOP Implementations Other implementations Work within Java Dynamic proxies, reflection, bytecode manipulation, custom class loading Aspect, advice and point-cut are plain Java classes Several implementations: AspectWerkz JBossAOP Spring framework And more

March 3rd, 2004 Object Oriented Design Course 5 AspectWerkz A dynamic, lightweight AOP framework for Java Allows adding aspects to new code as well to existing applications Advices can be plain Java objects (POJO)

March 3rd, 2004 Object Oriented Design Course 6 Example Advice public Object myAroundAdvice(JoinPoint joinPoint) throws Throwable { // do stuff Object result = joinPoint.proceed(); // do more stuff return result; }

March 3rd, 2004 Object Oriented Design Course 7 JoinPoint A well-defined point in the program flow Provides information on: The signature of the code (method/field/…) RTTI information JoinPoint.proceed() – telling the program to continue

March 3rd, 2004 Object Oriented Design Course 8 Advice types Around advice Invoked "around" the join point After advice Invoked after the join point Before advice Invoked before the join point JoinPoint.proceed() can only be called in around advices, otherwise you have infinite loops

March 3rd, 2004 Object Oriented Design Course 9 Definitions There are two aspect definition models External XML file Javadoc-like attributes Using XML … is using well known and supported format … is more complex, no refactoring

March 3rd, 2004 Object Oriented Design Course 10 Using Attributes Aspect are self contained Puts the definition and implementation in single class Makes it easy to build reusable aspect libraries

March 3rd, 2004 Object Oriented Design Course 11 Point-cut Types (1) execution( ) picks out join points defining method (static or member) or constructor execution call( ) picks out join points defining method (static or member) or constructor call get/set( ) picks out join points defining field access/modification. Valid advice for these pointcuts are around, before and after

March 3rd, 2004 Object Oriented Design Course 12 Point-cut Types (II) handler( ) picks out join points definining a catch clause. Valid advice for this pointcut is before

March 3rd, 2004 Object Oriented Design Course 13 Point-cut selection pattern language Defines where To Add the Advice * wildcard One package level or one method parameter At least one character (package name) Zero or more characters (otherwise).. Wildcard Any sequence of characters that start and end with a ".", org.codehaus..* will match all classes in all subpackages starting from org.codehaus

March 3rd, 2004 Object Oriented Design Course 14 How To Choose Classes? foo.bar.* - will match foo.bar.FooBar2 as well as foo.bar.FooBear foo.*.FooBar - will match foo.bar.FooBar2 as well as foo.bear.FooBar but not foo.bear.FooBear foo.*.FooB* - will match foo.bar.FooBar2 as well as foo.bear.FooBear as well as foo.bear.FooB

March 3rd, 2004 Object Oriented Design Course 15 How To Choose Fields? int foo.*.Bar.m_foo - will match int m_foo but not int s_foo or long m_foo * foo.*.Bar.m_foo - will match int m_foo as well as java.lang.String m_foo java.lang.* foo.*.Bar.m_foo - will match java.lang.String m_foo as well as java.lang.StringBuffer m_foo

March 3rd, 2004 Object Oriented Design Course 16 How To Choose Methods? (I) int foo.*.Bar.method() - will match int method() but not int method(int i) int *.method(*) - will match int Foo.method(int i) but not int Foo.method()

March 3rd, 2004 Object Oriented Design Course 17 How To Choose Methods? (II) int foo.*.*.method(*,int) - will match int method(String s, int i) as well as int method(int i1, int i2) int foo.*.Bar.method(..) - will match int method() as well as int method(String s, int i) as well as int method(int i, double d, String s, Object o)

March 3rd, 2004 Object Oriented Design Course 18 How To Choose Methods? (III) There are many more examples Variation of return type, method name and parameters Check definition_issues.html

March 3rd, 2004 Object Oriented Design Course 19 What About Constructors? Use “new” as method name foo.*.Bar.new() - will match new Bar() but not new Bar(int i) *.new(String) - will match new Foo(String name) and new Bar(String name) but not new Foo()

March 3rd, 2004 Object Oriented Design Course 20 Subtyping As we saw, the pattern * foo.Bar.*(..) will match any method declared in foo.Bar What about foo.Bar2 who extend foo.Bar? The pattern is * foo.Bar+.*(..)

March 3rd, 2004 Object Oriented Design Course 21 Point-cut composition Using the logical operators &&, ||, ! and () execution(* foo.bar.Baz.*(..)) || call(* foo.bar.Baz.*(..)) (set(* foo.bar.*) || get(* foo.bar.*)) && cflow(* foo.bar.Buzz.(..)) handler(java.lang.Exception+) && !cflow(* foo.bar.Buzz.(..))

March 3rd, 2004 Object Oriented Design Course 22 Example Code perInstance */ public class LoggingAspect extends Aspect { } * foo.bar.*.*(..) */ Pointcut logMethodCall; * foo.baz.*.*(..) */ Pointcut logMethodExecution; logMethodCall */ public void logEntry(JoinPoint joinPoint) {... } logMethodCall */ public void logExit(JoinPoint joinPoint) {... } logMethodExecution */ public Object logExecution(JoinPoint joinPoint) {... }

March 3rd, 2004 Object Oriented Design Course 23 Equivalent XML (I) <pointcut name="logMethodCall" expression="call(* foo.bar.*.*(..))"/> <pointcut name="logMethodExecution" expression="execution(* foo.baz.*.*(..))"/>

March 3rd, 2004 Object Oriented Design Course 24 Equivalent XML (II) <advice name="logEntry" type="before" bind-to="logMethodCall"/> <advice name="logExit" type="after" bind-to="logMethodCall"/> <advice name="logExecution" type="around" bind-to="logMethodExecution"/>

March 3rd, 2004 Object Oriented Design Course 25 Caching Example /** execution(int examples.caching.Pi.getPiDecimal(int)) */ public Object cache(final JoinPoint joinPoint) throws Throwable { MethodRtti rtti = (MethodRtti)joinPoint.getRtti(); final Long hash = new Long(calculateHash(rtti)); final Object cachedResult = m_cache.get(hash); if (cachedResult != null) { return cachedResult; } final Object result = joinPoint.proceed(); m_cache.put(hash, result); return result; }

March 3rd, 2004 Object Oriented Design Course 26 Exception Handling Example public class ExceptionHandlingAspect { /** handler(java.lang.Exception) */ public void logEntry(final JoinPoint joinPoint) throws Throwable { CatchClauseRtti rtti = (CatchClauseRtti)joinPoint.getRtti(); Exception e = (Exception)rtti.getParameterValue(); System.out.println( "[From advice] exception catched:" + e.toString()); }

March 3rd, 2004 Object Oriented Design Course 27 How To Use It? How do we add aspect to existing code? There are two modes: Online – “using” AspectWerkz as the virtual machine (instead of java) Offline – the class file are post-processed and the aspects are added

March 3rd, 2004 Object Oriented Design Course 28 Offline mode (I) Command line tool: aspectwerkz -offline [-cp ]* +

March 3rd, 2004 Object Oriented Design Course 29 Offline mode (II) Instead of aspectwerkz you can write “java org.codehaus.aspectwerkz. compiler.AspectWerkzC” Why this is important? Ant task More about it in the “introduction to ant” tirgul

March 3rd, 2004 Object Oriented Design Course 30 Where can you find it? ~ood/aspectwerkz Set the ASPECTWERKZ_HOME environment variable Add $ASPECTWERKZ_HOME/lib to the classpath Add $ASPECTWERKZ_HOME/bin to PATH

March 3rd, 2004 Object Oriented Design Course 31 Start Early It is a complex framework Don’t wait to exercise 5 to learn it There many examples in ~ood/aspectwerkz/src/samples run them and see that you understand them Next week How do we easily add the post process to the build process?

March 3rd, 2004 Object Oriented Design Course 32 More Information /01/14/aop.html