32
AOSD'04, Lancaster, UK 1 Remote Pointcut - A Language Construct for Distri buted AOP Muga Nishizawa (Tokyo Tech, Japa n) Shigeru Chiba (Tokyo Tech, Japa n) Michiaki Tatsubori (TRL, Japan I BM)

Remote Pointcut - A Language Construct for Distributed AOP

  • Upload
    liang

  • View
    30

  • Download
    0

Embed Size (px)

DESCRIPTION

Remote Pointcut - A Language Construct for Distributed AOP. Muga Nishizawa (Tokyo Tech, Japan) Shigeru Chiba (Tokyo Tech, Japan) Michiaki Tatsubori (TRL, Japan IBM). This Talk. Our goal To modularize crosscutting concerns in distributed software Motivating problem - PowerPoint PPT Presentation

Citation preview

Page 1: Remote Pointcut - A Language Construct for Distributed AOP

AOSD'04, Lancaster, UK 1

Remote Pointcut- A Language Construct for Distributed AOP

Muga Nishizawa (Tokyo Tech, Japan)Shigeru Chiba (Tokyo Tech, Japan)

Michiaki Tatsubori (TRL, Japan IBM)

Page 2: Remote Pointcut - A Language Construct for Distributed AOP

AOSD'04, Lancaster, UK 2

This Talk Our goal

To modularize crosscutting concerns in distributed software

Motivating problem AspectJ can separate them But, the implementation is NOT simple E.g. a test code for distributed software

Our solution Remote pointcut

Page 3: Remote Pointcut - A Language Construct for Distributed AOP

AOSD'04, Lancaster, UK 3

Test Code for Distributed Authentication Service

Confirm addUser() is executed on Database when client remotely calls registerUser() Client calls registerUser(),

registerUser() calls addUser()

Authenticator

Database

registerUser()

Client

addUser()

Register a new user on a DB

Page 4: Remote Pointcut - A Language Construct for Distributed AOP

AOSD'04, Lancaster, UK 4

Ideal Design for Test Code

On Client, 1. flag = false. 2. call registerUser() on Authenticator. 3. if addUser() is executed on Database,

then flag = true. 4. assert flag == true.

Authenticator

Database

registerUser()

addUser()

Client

Page 5: Remote Pointcut - A Language Construct for Distributed AOP

AOSD'04, Lancaster, UK 5

Test Code in Java Crosscutting concern

Database code must be edited for test

1. Flag = false2. Call registerUser()

3. assert flag == true

class Database { void addUser() { invoke Callback … … add the user to the database } … …}

Client

Flag = true

Callback

Database

Authenticator

RMI (Remote Method Invocation)

Crosscutting concern

Page 6: Remote Pointcut - A Language Construct for Distributed AOP

AOSD'04, Lancaster, UK 6

Test Code in Java and AspectJ

The concern is separated Database code is not edited

1. Flag = false2. Call registerUser()

3. Assert flag == true

Client

Flag = true

Callback

class Database { void addUser() {

… … add the user to the database }}

Database

aspect DatabaseTest { before(): execution(void addUser()){ invoke Callback }}

DatabaseTest

RMI

Page 7: Remote Pointcut - A Language Construct for Distributed AOP

AOSD'04, Lancaster, UK 7

This Design is Not Satisfactory When writing the test code, we must consider two

concerns: Test Distribution

It requires to divide the code into three sub-modules Network processing (RMI) and deployment

1. flag = false.2. call registerUser() on Authenticator.

3. if addUser() is invoked on Database,

flag = true.

4. Assert flag == ture

Three distributed sub-modules

Don’t consider this!

Page 8: Remote Pointcut - A Language Construct for Distributed AOP

AOSD'04, Lancaster, UK 8

Our Solution - Remote Pointcut

To identify join points in a program on a remote host To run advice on a different host from the host w

here join points are pointcut Like RMI for distributed OOP

class Database { void addUser() { … … }}

Remote pointcut

aspect Log { before() : execution(void addUser()) { System.out.println(“addUser”); }}

Identified join point

Page 9: Remote Pointcut - A Language Construct for Distributed AOP

AOSD'04, Lancaster, UK 9

Test Code using a Remote Pointcut Test program is a single non-distributed module

Authenticator

1. flag = false2. call registerUser()

3. assert flag == true

before(): cflow(call(void registerUser()))&&execution(void addUser()){ flag = true}

call addUser()

Remote Pointcut

class Database { void addUser() {

} … …}

Database

AuthenticatorTest(Aspect)

call registerUser()

Page 10: Remote Pointcut - A Language Construct for Distributed AOP

AOSD'04, Lancaster, UK 10

Test Code Implementationaspect AuthenticatorTest extends TestCase { boolean flag;

void testRegisterUser() { flag = false; String userId = "muga", password = "xxx"; Authenticator auth = (Authenticator) Naming.lookup("auth"); auth.registerUser(userId, password); assertTrue(flag); }

before(): // remote pointcut cflow(call(void Authenticator.registerUser())) && execution(void Database.addUser()) { flag = true; }}

When addUser() is executed, the flag is set to true

Confirms the flag is true

Calls registerUser()

Declares and initializes the flag

Page 11: Remote Pointcut - A Language Construct for Distributed AOP

AOSD'04, Lancaster, UK 11

DJcutter - Distributed AOP Language

It’s an extension of AspectJ language Remote pointcut Remote inter-type declaration

Load-time weaving Aspect weaving in DJcutter is performed at loa

d-time

Page 12: Remote Pointcut - A Language Construct for Distributed AOP

AOSD'04, Lancaster, UK 12

DJcutter Language Specification Pointcut

DJcutter provides pointcut designators in AspectJ Call, execution, within, target, …

Hosts(Host, …) The join points in execution on the hosts

Cflow(Pointcut) All join points that occur between the entry and exit of

each join point specified by Pointcut

Advice Before, after, and around

Page 13: Remote Pointcut - A Language Construct for Distributed AOP

AOSD'04, Lancaster, UK 13

Remote Inter-type Declaration To declare methods and fields in classes

on a remote host

Database

aspect AuthenticatorTest { boolean Database.containsUser(String userId) { // If the user entry specified by userId is found // in the database. }}

boolean containsUser();

Append at load-timeAuthenticatorTest

Page 14: Remote Pointcut - A Language Construct for Distributed AOP

AOSD'04, Lancaster, UK 14

Use of Remote Inter-type Declaration

aspect AuthenticatorTest extends TestCase {

void testRegisterUser() { String userId = "muga", password = "xxx"; Authenticator auth = (Authenticator) Naming.lookup("auth"); Database db = (Database) Naming.lookup(“db”); assertTrue(! db.containsUser(userId)); auth.registerUser(userId, password); assertTrue(db.containsUser(userId)); }

boolean Database.containsUser(String userId) { // If the user entry specified by userId is // found in the database. }}

Confirms that the user entry

Page 15: Remote Pointcut - A Language Construct for Distributed AOP

AOSD'04, Lancaster, UK 15

DJcutter Implementation - Load-time Weaving

Aspect source file

Java bytecode

Compiler

Aspect ServerClass Loader

Class Loader

entry

Distributed software

Distributed software

weave

weave

deploy

deploy

Runtime InfrastructureRuntime Infrastructure

Runtime Infrastructure

Page 16: Remote Pointcut - A Language Construct for Distributed AOP

AOSD'04, Lancaster, UK 16

Related Work 1

Middleware for automatic distribution E.g. J-Orchestra and Addistant They completely hide distribution concern Conbination of AspectJ and them

We are not sure they are good for Tomcat, Oracle, …

Page 17: Remote Pointcut - A Language Construct for Distributed AOP

AOSD'04, Lancaster, UK 17

Related Work 2 Other distributed AOP languages

E.g. D language framework JAC (Java Aspect Componenets)

DADO To modularize functional crosscutting concerns

DJcutter Remote pointcut To modularize non-functional crosscutting con

cerns

Page 18: Remote Pointcut - A Language Construct for Distributed AOP

AOSD'04, Lancaster, UK 18

Conclusion Remote pointcut

To transparently identify join points on remote hosts Like RMI for distributed OOP

To run advice on a different host from the host where join points are pointcut Without consideration of distribution concern

DJcutter – Distributed AOP Language Remote pointcut Extension of AspectJ language

Page 19: Remote Pointcut - A Language Construct for Distributed AOP

AOSD'04, Lancaster, UK 19

The End

Thanks

Page 20: Remote Pointcut - A Language Construct for Distributed AOP

AOSD'04, Lancaster, UK 20

Page 21: Remote Pointcut - A Language Construct for Distributed AOP

AOSD'04, Lancaster, UK 21

Page 22: Remote Pointcut - A Language Construct for Distributed AOP

AOSD'04, Lancaster, UK 22

Even if writing RMI is very easy,

We still have a question: Why the test code consists of three sub-modules? Because of not test but distribution concern

1. flag = false.2. call registerUser() on Authenticator.

3. if addUser() is invoked on Database,

flag = true.

4. Assert flag == ture

Design Problem

Page 23: Remote Pointcut - A Language Construct for Distributed AOP

AOSD'04, Lancaster, UK 23

DJcutter Implementation

Compiler To generate a Java-bytecode representing an

aspect Runtime infrastructure

To implement load-time weaving Aspect server Extended class loader

Page 24: Remote Pointcut - A Language Construct for Distributed AOP

AOSD'04, Lancaster, UK 24

Page 25: Remote Pointcut - A Language Construct for Distributed AOP

AOSD'04, Lancaster, UK 25

Our Solution

To run advice on a different host from the host where join points are pointcut

Implementing a single module without consideration of distribution

That is, it can separate distribution concern from the test code Non-distributed sub-modules, Automatic deployment, And separation of crosscutting concerns

Page 26: Remote Pointcut - A Language Construct for Distributed AOP

AOSD'04, Lancaster, UK 26

Remote Pointcut

To identify join points in a program flow on remote host transparently Corresponding to RMI for distributed OOP Extends to pointcut designators in AspectJ

A single non-distributed module on a single host

class Database { void addUser() { System.out.println(“addUser”); … … }}

Database

Remote pointcut

aspect Log { before() : execution(void addUser()) { System.out.println(“addUser”); }}

Log

Page 27: Remote Pointcut - A Language Construct for Distributed AOP

AOSD'04, Lancaster, UK 27

Three Distributed Sub-modules Ideally, a concern should be described a non-distributed single module We want to write without consideration of distribution

The test code is written with consideration of distribution As a result, sub-modules, complicated network

processing, deployment

1. flag = false.2. call registerUser() on Authenticator.

3. if addUser() is invoked on Database,

flag = true.

4. Assert flag == ture

Page 28: Remote Pointcut - A Language Construct for Distributed AOP

AOSD'04, Lancaster, UK 28

Three Distributed Sub-modules Idealy, a concern should be described as a non-dist

ributed single module on a single host この test code は、分散した sub-modules に

なっている Separated, but far from the ideal test code Remote method invocation among sub-modules Deployment

Client

Callback

DatabaseTest

RMI

DatabaseTest

ClientCallback

DatabaseTest

Page 29: Remote Pointcut - A Language Construct for Distributed AOP

AOSD'04, Lancaster, UK 29

Related Work

Page 30: Remote Pointcut - A Language Construct for Distributed AOP

AOSD'04, Lancaster, UK 30

Ideal Test Code In the test code, we declare a flag for comfirming t

hat addUser() was executed

AuthenticatorTest Program call registerUser()

1. Sets flag to false2. Remotely calls registerUser()

3. Confirms that flag is ture

Flag is set to true, when addUser() is executed

Main part for testingcall addUser()

class DbServer { void addUser() { … … }}

Database

Page 31: Remote Pointcut - A Language Construct for Distributed AOP

AOSD'04, Lancaster, UK 31

実際に実装するAuthServer

DbServer

AuthServerTest 1.registerUser() 呼出

2.addUser() 呼出

class AuthServerTest extends TestCase {

boolean wasAddUserCalled; void testRegisterUser() { Naming.rebind("test", new RecieverImpl()); wasAddUserCalled = false; String userId = "muga", password = "xxx"; AuthServer auth = (AuthServer) Naming.lookup("auth"); auth.registerUser(userId, password); assertTrue(wasAddUserCalled); }class ReceiverImpl extends UnicastRemoteObject implements NotificationReceiver {

void confirmCall() { wasAddUserCalled = true; } }interface NotificationReceiver { void confirmCall(); }

interface NotificationReceiver { void confirmCall(); }

aspect Notification { before(): execution(void DbServer.addUser()){ NotificationReceiver test = (NotificationReceiver) Naming.lookup("test"); test.confirmCall(); }}

RMI

Page 32: Remote Pointcut - A Language Construct for Distributed AOP

AOSD'04, Lancaster, UK 32

Experimental Results