ajdt: getting started with aspect-oriented programming in eclipse · 2017-12-06 · 9 ajdt: getting...

33
© 2005 by IBM and UBC; made available under the EPL v1.0 | 2 nd March 2005 AJDT: Getting started with Aspect-Oriented Programming in Eclipse Matt Chapman IBM Java Technology Hursley, UK AJDT Committer Andy Clement IBM Java Technology Hursley, UK AJDT & AspectJ Committer Mik Kersten UBC AJDT & AspectJ Committer

Upload: others

Post on 20-May-2020

0 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: AJDT: Getting started with Aspect-Oriented Programming in Eclipse · 2017-12-06 · 9 AJDT: Getting started with Aspect-Oriented Programming in Eclipse © 2005 by IBM and UBC; made

© 2005 by IBM and UBC; made available under the EPL v1.0 | 2nd March 2005

AJDT: Getting started with Aspect-Oriented Programming in Eclipse

Matt ChapmanIBM Java Technology

Hursley, UKAJDT Committer

Andy ClementIBM Java Technology

Hursley, UKAJDT & AspectJ Committer

Mik KerstenUBC

AJDT & AspectJ Committer

Page 2: AJDT: Getting started with Aspect-Oriented Programming in Eclipse · 2017-12-06 · 9 AJDT: Getting started with Aspect-Oriented Programming in Eclipse © 2005 by IBM and UBC; made

2AJDT: Getting started with Aspect-Oriented Programming in Eclipse © 2005 by IBM and UBC; made available under the EPL v1.0

Agenda

What is Aspect-Oriented Programming (AOP)?A brief overview of AspectJ

Demos demos demos…AspectJ Development Tools (AJDT) for Eclipse

Adopting the technology

Looking ahead…AJDTAspectJ

Page 3: AJDT: Getting started with Aspect-Oriented Programming in Eclipse · 2017-12-06 · 9 AJDT: Getting started with Aspect-Oriented Programming in Eclipse © 2005 by IBM and UBC; made

3AJDT: Getting started with Aspect-Oriented Programming in Eclipse © 2005 by IBM and UBC; made available under the EPL v1.0

good modularity

socket creation in Tomcatcolored lines show relevant lines of code

fits nicely into one package (3 classes)

Page 4: AJDT: Getting started with Aspect-Oriented Programming in Eclipse · 2017-12-06 · 9 AJDT: Getting started with Aspect-Oriented Programming in Eclipse © 2005 by IBM and UBC; made

4AJDT: Getting started with Aspect-Oriented Programming in Eclipse © 2005 by IBM and UBC; made available under the EPL v1.0

pretty good modularity

class loading in Tomcatcolored lines show relevant lines of code

mostly in one package (9 classes)

Page 5: AJDT: Getting started with Aspect-Oriented Programming in Eclipse · 2017-12-06 · 9 AJDT: Getting started with Aspect-Oriented Programming in Eclipse © 2005 by IBM and UBC; made

5AJDT: Getting started with Aspect-Oriented Programming in Eclipse © 2005 by IBM and UBC; made available under the EPL v1.0

not so good modularity

logging in Tomcatscattered across the packages and classes

error handling, security, business rules, …

Page 6: AJDT: Getting started with Aspect-Oriented Programming in Eclipse · 2017-12-06 · 9 AJDT: Getting started with Aspect-Oriented Programming in Eclipse © 2005 by IBM and UBC; made

6AJDT: Getting started with Aspect-Oriented Programming in Eclipse © 2005 by IBM and UBC; made available under the EPL v1.0

the cost of tangled code

redundant codesame fragment of code in many places

difficult to reason aboutnon-explicit structure

the big picture of the tangling isn’t clear

difficult to changehave to find all the code involved

and be sure to change it consistently

Page 7: AJDT: Getting started with Aspect-Oriented Programming in Eclipse · 2017-12-06 · 9 AJDT: Getting started with Aspect-Oriented Programming in Eclipse © 2005 by IBM and UBC; made

7AJDT: Getting started with Aspect-Oriented Programming in Eclipse © 2005 by IBM and UBC; made available under the EPL v1.0

the aop idea

crosscutting is inherent in complex systems

crosscutting concernshave a clear purpose

have a natural structure

so, let’s capture the structure of crosscutting concerns explicitly...in a modular way

with linguistic and tool support

aspects arewell-modularized crosscutting concerns

Page 8: AJDT: Getting started with Aspect-Oriented Programming in Eclipse · 2017-12-06 · 9 AJDT: Getting started with Aspect-Oriented Programming in Eclipse © 2005 by IBM and UBC; made

8AJDT: Getting started with Aspect-Oriented Programming in Eclipse © 2005 by IBM and UBC; made available under the EPL v1.0

How does it work?

AOP conceptsjoin points

pointcuts

advice

inter-type declarations

aspects

Page 9: AJDT: Getting started with Aspect-Oriented Programming in Eclipse · 2017-12-06 · 9 AJDT: Getting started with Aspect-Oriented Programming in Eclipse © 2005 by IBM and UBC; made

9AJDT: Getting started with Aspect-Oriented Programming in Eclipse © 2005 by IBM and UBC; made available under the EPL v1.0

Join Points

Points (events) in the execution of a programE.g. Call to a method, set of a field, initialization of an instance

Every program has hundreds/thousands of theseIncluding all your existing Java programs!

Not all events are of equal interest…calling a method

vs. the execution of the 27th byte code instruction

Page 10: AJDT: Getting started with Aspect-Oriented Programming in Eclipse · 2017-12-06 · 9 AJDT: Getting started with Aspect-Oriented Programming in Eclipse © 2005 by IBM and UBC; made

10AJDT: Getting started with Aspect-Oriented Programming in Eclipse © 2005 by IBM and UBC; made available under the EPL v1.0

Types of Join Points

Method & Constructor call

Method & Constructor executionadvice execution

Field get & set

Exception handler execution

Static & dynamic initialization

Page 11: AJDT: Getting started with Aspect-Oriented Programming in Eclipse · 2017-12-06 · 9 AJDT: Getting started with Aspect-Oriented Programming in Eclipse © 2005 by IBM and UBC; made

11AJDT: Getting started with Aspect-Oriented Programming in Eclipse © 2005 by IBM and UBC; made available under the EPL v1.0

PointcutsUsed to match join point events that occur during the program execution

Choose a subset of all the join points that occur during execution

pointcut move() :

call(void Line.setP1(Point)) ||

call(void Line.setP2(Point));

name and parameters

call of a method

composition

Page 12: AJDT: Getting started with Aspect-Oriented Programming in Eclipse · 2017-12-06 · 9 AJDT: Getting started with Aspect-Oriented Programming in Eclipse © 2005 by IBM and UBC; made

12AJDT: Getting started with Aspect-Oriented Programming in Eclipse © 2005 by IBM and UBC; made available under the EPL v1.0

Pointcuts

You can select join points based on…

the kind of join pointcall, execution, get, set, …

the static contextwithin, withincode

the runtime contextthis, target, args, cflow, cflowbelow

Page 13: AJDT: Getting started with Aspect-Oriented Programming in Eclipse · 2017-12-06 · 9 AJDT: Getting started with Aspect-Oriented Programming in Eclipse © 2005 by IBM and UBC; made

13AJDT: Getting started with Aspect-Oriented Programming in Eclipse © 2005 by IBM and UBC; made available under the EPL v1.0

Pointcuts

Can provide contextual information about join points they match

pointcut accountChange(BankAccount acc) :

set(!transient * *) &&

target(acc);

formal parameter

wildcards

parameterbinding

Page 14: AJDT: Getting started with Aspect-Oriented Programming in Eclipse · 2017-12-06 · 9 AJDT: Getting started with Aspect-Oriented Programming in Eclipse © 2005 by IBM and UBC; made

14AJDT: Getting started with Aspect-Oriented Programming in Eclipse © 2005 by IBM and UBC; made available under the EPL v1.0

Advice

Action to take at matched join points

parameter binding

after(BankAccount acc) returning : accountChange(acc) {

view.updateAccountDetails(acc);

}executes at every join point matched by “accountChange”

Page 15: AJDT: Getting started with Aspect-Oriented Programming in Eclipse · 2017-12-06 · 9 AJDT: Getting started with Aspect-Oriented Programming in Eclipse © 2005 by IBM and UBC; made

15AJDT: Getting started with Aspect-Oriented Programming in Eclipse © 2005 by IBM and UBC; made available under the EPL v1.0

Types of Advice

before()Before the selected join point matched

after() returningAfter successfully returning from the selected join point

after() throwingAfter returning with an exception from the selected join point

after() finallyAfter returning normally or with an exception from the selected join point

around()Both before and after, optionally executing the selected join point

Page 16: AJDT: Getting started with Aspect-Oriented Programming in Eclipse · 2017-12-06 · 9 AJDT: Getting started with Aspect-Oriented Programming in Eclipse © 2005 by IBM and UBC; made

16AJDT: Getting started with Aspect-Oriented Programming in Eclipse © 2005 by IBM and UBC; made available under the EPL v1.0

Aspects

The “unit of modularity” for cross-cutting concerns

huh?

Page 17: AJDT: Getting started with Aspect-Oriented Programming in Eclipse · 2017-12-06 · 9 AJDT: Getting started with Aspect-Oriented Programming in Eclipse © 2005 by IBM and UBC; made

17AJDT: Getting started with Aspect-Oriented Programming in Eclipse © 2005 by IBM and UBC; made available under the EPL v1.0

An Aspect

public aspect AccountWatcher {

private View view;

public void setView(View v) { this.view = v;}

pointcut accountChange(BankAccount acc) :

set(!transient * *) && target(acc);

after(BankAccount acc) returning : accountChange(p) {

view.updateAccount(p);

}

}

unit of modularity

state

behaviour

there are no explicit calls to

this advice in the system

Page 18: AJDT: Getting started with Aspect-Oriented Programming in Eclipse · 2017-12-06 · 9 AJDT: Getting started with Aspect-Oriented Programming in Eclipse © 2005 by IBM and UBC; made

18AJDT: Getting started with Aspect-Oriented Programming in Eclipse © 2005 by IBM and UBC; made available under the EPL v1.0

Enough!

Time for a demoa day in the life of an AspectJ programmer…

Eclipse is #1 for AOP

AspectJ Development Tools (AJDT) for EclipseIntegrate the AspectJ compiler into the Eclipse environment

Open Source

Developed in Hursley

Partnership with AspectJ team

Page 19: AJDT: Getting started with Aspect-Oriented Programming in Eclipse · 2017-12-06 · 9 AJDT: Getting started with Aspect-Oriented Programming in Eclipse © 2005 by IBM and UBC; made

19AJDT: Getting started with Aspect-Oriented Programming in Eclipse © 2005 by IBM and UBC; made available under the EPL v1.0

AJDT Demo – A simple project

Page 20: AJDT: Getting started with Aspect-Oriented Programming in Eclipse · 2017-12-06 · 9 AJDT: Getting started with Aspect-Oriented Programming in Eclipse © 2005 by IBM and UBC; made

20AJDT: Getting started with Aspect-Oriented Programming in Eclipse © 2005 by IBM and UBC; made available under the EPL v1.0

Web Services Invocation Framework (WSIF)

Middleware componentSimple Java API for invoking web services, no matter how or where they are provided

Released to ApacheBut IBM wants a version tightly coupled to IBM’s normal ‘qualities of service’

IBM tracing/monitoring/management

How do we manage this?

Page 21: AJDT: Getting started with Aspect-Oriented Programming in Eclipse · 2017-12-06 · 9 AJDT: Getting started with Aspect-Oriented Programming in Eclipse © 2005 by IBM and UBC; made

21AJDT: Getting started with Aspect-Oriented Programming in Eclipse © 2005 by IBM and UBC; made available under the EPL v1.0

AJDT Demo - WSIF

Page 22: AJDT: Getting started with Aspect-Oriented Programming in Eclipse · 2017-12-06 · 9 AJDT: Getting started with Aspect-Oriented Programming in Eclipse © 2005 by IBM and UBC; made

22AJDT: Getting started with Aspect-Oriented Programming in Eclipse © 2005 by IBM and UBC; made available under the EPL v1.0

Exploring Re-Use: The WSIF Story

WSIF for Open Source Communityorg.apache.wsif

+WebSphere RAS

CompositionWebSphere FFDC WSIF for

WebSphere

WebSphere PMI

Page 23: AJDT: Getting started with Aspect-Oriented Programming in Eclipse · 2017-12-06 · 9 AJDT: Getting started with Aspect-Oriented Programming in Eclipse © 2005 by IBM and UBC; made

23AJDT: Getting started with Aspect-Oriented Programming in Eclipse © 2005 by IBM and UBC; made available under the EPL v1.0

Demo conclusions

Capabilities of AOSD technology look promisingCode size reduction

No tangling

Faster development times

Product-line engineering

Page 24: AJDT: Getting started with Aspect-Oriented Programming in Eclipse · 2017-12-06 · 9 AJDT: Getting started with Aspect-Oriented Programming in Eclipse © 2005 by IBM and UBC; made

24AJDT: Getting started with Aspect-Oriented Programming in Eclipse © 2005 by IBM and UBC; made available under the EPL v1.0

Eliminating tanglingBEFORE

try {if (!removed)

entityBean.ejbPassivate();setState( POOLED );

} catch (RemoteException ex ) {destroy();throw ex;

} finally {removed = false; beanPool.put( this );

}

Crosscutting concernsextracted

try {if (!removed)

entityBean.ejbPassivate();setState( POOLED );

} catch (RemoteException ex ) {FFDCEngine.processException(ex,”EBean.passivate()”,”237”,this);

destroy();throw ex;

} finally {if (!removed &&

statisticsCollector != null) {statisticsCollector.

recordPassivation();}removed = false; beanPool.put( this );if (Logger.isEnabled) {

Logger.exit(tc,”passivate”);}

}

AFTER

Example: Code to handle EJB Entity bean passivation

Page 25: AJDT: Getting started with Aspect-Oriented Programming in Eclipse · 2017-12-06 · 9 AJDT: Getting started with Aspect-Oriented Programming in Eclipse © 2005 by IBM and UBC; made

25AJDT: Getting started with Aspect-Oriented Programming in Eclipse © 2005 by IBM and UBC; made available under the EPL v1.0

Applications of AOP

Problem determinationLogging, FFDC, performance monitoring

Architectural rule enforcementContracts, encapsulation, separation (no “up calls”)

Other concernsSecurity, transactions, persistence, caching/pooling, locking

Open source integration

Page 26: AJDT: Getting started with Aspect-Oriented Programming in Eclipse · 2017-12-06 · 9 AJDT: Getting started with Aspect-Oriented Programming in Eclipse © 2005 by IBM and UBC; made

26AJDT: Getting started with Aspect-Oriented Programming in Eclipse © 2005 by IBM and UBC; made available under the EPL v1.0

Adopting AOPreward

time & confidence

auxiliary /infrastructure

core /business

AO Analysis,AO Design,AO Strategy

explorationenforcement

Page 27: AJDT: Getting started with Aspect-Oriented Programming in Eclipse · 2017-12-06 · 9 AJDT: Getting started with Aspect-Oriented Programming in Eclipse © 2005 by IBM and UBC; made

27AJDT: Getting started with Aspect-Oriented Programming in Eclipse © 2005 by IBM and UBC; made available under the EPL v1.0

Simple but powerful enforcement aspect

Warn developers using System.out, System.err and printStackTrace

Try this when you get home!

public aspect EnforceLogging {

pointcut scope(): within(com.example..*);

pointcut printing(): get(* System.out) || get(* System.err) || call(* Throwable+.printStackTrace());

declare warning: scope() && printing():"don't print, use the logger";

}

Page 28: AJDT: Getting started with Aspect-Oriented Programming in Eclipse · 2017-12-06 · 9 AJDT: Getting started with Aspect-Oriented Programming in Eclipse © 2005 by IBM and UBC; made

28AJDT: Getting started with Aspect-Oriented Programming in Eclipse © 2005 by IBM and UBC; made available under the EPL v1.0

AJDT status: Stable release stream

1.1.12 released August 2004Changes since 1.1.4 include:

Per-project and global compiler settings

Related location context menu entries

Gutter annotations for in-jar aspects and ITDs

New cheat sheet and welcome pages

New dynamic build configurations

New advice icons including indication of runtime test

Property pages for InPath and AspectPath settings

Standalone extensible Visualiser

Ajdoc wizard

Export AspectJ plugins wizard

Breakpoints in aspects

Page 29: AJDT: Getting started with Aspect-Oriented Programming in Eclipse · 2017-12-06 · 9 AJDT: Getting started with Aspect-Oriented Programming in Eclipse © 2005 by IBM and UBC; made

29AJDT: Getting started with Aspect-Oriented Programming in Eclipse © 2005 by IBM and UBC; made available under the EPL v1.0

AJDT status: Development release stream

Milestone builds of 1.2.0Nearly there - changes so far include:

AspectJEditor improvements: code completion, organize imports, add import, code formatting, and foldingEagerly parsed structure of aspects shown in package explorer and outline viewVisualiser changes: rendering is faster and uses less memory, new look, extensible drawing styles and palettes, new drawing preferences page, new selection and keyboard traversal mechanisms, improved scaling modes, support for showing AspectJ errors and warnings, and new provider for Eclipse resourcesNew wizard for exporting AspectJ projects to JAR filesNew launch configurations with support for AspectPath and main methods in aspects

cont’d…

Page 30: AJDT: Getting started with Aspect-Oriented Programming in Eclipse · 2017-12-06 · 9 AJDT: Getting started with Aspect-Oriented Programming in Eclipse © 2005 by IBM and UBC; made

30AJDT: Getting started with Aspect-Oriented Programming in Eclipse © 2005 by IBM and UBC; made available under the EPL v1.0

AJDT status: Development release stream

Changes in 1.2.0 continued:Now built with AspectJ / AJDT

New cross reference view to show crosscutting relationships

Image decorator to show advised elements

In-place outline view in AspectJ editor

Incremental compilation now the default

New “advises” markers, to allow two-way navigation via markers

Visible project settings file to enable shared configurations

Includes AspectJ 5 builds

Page 31: AJDT: Getting started with Aspect-Oriented Programming in Eclipse · 2017-12-06 · 9 AJDT: Getting started with Aspect-Oriented Programming in Eclipse © 2005 by IBM and UBC; made

31AJDT: Getting started with Aspect-Oriented Programming in Eclipse © 2005 by IBM and UBC; made available under the EPL v1.0

AJDT Future plans

Deliver AJDT 1.2.0 final for Eclipse 3.0 and 3.1:Closer integration with JDT/Eclipse

A robust, stable development environment

AJDT 1.2.1 and beyond:Aspect-aware and aspect-specific refactorings

AspectJ-specific quick fixes

Support for aspect libraries

More views and support for working with the crosscutting nature of your applications

Page 32: AJDT: Getting started with Aspect-Oriented Programming in Eclipse · 2017-12-06 · 9 AJDT: Getting started with Aspect-Oriented Programming in Eclipse © 2005 by IBM and UBC; made

32AJDT: Getting started with Aspect-Oriented Programming in Eclipse © 2005 by IBM and UBC; made available under the EPL v1.0

Current AspectJ Status

v1.2.1 currently released versionSee the readme’s for 1.2 and 1.2.1 linked from our websiteLast release before we tackled Tiger…

Currently working on AspectJ5Targeted for March release

AspectJ5 Features:Includes JDT compiler that supports Java 5

annotations/generics/autoboxing/varargs/enums/etc..Pointcut syntax now aware of Java 5 language features

Write pointcuts that match based on annotationsAfter joining with the AspectWerkz team AspectJ5 will now support an alternative annotation style syntax for aspect developmentImproved Load Time Weaving support

Page 33: AJDT: Getting started with Aspect-Oriented Programming in Eclipse · 2017-12-06 · 9 AJDT: Getting started with Aspect-Oriented Programming in Eclipse © 2005 by IBM and UBC; made

33AJDT: Getting started with Aspect-Oriented Programming in Eclipse © 2005 by IBM and UBC; made available under the EPL v1.0

What Next?AspectJ home page: http://www.eclipse.org/aspectj

AJDT home page: http://www.eclipse.org/ajdt

Pick up a book …

Attend a conference (see http://aosd.net) Or email us:Matt [email protected]

Andy [email protected]

Mik [email protected]

Chicago, USAMarch 14-18, 2005