Applying Aspect-Oriented Software Development to Middleware Frameworks
Total Page:16
File Type:pdf, Size:1020Kb
APPLYING ASPECT-ORIENTED SOFTWARE DEVELOPMENT TO MIDDLEWARE FRAMEWORKS TAL COHEN APPLYING ASPECT-ORIENTED SOFTWARE DEVELOPMENT TO MIDDLEWARE FRAMEWORKS RESEARCH THESIS IN PARTIAL FULFILLMENT OF THE REQUIREMENTS FOR THE DEGREE OF DOCTOR OF PHILOSOPHY TAL COHEN SUBMITTED TO THE SENATE OF THE TECHNION — ISRAEL INSTITUTE OF TECHNOLOGY ADAR, 5767 HAIFA FEBRUARY 2007 THIS RESEARCH THESIS WAS DONE UNDER THE SUPERVISION OF DR. JOSEPH (YOSSI) GIL IN THE DEPARTMENT OF COMPUTER SCIENCE I would like to thank the many people who have directly or indirectly helped me during the long period of research. I thank my supervisor, Yossi Gil, who never ceased to amaze me; my friend and co-student Itay Maman, who greatly helped in large parts of this research; Prof. Shmuel Katz, who first introduced me to the world of aspect-oriented programming; Omer Barkol, who was a wonderful office-mate these last few years; Prof. Ron Pinter, who advised and encouraged; and lastly, Yardena Kolet, the final authority in the CS faculty. This work is dedicated to my family: to my parents, Rachel and Nahum; to my beloved wife Irit; and to my two wonderful children, Stav and Yuval: May you always have rea- sons for joy! THE GENEROUS FINANCIAL HELP OF THE TECHNION IS GRATEFULLY AC- KNOWLEDGED. Contents List of Figures v List of Tables ix Abstract 1 1 Introduction 3 1.1 Why Existing Solutions Are Broken . 6 1.1.1 Limitations of the Services-Based Solution . 6 1.1.2 Limitations of Existing AOP Solutions . 7 1.1.3 Marrying J2EE with AOP . 9 1.2 Contributions and Outline . 9 1.2.1 Shakeins . 10 1.2.2 ASPECTJ2EE ................................ 10 1.2.3 JTL . 11 1.2.4 Factories . 12 1.2.5 Object Evolution . 12 2 Shakeins 15 2.1 Classes, Types, and Aspects . 16 2.1.1 The Five Facets of a Class . 16 2.1.2 The Aspects-Inheritance Schism . 18 2.2 Shakeins as Class Re-Implementors . 19 2.3 Parameterized Class Modification . 22 2.3.1 Pointcut Parameters . 26 2.3.2 Shakein Composition and Repeated Application . 27 2.3.3 A New Light on Aspect Terminology . 29 2.4 Related Work . 30 2.4.1 JBoss Dynamic AOP . 30 2.4.2 Spring AOP . 34 2.4.3 Other Related Work . 36 2.5 Summary . 37 3 AspectJ2EE 39 3.1 An Overview of ASPECTJ2EE ........................... 40 3.2 Weaving, Deployment and Deploy-Time Weaving . 42 3.2.1 Weaving . 42 3.2.2 Deployment . 43 3.2.3 Deployment as a Weaving Process for EJBs . 46 3.2.4 Deploy Time Weaving for General Classes . 48 i 3.3 The ASPECTJ2EE Programming Language . 48 3.3.1 Language Syntax . 49 3.3.2 The Deployment Descriptor . 50 3.3.3 Implementing Advice by Sub-Classing . 53 3.3.4 The Core Aspects Library . 57 3.4 Innovative Uses for AOP in Multi-Tier Applications . 57 3.4.1 Client-Side Checking of Preconditions . 58 3.4.2 Symmetrical Data Processing . 58 3.4.3 Memoization . 60 3.5 Summary . 60 4 JTL 63 4.0.1 Two Introductory Examples . 64 4.0.2 The Underlying Model . 64 4.1 The JTL Language . 66 4.1.1 Simple Patterns . 67 4.1.2 Signature Patterns . 68 4.1.3 Variables . 70 4.1.4 Predicates . 70 4.1.5 Set Queries . 72 4.1.6 List Queries . 74 4.1.7 Pedestrian Queries of Imperative Code . 75 4.2 Underlying Semantics . 76 4.2.1 Translating JTL into Datalog . 79 4.3 Using JTL in Aspect-Oriented Systems . 80 4.3.1 Specifying Pointcuts Using JTL . 80 4.3.2 Concepts for Generic Programming . 83 4.4 Additional Applications . 85 4.4.1 Integration in CASE Tools and IDEs . 85 4.4.2 LINT-Like Tests . 87 4.4.3 Additional Applications . 87 4.5 Related Work on Language Queries . 87 4.5.1 Using Existing Query Languages . 88 4.5.2 AST vs. Relational Model . 91 4.6 A JTL Extension for Program Transformation . 93 4.6.1 Simple Baggage Management . 93 4.6.2 Implementation Issues . 95 4.6.3 Multiple Baggage . 96 4.6.4 String Literals . 97 4.6.5 Baggage Management in Queries . 98 4.7 Applications of the Program Transformation Extension . 99 4.7.1 Using JTL in an IDE and for Refactoring . 101 4.7.2 JTL as a Lightweight AOP Language . 102 4.7.3 Templates, Mixins and Generics . 105 4.7.4 Non-JAVA Output . 106 4.8 Related Work on Program Transformation . 107 4.8.1 Output Validation . 110 4.9 Summary . 111 ii 5 Factories 113 5.1 Terminology . 115 5.2 Constructor Anomalies . 116 5.3 Stages of Object Creation . 117 5.4 Factories . 119 5.4.1 Automatically Generated Factories . 120 5.5 Better Decoupling with Factories . 122 5.6 Client-Side Factories . 124 5.6.1 Dynamically Bound Factories . 126 5.7 Summary . 128 6 Object Evolution 131 6.0.1 Three Approaches to Object Evolution . 132 6.0.2 Evolution Failures . 133 6.1 The Case for Object Evolution . 134 6.1.1 Implementing the STATE Design Pattern . 134 6.1.2 Lazy Data Structures . 135 6.1.3 Representing Knowledge Refinement . 139 6.1.4 Supporting Data Covariance . 139 6.2 Object Evolution . 140 6.2.1 Evolvers: Maintaining Class Invariants at Evolution . 142 6.2.2 When this Evolves . 145 6.2.3 Evolution Failures . 147 6.3 I-Evolution: Evolving within the Inheritance Tree . 147 6.3.1 Evolution to Mixin-Generated Classes . 147 6.3.2 I-Evolution Limitations . 148 6.4 M-Evolution: Evolving with Mixins . 149 6.4.1 M-Evolution and Idempotent Mixins . 149 6.4.2 M-Evolution and Non-Idempotent Mixins . 151 6.4.3 M-Evolution Limitations . 152 6.5 S-Evolution: Evolving with Shakeins . 153 6.5.1 Shakein State-Groups . 153 6.5.2 Shakeins as Dynamic Aspects . 156 6.6 Implementation Strategies . 157 6.6.1 Using Object Handles . 158 6.6.2 Compacting Evolution . 158 6.7 Related Work . 159 6.7.1 Monotonic Reclassification in the Literature . ..