690 likes | 864 Views
Motorola WEAVR : Aspect-Oriented Modeling in TAU. Thomas Cottenier 1,2 , Aswin van den Berg 1 , Tzilla Elrad 2 1. Software & Systems Engineering Lab, Motorola Labs 2. Illinois Institute of Technology. Outline. Aspect-Oriented Software Development Aspect-Oriented Programming
E N D
Motorola WEAVR:Aspect-Oriented Modeling in TAU Thomas Cottenier1,2, Aswin van den Berg1, Tzilla Elrad2 1. Software & Systems Engineering Lab, Motorola Labs 2. Illinois Institute of Technology
Outline • Aspect-Oriented Software Development • Aspect-Oriented Programming • Aspect-Oriented Modeling and Model Weaving • The Motorola WEAVR add-in • A Profile for modeling Aspects in UML 2.0 • An Agent for visualizing Joinpoints and Analyze Joinpoint Effects • An Agent for weaving Aspects in models • An Agent for simulating woven models in the Model Verifier • An Agent for decomposing the generated traces • Conclusions
Models Models@runtime Aspect-Oriented Programming Source Code 1990’s Object Oriented Programming Procedural Programming 1980’s Aspect-Oriented Software Development Aspect-Oriented Software Development Evolution of Software Design: Monolithic → Modular Abstraction Focus only on relevant properties Decomposition Divide software into separately named and addressable modules Encapsulation Group related things together. InformationHiding Hide implementation details from the outside Separation of Concerns Ensure that each module only deals with one concern - Low Coupling among the modules - High Cohesion within one module Metamodeling 2000’s Model-Driven Engineering
Aspect-Oriented Software DevelopmentGood Modularity Socket creation in Tomcat - fits nicely into one package (3 classes)
Aspect-Oriented Software DevelopmentGood Modularity Class Loading in Tomcat - mostly in one package (9 classes)
Aspect-Oriented Software DevelopmentPoor Modularity Logging in Tomcat - scattered across the packages and classes - error handling, security, business rules, …
Display * Figure FigureElement getX() getY() setX(int) setY(int) getP1() setP1() setP1(Point) setP2(Point) Point Line 2 Aspect-Oriented Software DevelopmentCrosscutting Concerns class DisplayTracker { static void updatePoint(Point p){ this.display(p); .... } static void updateLine(Line l){ this.display(l);.... } } DisplayTracking class Point { void setX(int x) { DisplayTracker.updatePoint(this); this.x = x; } } class Line { void setP1(Point p1) { DisplayTracker.updateLine(this); this.p1 = p1; } }
Aspect-Oriented Software DevelopmentCrosscutting Concerns Display class Tracer { static void traceEntry(String str){ System.out.println(str); } static void traceExit(String str){ System.out.println(str); } } * Figure FigureElement 2 getX() getY() setX(int) setY(int) getP1() setP1() setP1(Point) setP2(Point) Point Line Tracing class Point { void setX(int x) { Tracer.traceEntry(“Entry Point.set”); this.x = x; Tracer.traceExit(“Exit Point.set”); } } class Line { void setP1(Point p1) { Tracer.traceEntry(“Entry Line.set”); this.p1 = p1; Tracer.traceExit(“Exit Line.set”); } }
Aspect-Oriented Software DevelopmentCrosscutting Concerns Scattering In a given implementation, the code for a concern is spread out. Single concern affects multiple modules. Tangling Multiple concerns are interleaved in a single module Crosscutting Concern The inherent structure of the concern can not be modularized in the decomposition mechanism of the language (Objects or procedures), because it follows different composition rules. class Point { void setX(int x) { Tracer.traceEntry(“Entry Point.set”); DisplayTracker.updatePoint(this); this.x = x; Tracer.traceExit(“Exit Point.set”); } }
Aspect-Oriented Software DevelopmentCrosscutting Concerns • Auxiliary concerns are scattered and tangled Synchronization, Real-time constraints, Error-checking, Object interaction constraints, Memory management, Persistency, Security, Caching, Logging, Monitoring, Testing, Domain specific optimization • 80% of problems come from this 20% of code • Inflexibility: hard to change/maintain have to find all the code involved and be sure to change it consistently • Redundancy: same fragment of code in many places Leads to inconsistency • Incomprehensibility: can’t see the forest for the trees
Aspect-Oriented Software DevelopmentThe AOSD idea • crosscutting is inherent in complex systems • crosscutting concerns • have a clear purpose • have a natural structure • let’s capture the structure of crosscutting concerns explicitly • in a modular way • with linguistic and tool support
Aspect-Oriented Software DevelopmentAspects Goal of AOSD Enable the modular (not scattered) implementation of crosscutting concerns. Aspect Explicit abstraction for representing crosscutting concerns Aspect-Oriented Programming Language that provides mechanisms to capture aspects Aspect Weaver Composition mechanism that coordinates aspects with the rest of the code.
Aspect-Oriented ProgrammingAspect-Oriented Language Elements • join point (JP) model certain principled points in program execution such as method calls, field accesses, and object construction • means of identifying JPs picking out join points of interest (predicate) pointcuts: set of join points • means of specifying behavior at JPs what happens advice declarations pointcut traced(): call(* Line.*) || call(* Point.*); before(): traced() { println(“Entering:” + thisjoinpoint); }
setY(int) setX(int) setY(int) setX(int) Aspect-Oriented ProgrammingAspect-Oriented Language Elements Joinpoints certain principled points in program execution such as method calls, field accesses, and object construction - method execution - method call - field get & set - exception handler execution - static & dynamic initialization - … :Line end1:Point end2:Point moveBy(int, int) moveBy(int, int) moveBy(int, int)
Aspect-Oriented ProgrammingAspect-Oriented Language Elements Pointcuts: Queries over Joinpoints - filters picking out join points - primitive and user-definable - composable with &&, ||, ! pointcut moves(): call(void Line.setP1(Point)) || call(void Line.setP2(Point)) || call(void Point.setX(int)) || call(void Point.setY(int)) || call(void FigureElement.incrXY()); pointcut traced(): call(* Line.*) || call(* Point.*);
Aspect-Oriented ProgrammingAspect-Oriented Language Elements Advice • code body attached to a pointcut • code runs at every join point picked out by a pointcut • after advice runs after the computation of a join point (both returning normally and throwing an exception) after(): moves() { Display.update(); } before(): (sets(int Point.x)) && !withincode(void Point.setX())) || (sets(int Point.y)) && !withincode(void Point.setY())) {throw new AccessDeniedException(); }
Aspect-Oriented ProgrammingAspect-Oriented Language Elements An Aspect is a special type that crosscuts other types aspect MoveCounting { int count = 0;pointcut moves(): call(void Line.setP1(Point)) || call(void Line.setP2(Point)) ||call(void Point.setX(int)) || call(void Point.setY(int)); after(): moves() && !cflowSub(moves()) { count++; } }
Aspect-Oriented Modeling • Address Crosscutting Concerns in Behavioral Models • Abstract away from pervasive implementation details • Model-Driven Architecture: Aspect specify a Model Transformation
Models Source Code Coordination of Crosscutting Concerns in Models TAU + WEAVR Components SIP Blog IPv6 Crosscutting Concern weaving Security Fault Tolerance Data Logging TAU Code Generators
Coordination of Crosscutting Concerns in Models Models Source Code IPv6 SIP Blog TAU + WEAVR SIP Blog IPv6 Security Fault Tolerance Data Logging TAU Code Generators Translating to: C, C++, C#, Java, … Finalized Components
Coordination of Crosscutting Concerns in Models WEAVR Model weaving Engine Resource Initialization Aspect Initialization Exception Handling Aspect
The Motorola WEAVR add-in • A Profile for modeling Aspects in UML 2.0 • An Agent for visualizing Joinpoints and Analyze Joinpoint Effects • An Agent for weaving Aspects in models • An Agent for simulating woven models in the Model Verifier • An Agent for decomposing the generated traces
Motorola WEAVR A Profile for modeling Aspects in UML 2.0 Extensions to UML 2.0 for Aspect-Oriented Modeling. 3 different functions: • Define the WEAVR Aspect-Oriented Modeling constructs • Provide stereotypes to annotate the model elements that are affected by aspects (The Model Joinpoints). • Provide a reflection library (thisJoinPoint)
Motorola WEAVR A Profile for modeling Aspects in UML 2.0 An Aspect
All method calls with 2 args Tracing with 2 params All send signal with 2 args All method executions with 2 params All state machine initialize with 2 params All receive signal with 2 params All state machine termination with 2 params Aspect Deployment: Apply tracing to 4 packages Motorola WEAVR A Profile for modeling Aspects in UML 2.0
Motorola WEAVR A Profile for modeling Aspects in UML 2.0 A Pointcut
Motorola WEAVR A Profile for modeling Aspects in UML 2.0 A Connector
Motorola WEAVR A Profile for modeling Aspects in UML 2.0 WEAVR Aspect-Oriented Modeling constructs:
Motorola WEAVR A Profile for modeling Aspects in UML 2.0 • An Aspect is a specialization of a Class. As such, it has all the properties of a regular class. It can define operations, attributes, ports, signals, timers, etc. Aspects can also contain two special types of Operations: Pointcuts and Connectors. • A Pointcut is an operation that defines a query over model State Machine Entities. A pointcut is defined with respect to an Expression. An expression is a pattern over Operation, Signals or Timer signatures. • A Connector is an operation that encapsulates the behavior that is injected at the locations in the model that match a pointcut expression. • The Binds dependency specifies a binding between Connectors and Pointcuts.
Motorola WEAVR A Profile for modeling Aspects in UML 2.0 New Joinpoint Model: State Machine Actions and Transitions Action Joinpoints: • Call Expression ActionJoinpoints (equivalent to call joinpoints) • Create Expression Action Joinpoints • Output Action Joinpoints • Timer Set Action Joinpoints Transition Joinpoints: • Start Transition Joinpoints (equivalent to execution joinpoints) • Initialization Transition Joinpoints • Termination Transition Joinpoints • Triggered Transition Joinpoints
Motorola WEAVR A Profile for modeling Aspects in UML 2.0 Action Joinpoints
Motorola WEAVR A Profile for modeling Aspects in UML 2.0 Transition Joinpoints
Motorola WEAVR A Profile for modeling Aspects in UML 2.0 New Pointcut Language: Actions and Transitions Action Pointcuts:
Motorola WEAVR A Profile for modeling Aspects in UML 2.0 Action Pointcuts: example
Motorola WEAVR A Profile for modeling Aspects in UML 2.0 New Pointcut Language: Actions and Transitions Transition Pointcuts:
Motorola WEAVR A Profile for modeling Aspects in UML 2.0 Transition Pointcuts: examples
Motorola WEAVR A Profile for modeling Aspects in UML 2.0 Action Pointcuts: example
Motorola WEAVR A Profile for modeling Aspects in UML 2.0 Aspect deployment entities
Motorola WEAVR A Profile for modeling Aspects in UML 2.0 Aspect deployment entities • Aspect deployment entities are use to define which model Packages or Classes are subject to Aspect weaving. • A Deployment Diagram specifies the relationship between Aspects and Model Packages and Classes, as well as the relationships between Aspects. • The Crosscuts dependency specifies which Packages or Classes are subject to weaving for a specific Aspect. • The Follows dependency defines the order in which Aspects are woven in the model, when those interact with the model at the same locations.
Motorola WEAVR A Profile for modeling Aspects in UML 2.0 Aspect deployment entities
Motorola WEAVR A Profile for modeling Aspects in UML 2.0 Aspect deployment entities
Motorola WEAVR A Profile for modeling Aspects in UML 2.0 Aspect deployment entities
Motorola WEAVR A Profile for modeling Aspects in UML 2.0 Aspect Visualization Stereotypes
Motorola WEAVR A Profile for modeling Aspects in UML 2.0 Aspect Visualization Stereotypes • The Show Joinpoints ( ) WEAVR operation allows the user to visualize the locations in the model where Aspects apply. • Annotations are inserted in the model to indicate which Pointcuts and Aspects interact with the model at these locations. • Joinpoints ( ) are Model Elements that match a Pointcut Expression. • The jpContext ( ) stereotype extends State Chart Diagrams that contains Joinpoints. • The Before and After stereotypes are used to delimit the entry point and the exits point of Transition Joinpoints.
Motorola WEAVR A Profile for modeling Aspects in UML 2.0 ThisJoinPoint Reflective API
Motorola WEAVR An Agent for visualizing Joinpoints and Analyze Joinpoint Effects Example: Ping Pong
Motorola WEAVR An Agent for visualizing Joinpoints and Analyze Joinpoint Effects Example: Ping Pong