Transcript ppt

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";
ResultSet rs = stmt.executeQuery(query);
while (rs.next()) {
Coffee coffee = new Coffee();
coffee.setName(rs.getString("COF_NAME"));
coffee.setPrice(rs.getFloat("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/impedanceMismatch.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:
●
●
●
AspectJ example: persistence and application
logic could be separate; retrieval and deletion
have to be explicit, storing and updating don't.
PersAJ : 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 nitr0 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.
Nitr0 Sample Application
➲
Sample Program
Nitr0 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 'firstName' and 'surname'
attributes, adds a 'middleName' attribute.
Could also modify the show method to display
middle name
The Nitr0 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 Nitr0 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/DesignPatterns/VisitorPattern.htm
➲
The programmer can obtain computational
reflection my modifying the execution
visitor's visit methods.
The Nitr0 Persistence System:
Application
➲
➲
➲
Java runtime classes: Classes (JClass),
Fields (JField), constructors (JConstructor),
methods + constructors (JMethodGroup),
references (JRef)
Instance interface (methods to make an
element persistent): makePersistent,
makeTransient, store, restore, getID
Unique ID Considerations: JInstance returns
: IP address, process ID, user ID, active
thread ID, millis since 01/01/1970
The Nitr0 Persistence System:
Persistence
➲
Class Diagram:
The Nitr0 Persistence System:
Persistence (2)
➲
Notes:
●
●
Manager : the module's Facade, implemented
as a Singleton
Storage and StoragePolicy: abstract classes,
partial implementation.
The Nitr0 Persistence System:
Persistence - Storage
Storages : a way of keeping persistent
information
3 Types of storage:
●
●
●
●
●
SimpleStorage : dictionary
BSDStorage : linear hash, B+ tree, variable length
record storage
DBMStorage : a unix based DBMS library.
The Nitr0 Persistence System:
Persistence - Policies
Policies : how to update the objects into the
selected storage
2 policies:
●
●
●
●
SimplePolicy: whenever a persistence object is
modified.
TimedPolicy: whenever a timer reaches a configurable
number of seconds
The Nitr0 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.
InstanceTable: weak dictionary mapping
PIDs to memory references, also a cache.
InstanceTable: uses weak references,
garbage collected.
Sample Bibliography application
Conclusion:
➲
Runtime Performance:
●
●
➲
To be addressed in the future using JIT (Just-InTime) 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