Presentation is loading. Please wait.

Presentation is loading. Please wait.

Monitoring Design Pattern Contracts Jason O. Hallstrom Clemson University SAVCBS 04 Workshop at ACM SIGSOFT 2004/FSE-12 Benjamin Tyler (Presenter) Ohio.

Similar presentations


Presentation on theme: "Monitoring Design Pattern Contracts Jason O. Hallstrom Clemson University SAVCBS 04 Workshop at ACM SIGSOFT 2004/FSE-12 Benjamin Tyler (Presenter) Ohio."— Presentation transcript:

1 Monitoring Design Pattern Contracts Jason O. Hallstrom Clemson University SAVCBS 04 Workshop at ACM SIGSOFT 2004/FSE-12 Benjamin Tyler (Presenter) Ohio State University Neelam Soundarajan Ohio State University

2 Design Patterns and Monitoring Patterns capture key system behaviors Patterns capture key system behaviors –Behaviors often cross-cutting –Usually, specified informally To monitor and test behaviors, informal specs are not enough To monitor and test behaviors, informal specs are not enough

3 Our Approach AOP aspect – Language construct, similar to a class, that implements cross-cutting behaviors for classes in an application AOP aspect – Language construct, similar to a class, that implements cross-cutting behaviors for classes in an application Aspects can be used to capture design pattern contracts Aspects can be used to capture design pattern contracts These aspects can be used to monitor system behavior to see if these contracts are respected These aspects can be used to monitor system behavior to see if these contracts are respected

4 Methodology Overview Contract Aspect for P (abstract) The contract aspect contains the main checking logic for a pattern The contract aspect contains the main checking logic for a pattern

5 Methodology Overview System Code Purportedly uses pattern P Contract Aspect for P (abstract) The contract aspect contains the main checking logic for a pattern The contract aspect contains the main checking logic for a pattern

6 Methodology Overview System Code Purportedly uses pattern P Contract Aspect for P (abstract) Subcontract Aspect Specific to System The subcontract aspect contains definitions specific to the application The subcontract aspect contains definitions specific to the application

7 Methodology Overview System Code Purportedly uses pattern P Contract Aspect for P (abstract) Subcontract Aspect Specific to System Compiled System Monitors P Compile/Weave

8 Methodology Overview Another System Also uses P Contract Aspect for P (abstract) Subcontract Aspect Specific to System

9 Methodology Overview Another System Also uses P Contract Aspect for P (abstract) Another Subct. Aspect Specific to System

10 Methodology Overview Another System Also uses P Contract Aspect for P (abstract) Another Subct. Aspect Specific to System Compiled System Also monitors P Compile/Weave

11 Benefits of Our Approach No instrumentation of source code No instrumentation of source code Monitoring code separate from application code Monitoring code separate from application code Contract aspect needs to be created only once for a given design pattern Contract aspect needs to be created only once for a given design pattern –Only need to create new subcontract aspects for each system to be monitored

12 Aspect Terminology Pointcut – A set of places in the class code where an aspect can insert new behavior Pointcut – A set of places in the class code where an aspect can insert new behavior Advice – Code associated with a pointcut that implements this new behavior Advice – Code associated with a pointcut that implements this new behavior

13 Monitoring with Aspects before(Calc c): SqPc(c) { } after(Calc c): SqPc(c) { } aspect CalcMonitor { int st_old; pointcut SqPc(Calc c): exec(Sqrt()) && targ(c); assert(c.st >= 0); st_old = c.st; assert(c.st^2 <= st_old && st_old <(c.st+1)^2); } class Calc { int st; void Sqrt() { int i = 1; while(i*i<=st) i++; st = i-1; }

14 Pattern Example: Observer Subject +Attach(in Observer) +Notify() +Detach(in Observer) ConcreteSubject - subjectState Observer + Update() ConcreteObserver + Update() - observerState observers subject 1 * for all o in observers o.Update()

15 The Contract Aspect Formalizes the behavior intended by the pattern Formalizes the behavior intended by the pattern Advice provides the main monitoring code for the pattern Advice provides the main monitoring code for the pattern However, method names/signatures and concrete definitions for relations vary from application to application However, method names/signatures and concrete definitions for relations vary from application to application Use abstract pointcuts and methods for these in the contract aspect Use abstract pointcuts and methods for these in the contract aspect

16 Part of the Contract Aspect for Observer Property: After call to Update(), the Observer should be consistent with its subject Property: After call to Update(), the Observer should be consistent with its subject after(Subj s, Obs o): UpdatePc(s, o) { assert(Consistent(s, o)); } abstract pointcut UpdatePc(Subj s, Obs o) ; abstract boolean Consistent(Subj s, Obs o) ;

17 Part of the Contract Aspect for Observer Another property: If a call to a Subject method results in a change in state, Notify() should have been called Another property: If a call to a Subject method results in a change in state, Notify() should have been called after(Subj s): SubjMethPc(s) { assert(! Modified(s_old, s)); } before(Subj s): NotifyPc(s) { s_old = copyObject(s); … } abstract pointcut SubjMethPc(Subj s) ; abstract pointcut NotifyPc(Subj s) ; abstract boolean Modified(Subj s1, Subj s2) ;

18 In the Subcontract Aspect… Associate concrete classes with pattern roles Associate concrete classes with pattern roles –Insert dummy interfaces in the class hierarchy (AspectJ feature) Pointcut definitions that associate role methods with actual methods in the application Pointcut definitions that associate role methods with actual methods in the application Definitions for relations specific to the given application Definitions for relations specific to the given application

19 Hospital Example Patients play the Subject role Patients play the Subject role –State includes temp and heart rate Nurses observe Patients Nurses observe Patients –Keep track if Patients have a fever or not –Updates done with –Updates done with Nrs.TempUpd(Pat) Doctors also observe Patients Doctors also observe Patients –Record whether or not patients are in stable condition –Updates done with –Updates done with Doc.CondUpd(Pat)

20 Pointcuts in the Subcontract Aspect In the subcontract aspect, we give definitions for the abstract pointcuts mentioned in the contract aspect In the subcontract aspect, we give definitions for the abstract pointcuts mentioned in the contract aspect Examples: Examples: pointcut UpdatePc(Subj subj, Obs obs) : ( exec(Nrs.TempUpd(Pat)) || exec(Doc.CondUpd(Pat)) ) && targ(obs) && arg(subj) ; pointcut SubjMethPc(Subj subj) : exec(Pat.*(..)) && targ(subj) ;

21 Defining Relations Need to provide definitions of application-specific relations in the subcontract aspect Need to provide definitions of application-specific relations in the subcontract aspect Example: Modified Example: Modified boolean Modified(Subj s1, Subj s2) { return s1.temp != s2.temp || s1.hrtRate != s2.hrtRate; }

22 Defining Relations Another example: Consistent Another example: Consistent boolean Consistent(Subj subj, Obs obs) { if (obs instanceOf Nrs) { return subj.temp > 104 == obs.isFeverish(subj); } else if (obs instanceOf Doc) { return (55 < subj.hrtRate < 100 && 92 < subj.temp < 105) == obs.isStable(subj); } else { /* Error! */} }

23 Discussion Contract aspects generally harder to write than the subcontract aspects Contract aspects generally harder to write than the subcontract aspects –Only have to write them once! Information such as method call sequences can be tracked using auxiliary variables in the aspect Information such as method call sequences can be tracked using auxiliary variables in the aspect Pointcuts can encompass more than just method calls Pointcuts can encompass more than just method calls Current and future work Current and future work – MonGen and PCL

24 Presented Methodology System Code Purportedly uses pattern P Contract Aspect for P (abstract) Subcontract Aspect Specific to System Compiled System Monitors P Compile/Weave Monitoring Code

25 MonGen Methodology Contract Spec for P Subcontract Spec Specific to System Specs written in PCL MonGen System Code Purportedly uses pattern P Monitoring Aspect for System Compiled System Monitors P Compile/Weave

26 Conclusion Design patterns often describe behaviors that encompass multiple classes Design patterns often describe behaviors that encompass multiple classes Aspects are a natural way to monitor such behaviors Aspects are a natural way to monitor such behaviors Separating the essence of the pattern from the details of the application saves time and effort Separating the essence of the pattern from the details of the application saves time and effort

27 Questions? MonGen Web page: MonGen Web page: –www.cse.ohio-state.edu/~tyler/MonGen


Download ppt "Monitoring Design Pattern Contracts Jason O. Hallstrom Clemson University SAVCBS 04 Workshop at ACM SIGSOFT 2004/FSE-12 Benjamin Tyler (Presenter) Ohio."

Similar presentations


Ads by Google