Presentation is loading. Please wait.

Presentation is loading. Please wait.

Stateful Aspects in JAsCo

Similar presentations


Presentation on theme: "Stateful Aspects in JAsCo"— Presentation transcript:

1 Stateful Aspects in JAsCo
Wim Vanderperren | pag. 1

2 Natural Evolution of joinpoints:
Stateful Aspects Natural Evolution of joinpoints: Static Dynamic (e.g. cflow) Stateful Stateful Aspects in JAsCo | pag. 2

3 Timing Aspect 1 class DynamicTimer {
3 private Vector<TimeListener> listeners = new Vector<TimeListener>(); 4 private long timestampbefore, timestampafter; 6 void addTimeListener(TimeListener aListener) { listeners.add(aListener); 8 } 9 void removeTimeListener(TimeListener aListener) { listeners.remove(aListener); 11 } 12 void notifyTimeListeners(Method method, long time) { for (TimeListener listener : listeners) { listener.timeStampTaken(method,time); } 16 } 18 hook TimeStamp { TimeStamp(timedmethod(..args)) { execution(timedmethod); } before { timestampbefore = System.currentTimeMillis(); } after { timestampafter = System.currentTimeMillis(); notifyListeners(thisJointPoint,timestampafter-timestampbefore); } 29 } 30 } Stateful Aspects in JAsCo | pag. 3

4 Timing one method: But how to time a protocol? E.g. time between execution of a-b-c on ComponentX. 1 connector TimeConnector { 2 DynamicTimer.TimeStamp timer = new DynamicTimer.TimeStamp (void ComponentX.a()); 4 timer.before(); 5 timer.after(); 6 } Stateful Aspects in JAsCo | pag. 4

5 Protocol Timing Aspect?
1 class ProtocolDynamicTimer extends DynamicTimer { 2 3 boolean methodaexecuted, methodbexecuted = false; 4 5 hook ProtocolMethodA { ProtocolMethodA(methodA(..args)) { execution(methodA); } before { timestampbefore = System.currentTimeMillis(); methodaexecuted = true; } isApplicable() { return !methodaexecuted; } 15 } 16 17 hook ProtocolMethodB { ProtocolMethodB(methodB(..args)) { execution(methodB); } before { methodbexecuted = true; } isApplicable() { return methodaexecuted; } 25 } 26 27 hook ProtocolMethodC { ProtocolMethodC(methodC(..args)) { execution (methodC); } after { timestampafter = System.currentTimeMillis(); notifyListeners(method,timestampafter-timestampbefore); methodaexecuted = false; methodbexecuted = false; } isApplicable() { return methodbexecuted; } 37 } 39 } connector TimeConnector { DynamicTimer.ProtocolMethodA timera = new DynamicTimer. ProtocolMethodA (void ComponentX.a()); DynamicTimer.ProtocolMethodB timerb = new DynamicTimer. ProtocolMethodB (void ComponentX.b()); DynamicTimer.ProtocolMethodC timerc = new DynamicTimer. ProtocolMethodC (void ComponentX.c()); } Stateful Aspects in JAsCo | pag. 5

6 Stateful Aspects: Motivation
Protocol based aspects are rarely supported in current AOSD approaches (apart cflow). Result: protocol checking code is scattered over advices, poluting advice code… Is also not optimal, checks at all possible joinpoints while only a subset is required. Stateful Aspects in JAsCo | pag. 6

7 Example: Realize a more general protocol history condition than cflow.
Stateful Aspects Allows specifying regular (=DFA based) hook triggering conditions in a hook’s constructor. Advices can be attached to any transition of the DFA, or all of them (global). Example: Realize a more general protocol history condition than cflow. Stateful Aspects in JAsCo | pag. 7

8 Timing Example Revisited
1 class ProtocolDynamicTimer extends DynamicTimer { 2 3 hook StatefulProtocolTimer { 4 long timestamp; 6 StatefulProtocolTimer(methodA(..args),methodB(..args),methodC(..args)) { ATrans: execution(methodA) > BTrans; BTrans: execution(methodB) > CTrans; CTrans: execution(methodC) > ATrans; } 12 before ATrans() { timestamp=System.currentTimeMillis(); } after CTrans() { long resultingtime = System.currentTimeMillis(); notifyListeners(calledmethod,resultingtime-timestamp); } 20 21 } 22 } Regular JAsCo Pointcuts for triggering the transition Transition Labels Stateful Pointcut Following Transitions to evaluate Attaching Advices to specific transitions Stateful Aspects in JAsCo | pag. 8

9 Timing Example Revisited
static connector TimingConnector { perthread ProtocolDynamicTimer.StatefulProtocolTimer timer = new ProtocolDynamicTimer.StatefulProtocolTimer( void ComponentX.a()., void ComponentX.b(), void ComponentX.c() ); } Stateful Aspects in JAsCo | pag. 9

10 Advanced Pointcut Features
Explicit start transitions start > XTrans; Starting with two transitions: start > XTrans || QTrans; two destination transitions: XTrans: execution(methodA) > YTrans || QTrans; no destination transition QTrans: execution(methodB) && !cflow(methodC); Stateful Aspects in JAsCo | pag. 10

11 Advices Multiple specific advices possible, one for each transition per before/around */after * Global advice works for all transitions isApplicable can also be global or specific isApplicable() { //global condition for all transitions // returns true if advices should be executed } isApplicable XTrans() { //local condition only relevant for the transition XTrans // returns true if advices should be executed for the XTrans transition advantages Stateful Aspects in JAsCo | pag. 11

12 Strict Protocols Per default, stateful aspects are non-strict, e.g. protocol a()-d()-b()-c() also matches timing aspect. When no intermediate transitions are allowed, use the strict keyword: strict: ATrans: execution(methodA) > BTrans; BTrans: execution(methodB) > CTrans; CTrans: execution(methodC) > ATrans; Stateful Aspects in JAsCo | pag. 12

13 Strict Protocols with Context
Only strict with respect to a certain set of joinpoints. E.g. timing aspect does not accept intermediate transitions on ComponentX, on other classes is ok though. StatefulProtocolTimer(methodA(..args),methodB(..args),methodC(..args), context(..args)) { strict[execution(context)]: ATrans: execution(methodA) > BTrans; BTrans: execution(methodB) > CTrans; CTrans: execution(methodC) > ATrans; } Rejects: ComponentX.a() ComponentX.d() ComponentX.b() ComponentX.c() static connector TimingConnector { …. new ProtocolDynamicTimer.StatefulProtocolTimer( void ComponentX.a()., void ComponentX.b(), void ComponentX.c(), void ComponentX.*(*) ); } Accepts: ComponentX.a() Y.d() ComponentX.b() ComponentX.c() Stateful Aspects in JAsCo | pag. 13

14 Complement of a protocol
Trigger advices on everything outside the protocol: COMPLEMENT StatefulProtocolTimer(methodA(..args),methodB(..args),methodC(..args)) { complement: ATrans: execution(methodA) > BTrans; BTrans: execution(methodB) > CTrans; CTrans: execution(methodC) > ATrans; } around complement() { throw new SecurityException(“this is not allowed on “+thisJoinPoint.getClass()); Stateful Aspects in JAsCo | pag. 14

15 Complement with Context
Only complement with respect to a certain set of joinpoints. StatefulProtocolTimer(methodA(..args),methodB(..args),methodC(..args), context(..args)) { complement[execution(context)]: ATrans: execution(methodA) > BTrans; BTrans: execution(methodB) > CTrans; CTrans: execution(methodC) > ATrans; } d() in complement: ComponentX.a() ComponentX.d() ComponentX.b() ComponentX.c() static connector TimingConnector { …. new ProtocolDynamicTimer.StatefulProtocolTimer( void ComponentX.a()., void ComponentX.b(), void ComponentX.c(), void ComponentX.*(*) ); } No complement: ComponentX.a() Y.d() ComponentX.b() ComponentX.c() Stateful Aspects in JAsCo | pag. 15

16 Default: weaved at all possible joinpoints defined in the pointcut.
Weaving A DFA (Deterministic Finite Automaton) executes the stateful aspect at run-time. Default: weaved at all possible joinpoints defined in the pointcut. Optionally, jumping aspect in cooperation with run-time weaver: only weaved at next joinpoints in protocol overhead of reweaving vs overhead of aspect applied at all Stateful Aspects in JAsCo | pag. 16


Download ppt "Stateful Aspects in JAsCo"

Similar presentations


Ads by Google