Separating Adaptable Persistence Attributes through Computational Reflection Authors
Separating Adaptable Persistence Attributes through Computational Reflection Authors: Francisco Ortin, Benjamin Lopez, J. Baltazar Garcia Perez-Schofield. IEEE Software, Nov – Dec 2004
Dominant Persistent-Application Development ➲ Directly Interface with SQL ● Example: List coffees = new Vector(); String query = "SELECT COF_NAME, PRICE FROM COFFEES"; Result. Set rs = stmt. execute. Query(query); while (rs. next()) { Coffee coffee = new Coffee(); coffee. set. Name(rs. get. String("COF_NAME")); coffee. set. Price(rs. get. Float("PRICE")); coffees. add(coffee); }
Dominant Persistent-Application Development (2) ➲ Use Object-Relational Mapping Software (Hibernate, OJB, etc) ● Example: <class-descriptor class="jdbctutorial. Coffee" table="Coffee"> <field-descriptor name="name" column="Name" jdbc-type="VARCHAR" length="100" /> <field-descriptor name="price" column="Price" jdbc-type="FLOAT" length="100" /> </class-descriptor>
Dominant Persistent-Application Development (3) ➲ Object Serialization ● Example: <coffee> <name> Colombian </name> <price> 11. 22 </price> </coffee>
Dominant Persistent-Application Development (4) – Problems ➲ ➲ Runtime overhead Impedance mismatch http: //www. agiledata. org/essays/impedance. Mismatch. html ➲ Explicitly write code to make objects persist
Orthogonal Persistence Purpose: to provide a single uniform computational model for all aspects of an application handling long lived data ➲ Principles: ➲ ● ● ● Type Orthogonality : all data objects should have a full range of persistence Persistence Independence : A program's form should be independent of the longevity of the data it manipulates Persistence By Reachability: reachability from a set of root objects should determine each object's lifetime.
Orthogonal Persistence (2) Examples: Orthogonal Persistence for Java (OPJ), Persistent Java (Pjama), PEVM ➲ Drawbacks: ➲ ● don't treat persistence as a completely separate concern: programmers have to follow certain steps in the application to retrieve existing or create new persistent objects. ● no adaptation of existing features such as security and concurrency)
Persistence in Aspect-Oriented Programming AOP Approach: Identify a set of crosscutting concerns and allow to program them separately (outside of the application main logic) ➲ AOP Persistence Goals: ➲ ● ● ● Modularize Persistence as an effective aspect, employing AOP techniques Reuse persistence aspects regardless of the application Develop programs that are unaware of their data's persistence nature.
Persistence in Aspect-Oriented Programming (2) ➲ Examples & Shortcomings: ● ● ● Aspect. J example: persistence and application logic could be separate; retrieval and deletion have to be explicit, storing and updating don't. Pers. AJ : provides a model for persistence, doesn't separate application data and persistence code Jorg Kienzle & Rachid Guerraoui case study on separating concurrency control and failure handling code in a distributed system: only reviewed translations – one facet of persistence
Reflective Systems Definition: a computational system's capability to reason about and act upon itself. ➲ Levels of Reflection: ➲ ● ● ● Introspection: access to system structure but not modification (Java, C#, C++) Structural Reflection: dynamic altering of a system's structure (Python, Smalltalk) Computational Reflection: dynamic customization of system structure and semantics
The nitr 0 reflective system Nonrestrictive computationally reflective system ➲ Language Neutral : currently Python, ECMAScript, Java (subset) ➲ Developed in Python 2. 2 ➲ Generic Interpreter capable of interpreting any language based on a specification ➲ Language Specification Files : express lexical and syntactic features using context free grammar. ➲
Nitr 0 Sample Application ➲ Sample Program
Nitr 0 Sample Application (2) ➲ Things to note: ● ● Java app statements to identify the application name and language The reflective app can access the author program's internal structure, and language semantics, dynamically adapting the application through computational reflection. Python app modifies 'first. Name' and 'surname' attributes, adds a 'middle. Name' attribute. Could also modify the show method to display middle name
The Nitr 0 Persistence System ➲ Subsystems: ● ● ● Interpreter: contextual analysis and application execution. A subset of Java, eliminating primitives. Application: offers representation of every running program (classes, methods, objects, etc). Independent of language (must be OO). Persistence: allows dynamic and transparent customization of the app's reflective features (e. g. storage, indexing, and update policy)
The Nitr 0 Persistence System: Interpreter Generates the program's Abstract Syntax Tree (AST) based on Java specification ➲ Interprets AST ➲ Performs decoration of AST, following the Visitor design pattern ➲ http: //exciton. cs. oberlin. edu/javaresources/Design. Patterns/Visitor. Pattern. htm ➲ The programmer can obtain computational reflection my modifying the execution visitor's visit methods.
The Nitr 0 Persistence System: Application Java runtime classes: Classes (JClass), Fields (JField), constructors (JConstructor), methods + constructors (JMethod. Group), references (JRef) ➲ Instance interface (methods to make an element persistent): make. Persistent, make. Transient, store, restore, get. ID ➲ Unique ID Considerations: JInstance returns : IP address, process ID, user ID, active thread ID, millis since 01/01/1970 ➲
The Nitr 0 Persistence System: Persistence ➲ Class Diagram:
The Nitr 0 Persistence System: Persistence (2) ➲ Notes: ● ● Manager : the module's Facade, implemented as a Singleton Storage and Storage. Policy: abstract classes, partial implementation.
The Nitr 0 Persistence System: Persistence - Storages : a way of keeping persistent information 3 Types of storage: ● ● ● Simple. Storage : dictionary BSDStorage : linear hash, B+ tree, variable length record storage DBMStorage : a unix based DBMS library.
The Nitr 0 Persistence System: Persistence - Policies : how to update the objects into the selected storage 2 policies: ● ● Simple. Policy: whenever a persistence object is modified. Timed. Policy: whenever a timer reaches a configurable number of seconds
The Nitr 0 Persistence System: Persistence – Serialization Object serialization : Python pickle module (Object ->byte array and vice versa) ➲ Swizzling & Unswizzling: converting persistence object Ids (PIDs) to references. ➲ Manager translates all persistent objects that the current one has references to. ➲ Instance. Table: weak dictionary mapping PIDs to memory references, also a cache. ➲ Instance. Table: uses weak references, garbage collected. ➲
Sample Bibliography application
Conclusion: ➲ Runtime Performance: ● ● ➲ To be addressed in the future using JIT (Just-In. Time) compilation or adaptable native code generation for the generic interpreter Can be improved via a Python JIT compiler as all objects are converted to Python. Available at http: //www. di. uniovi. es/reflection/lab
- Slides: 23