1 / 27

Monitoring Design Pattern Contracts

Monitoring Design Pattern Contracts. Neelam Soundarajan Ohio State University. Jason O. Hallstrom Clemson University. Benjamin Tyler (Presenter) Ohio State University. SAVCBS ’04 Workshop at ACM SIGSOFT 2004/FSE-12. Design Patterns and Monitoring. Patterns capture key system behaviors

gilles
Download Presentation

Monitoring Design Pattern Contracts

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. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


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

  2. Design Patterns and Monitoring • Patterns capture key system behaviors • Behaviors often cross-cutting • Usually, specified informally • 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 • 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

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

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

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

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

  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 Compile/ Weave Compiled System Also monitors P

  11. Benefits of Our Approach • No instrumentation of source code • Monitoring code separate from application code • 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 • Advice – Code associated with a pointcut that implements this new behavior

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

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

  15. The Contract Aspect • Formalizes the behavior intended by 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 • 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 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 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 • Insert dummy interfaces in the class hierarchy (AspectJ feature) • Pointcut definitions that associate role methods with actual methods in the application • Definitions for relations specific to the given application

  19. Hospital Example • Patients play the Subject role • State includes temp and heart rate • Nurses observe Patients • Keep track if Patients have a fever or not • Updates done with Nrs.TempUpd(Pat) • Doctors also observe Patients • Record whether or not patients are in stable condition • 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 • Examples: pointcut UpdatePc(Subjsubj, Obsobs) : ( exec(Nrs.TempUpd(Pat)) || exec(Doc.CondUpd(Pat)) ) && targ(obs) && arg(subj) ; pointcut SubjMethPc(Subjsubj) : exec(Pat.*(..)) && targ(subj) ;

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

  22. Defining Relations • Another example: Consistent boolean Consistent(Subjsubj, Obsobs) { 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 • Only have to write them once! • Information such as method call sequences can be tracked using auxiliary variables in the aspect • Pointcuts can encompass more than just method calls • 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 Compile/ Weave Compiled System Monitors P Monitoring Code

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

  26. Conclusion • Design patterns often describe behaviors that encompass multiple classes • 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

  27. Questions? • e-mail • tyler@cse.ohio-state.edu • MonGen Web page: • www.cse.ohio-state.edu/~tyler/MonGen

More Related