AspectJ2EE = AOP + J2EE - Computer Science Department

Download Report

Transcript AspectJ2EE = AOP + J2EE - Computer Science Department

AspectJ2EE/Clasa
Israel Institute of Technology
The Computer Science department
Itay Maman
Talk outline


Our Group
Overview of AspectJ2EE



Weaving mechanism
The Clasa language
A generic middleware platform: The
vision
2
Overview of AspectJ2EE

The key issue: Weaving can be achieved
via sub-classing




The sub-class will inject the additional code
into its super class
Each aspect is actually a type-to-subtype
mapping
Hence, aspects in AspectJ2EE are called:
Shakeins
Objects must be created through an object
factory

(the dynamic type of the object is different from
its static type)
3
AspectJ2EE: What the System Generates
«interface»
javax.ejb.EJBHome
«interface»
javax.ejb.EntityBean
«interface»
javax.ejb.EJBObject
«interface»
AccountHome
+create() : Account
+findByPrimaryKey() : Account
AccountBean
«interface»
Account
+withdraw()
+deposit()
+getBalance() : float
ConcreteRemoteAccountHome
+withdraw()
+deposit()
+getId() : String
+setId()
+getBalance() : float
+setBalance()
+create() : AdvAccount_Transactions
+findByPrimaryKey() : AdvAccount_Transactions
«creates»
AdvAccount_Transactions
-context : TransactionContext
-modes : Hashtable
+AdvAccount_Transactions()
+_init()
+withdraw()
+deposit()
+getId() : String
+setId()
+getBalance() : float
+setBalance()
AdvAccount_Security
-principle : String
+AdvAccount_Security()
+_init()
+withdraw()
+deposit()
(Assumes 4
Applied aspects)
_Account_Stub
+withdraw()
+deposit()
+getBalance() : float
AdvAccount_Persistence
AdvAccount_Lifecycle
-conn : Connection
-dirty : boolean
+AdvAccount_Persistence()
+_init()
+setId()
+setBalance()
+ejbLoad()
+ejbStore()
+ejbCreate()
+ejbActivate()
+ejbPassivate()
+ejbRemove()
-id : String
-balance : float
-ctx : EntityContext
+AdvAccount_Lifecycle()
+getId() : String
+setId()
+getBalance() : float
+setBalance()
+ejbLoad()
+ejbStore()
+ejbCreate()
+ejbActivate()
+ejbPassivate()
+ejbRemove()
+setEntityContext()
+unsetEntityContext()
+getEntityContext()
Lifecycle
management
is an aspect
4
Current focus: Clasa (1/4)
Motivation


Describing the characteristic of a class is not an
easy task
Example 1- Let’s define a stateless class as a
class with no fields.



Can it have static fields?
Can its super class have a private instance field?
Example 2- NoName is a class without a
“getName()” method


Can it have a static getName() method?
Can its super class have a private non-static
getName() method?
5
Current focus: Clasa (2/4)
Motivation (continued)
 There is a major gap between the
intuition and the formal definition

This gap must be bridged when:





Statistical analysis is applied over classes
A refactoring tool is developed
A point-cut is defined
…
Current point-cut constructs lack in their
expressive power

Thus, they cannot capture the wide spectrum
of Java element
6
Current focus: Clasa (3/4)
What is Clasa?

A language over the domain of Java programs



Main features





A Jar file can be thought of as a database
A Clasa function can be thought of as a query
Built-in functions for handling relations
Pattern matching
Elegant syntax
Static, strong typing, with type inference
Implementation is based on ideas drawn from
languages such as Icon, Prolog
 By using Clasa, one can precisely define
complex pointcuts
7
Current focus: Clasa (4/4)
Some Clasa queries
has_age := abstract class {
public int getAge();
public void setAge(int);
}
primitive := boolean | char | int | long | float | double;
serializeable := primitive | implements: {
‘java.lang.Serializeable‘)
non_private_ctor := [public|protected|default] ctor;
singleton := class {
no non_private_ctor;
static T create();
private static T field; }
8
Generic middleware platform (GMF) 1/4
1st approach
 What AspectJ2EE needs?

An infrastructure which provides core J2EE
services:
Persistency
 Security
 Transaction
 Logging
…


The protocol should be minimal but complete
No fancy (compound) operations
 Just like the APIs provided by an operating
system

9
Generic middleware platform (GMF) 2/4
(1st approach continued)
 What AspectJ2EE does not need?

AspectJ2EE’s weaver is based on inheritance
The advice is woven by means of sub-classing
 sub-classing is a built-in mechanism of Java



=>No “Aspect awareness”: Neither the GMF
nor the JVM need to support aspects
A “nice to have” feature:



GMF will allow client code to customize the
type of each created object
Can be thought of as a built-in object factory
Increases POJOness of the code
10
Generic middleware platform (GMF) 3/4
2nd approach

Let’s think of the GMF abstractly…
1.
2.
3.
Provides a set of built-in aspects
Allows developers to define new aspects
Is implemented by aspects ?!
=> one aspect-weaving mechanism that is used both
internally and externally

Pros



Small, compact core
A Highly customizable GMF
Cons



Bootstrapping
Not specifically related to middleware platforms
Performance
11
Generic middleware platform (GMF) 4/4
(2nd approach continued)

What is the minimal kernel of such a GMF?




A Pointcut matching engine
“primitive” aspect: Object creation

The type-to-subtype mapping is just a parameter
“primitive” aspect: System configuration change
The bottom line:



A small kernel
A huge library
Almost every thing can be customized
12
- The End -
13