12
Aspects Made Explicit for Safe Transactional Semantics Kevin Hoffman / Patrick Eugster

Aspects Made Explicit for Safe Transactional Semantics [DSN 2006]

Embed Size (px)

DESCRIPTION

Implementing the transactions cross-cutting concern in AspectJ faces many challenges. We propose making join points an explicit part of the base code to overcome these challenges.

Citation preview

Page 1: Aspects Made Explicit for Safe Transactional Semantics [DSN 2006]

Aspects Made Explicit for

Safe Transactional Semantics

Kevin Hoffman / Patrick Eugster

Page 2: Aspects Made Explicit for Safe Transactional Semantics [DSN 2006]

-2-Kevin Hoffman and Patrick Eugster

Properties of Transactions

A tomicity – all or nothing

C onsistency – changes respect specifications

I solation – effects of concurrency masked

D urability – committed results never lost

Page 3: Aspects Made Explicit for Safe Transactional Semantics [DSN 2006]

-3-Kevin Hoffman and Patrick Eugster

Implementation Approaches

Library approach

- Safety

- Elegance

+Flexibility

+Interoperability

Language approach

+Safety

+Elegance

- Flexibility

- Interoperability

Page 4: Aspects Made Explicit for Safe Transactional Semantics [DSN 2006]

-4-Kevin Hoffman and Patrick Eugster

The Pursuit of Elegance

Cross-cutting concerns tangle/scatter code

Aspect Oriented Programming (AOP) / AspectJ

Exposes structural points (e.g. method call, member

accesses) of a program’s primary decomposition as

language features

Provides language features (aspects) to superimpose

logic (advice) systematically onto the mainline code

(via pointcuts)

AOP improves elegance but complicates safety

Page 5: Aspects Made Explicit for Safe Transactional Semantics [DSN 2006]

-5-Kevin Hoffman and Patrick Eugster

AOP/AspectJ in 60 seconds

void buy(…){

…}

void cancel(…){

…}

void return(…){

…}

Store class

…DB.buy(order);…

…DB.cancel(o);…

…DB.return(o);…

pointcut tranOp():call(* * Store.*(..));

around(): tranOp() { //adviceT = thisJoinP.getTarget();TransMan.beginTrans(T);try{

Object ret = proceed();TransMan.commit(T);return ret;

} catch (Exception e){TransMan.abort(T);throw e;

}}

JSP Pages Transactionalizer aspect

Page 6: Aspects Made Explicit for Safe Transactional Semantics [DSN 2006]

-6-Kevin Hoffman and Patrick Eugster

AOP/AspectJ Safety Issues

void buy(…){

…}

void cancel(…){

…}

void return(…){

…}

Store class

…DB.buy(order);…

…DB.cancel(o);…

…DB.return(o);…

JSP Pages Transactionalizer aspect

pointcut tranOp():call(* * Store.*(..));

around(): tranOp() { //adviceT = thisJoinP.getTarget();TransMan.beginTrans(T);try{

Object ret = proceed();TransMan.commit(T);return ret;

} catch (Exception e){TransMan.abort(T);throw e;

}}

Aspects can throw

unexpected

exceptions

due to new logic.

But there is no way

to constrain the

base code to catch

these exceptions…

Page 7: Aspects Made Explicit for Safe Transactional Semantics [DSN 2006]

-7-Kevin Hoffman and Patrick Eugster

void buy(…){TA.jpTrans() {

}}void cancel(…){

TA.jpTrans() {…

}}void return(…){

TA.jpTrans() {…

}}

Our Idea: Explicit Join PointsStore class

…DB.buy(order);…

…DB.cancel(o);…

…DB.return(o);…

scoped joinpoint jpTrans()throws TranException;

pointcut tranOp():joinpoint(jpTrans);

before (): tranOp() {T = thisJoinP.getTarget();TransMan.beginTrans(T);

}after () throwing: tranOp() {

TransMan.abort(T);}after () returning: tranOp() {

TransMan.commit(T);}

JSP PagesTransactionalizer aspect [TA]

Page 8: Aspects Made Explicit for Safe Transactional Semantics [DSN 2006]

-8-Kevin Hoffman and Patrick Eugster

EJP Larger Example [Aspect]aspect Transactionalizer {

scoped joinpoint jpTrans(Serializable[ ] objects)throws TransactionException; /* EJPs makes this constraint possible */

pointcut pcTrans(Serializable[ ] objects) :joinpoint(jpTrans) && args(objects);

before(Serializable[ ] objs): pcTrans(objs) {TransMan.begin(objs, ...);

}

after() throwing: pcTrans() { // if mainline code fails,

TransMan.abort(...); // abort transaction

}after() returning: pcTrans() { // after normal completion,

TransMan.commit(...); // commit transaction

}}

Page 9: Aspects Made Explicit for Safe Transactional Semantics [DSN 2006]

-9-Kevin Hoffman and Patrick Eugster

EJP Larger Example [Mainline]/* EJPs explicitly require object to be Serializable to be Transactionalized */

class Agent implements Serializable {

void createTrip(Person p, Flight f, Hotel h, RentalCar c){

boolean bCharged = false;

try {

/* EJPs provide bilateral communication with aspects */

Serializable [ ] objects = {this, p, f, h, c};

joinpoint Transactionalizer.jpTrans(objects) {

/* Scope of transaction specified by scope of EJP */

f.ReserveSeat(p); h.ReserveRoom(p);

c.ReserveVehicle(c); m_CC.Debit(p.getCC(), …);

bCharged=true;

}

} catch (TransactionException e) { /* Required by EJP */

if (bCharged){ m_CC.Credit(p.getCC(), …); }

}

}

Page 10: Aspects Made Explicit for Safe Transactional Semantics [DSN 2006]

-10-Kevin Hoffman and Patrick Eugster

Why is an EJP not a method call?

Multiple aspects may advise the EJP

Scoped EJPs provide new code structure

which can be advised, increasing safety

Aspect instance can depend on context of

joinpoint (via pertarget, percflow, …)

Pointcuts may be passed as parameters,

utilizing the full power of AOP features

Page 11: Aspects Made Explicit for Safe Transactional Semantics [DSN 2006]

-11-Kevin Hoffman and Patrick Eugster

How EJP Measures Up

+ Safety: EJP constraints enforced at

compile time

+ Elegance: EJP increases AspectJ power

(bilaterial communication, constraints)

+ Flexibility: Change implementation easily

+ Interoperability: Superset of AspectJ;

works with any other Java program

Page 12: Aspects Made Explicit for Safe Transactional Semantics [DSN 2006]

-12-Kevin Hoffman and Patrick Eugster

The End of the Beginning

[email protected]

[email protected]