Semantics-based Crosscutting for Message Invocations in AspectJ - PowerPoint PPT Presentation

Semantics based crosscutting for message invocations in aspectj
Download
1 / 20

  • 69 Views
  • Uploaded on
  • Presentation posted in: General

Semantics-based Crosscutting for Message Invocations in AspectJ. Karl Lieberherr. Crosscuts. Crosscuts are defined in terms of key events in the execution of Java programs. We focus on message invocations.

I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.

Download Presentation

Semantics-based Crosscutting for Message Invocations in AspectJ

An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Presentation Transcript


Semantics based crosscutting for message invocations in aspectj

Semantics-based Crosscutting for Message Invocations in AspectJ

Karl Lieberherr


Crosscuts

Crosscuts

  • Crosscuts are defined in terms of key events in the execution of Java programs.

  • We focus on message invocations.

  • A message is used to refer to the combination of a method name, its result type and the types of its parameters.


A simple aspect

A simple aspect

crosscut gets():

(Point & (int getX() |

int getY() | new()))

|

(Line & (Point getP1() |

Point getP2() | new()))

static advice(): gets() {

after { log.write(“A point or line

was accessed or constructed”);

}

}


Constraints

Constraints

  • There are classes Point and Line.

  • Point has getX() and getY() and a constructor without parameters

  • Line has getP1() and getP2() and a constructor without parameters


Example 3 count collaboration

Example 3: Count Collaboration

  • collaboration Counting {

    • participantSource{

    • expectTraversalGraph getT();

    • // newTraversalGraph(classGraph,

    • // new Strategy(“from Source to Target”));

    • public int count (){ // traversal/visitor weaving

    • getT().traverse(this, new Visitor(){ int r;

    • public void before(Target host){ r++; }

    • public void start() { r = 0;} …) } }

  • // ClassGraph classGraph = new ClassGraph();


Example 3 count collaboration1

Example 3: Count Collaboration

  • participantTarget{}

  • }

  • Use in Bus simulation example:

    Source -- BusRoute

    Target -- Person


    Resulting java program

    Resulting Java Program

    • classBusRoute{

      • // newTraversalGraph(classGraph,

      • // new Strategy(“from BusRoute via BusStop to Person”));

      • public int count (TraversalGraph getT){

      • getT.traverse(this, new Visitor(){ int r;

      • public void before(Person host){ r++; }

      • public void start() { r = 0;} …) }

      • }

    • // ClassGraph classGraph = new ClassGraph();


    Exercise simulate traversal visitor style in aspectj

    Exercise: simulate traversal-visitor style in AspectJ

    • Write traversal methods tr1 manually.

    • For each visitor entry: write crosscut and advice:

      crosscut forTarget_tr1(Target h):

      h & void tr1();

      static advice(Target h):

      forTarget_tr1(h){

      after { … /* use h */ }}


    Exercise simulate collaborations adapters with aspectj

    Exercise: simulate collaborations/ adapters with AspectJ

    • Expand each adapter

    class Logging {

    crosscut gets():

    (Point & (int getX() |

    int getY() | new()))

    |

    (Line & (Point getP1() |

    Point getP2() | new()))

    static advice(): gets() {

    after { log.write(“A point or line

    was accessed or constructed”);

    }

    }

    }


    Corresponding collaboration

    Corresponding collaboration

    collaboration Logging {

    participant DataToLog {

    expect methodToLog();

    expect stringToPrint();

    replace methodToLog(){

    expected(s);

    log.write(stringToPrint();}}}


    Corresponding adapter

    Corresponding adapter

    adapter LoggingUse {

    Point is Logging.DataToLog

    with {

    methodToLog() = {int getX(), int getY(), new()}

    stringToPrint() {

    return(“Point accessed or constructed”);}}

    Line is Logging.DataToLog

    with {

    methodToLog() = {Point getP1(), Point getP2(), new()}

    stringToPrint() {

    return(“Line accessed or constructed”);}}}


    Using abstract crosscuts for reusability of aspects

    Using Abstract Crosscuts for Reusability of Aspects

    abstractpublicclass AbstractLogAndIgnore {

    abstractcrosscut methods();

    staticadvice methods() {

    catch {RemoteException e) {

    ErrorLog.print(“remote call failed in:”

    + thisMethodName + “:” + e);

    }

    }

    }


    Instantiate through subclassing

    Instantiate through Subclassing

    publicclass JWAMRemoteExceptionHandler

    extends AbstractLogAndIgnore{

    crosscut methods():

    RegistryServer & * *(..) |

    RMIMessageBrokerImpl &

    private * * (..);

    }


    Adapters versus abstract crosscuts

    Adapters versus Abstract Crosscuts

    • With crosscut refinement we can only specify the details of crosscuts.

    • With adapters we can do more: specify crosscut details and implement the expected methods.

    • But we can also introduce implementations of abstract methods through subclassing. Does not work: Method of aspect not participant.


    Collaborations adapters in aspectj

    Collaborations/adapters in AspectJ

    • Works if adapter is pure crosscut: E.g.:

      methodToLog() = {int getX(), int getY(), new()}


    From aspectj to collaborations adapters

    From AspectJ to collaborations/adapters

    • Static advices go into collaborations (replaced methods)

    • Crosscuts go into adapters

    • What do we do about crosscut signatures? We can have arguments in replaced methods.


    Mappings

    Mappings

    • One participant to several classes

      • AspectJ: mention classes in crosscut

      • CA: {X,Y,Z} is Collab.P or multiple X is ...

    • One method to several methods

      • AspectJ: enumerate them or use wildcards

      • CA: enumerate them or use wildcards


    Conclusions

    Conclusions

    • Collaborations and adapters can not be easily expressed in AspectJ.

    • Instantiated collaborations can be expressed in AspectJ.


    How does aspectj help in implementing collaborations adapters

    How does AspectJ help in implementing collaborations/adapters?

    • Implements wildcards

    • Implements advices (around), Implements replace

    • What if AspectJ work stops? Source code available?


    Semantics based crosscutting for message invocations in aspectj

    • Adaptive software consists of three parts:

      • succinct constraints C on customizers

      • initial behavior specications expressed in terms of C

      • behavior enhancements expressed in terms of C


  • Login