Download Aspect Weaving for OSGi

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
Aspect Weaving for OSGi
Martin Lippert (akquinet it-agile GmbH)
H ik S
Heiko
Seeberger
b
(Weigle
(W i l Wilczek
Wil
kG
GmbH)
bH)
© 2008 by Martin Lippert, Heiko Seeberger; made available under Creative Commons Att. Nc Nd 2.5 license | November 7th, 2008
Aspect-oriented programming
• Modularity improved a lot by OO concepts
Š Classes, interfaces
Š Information hiding, polymorphism, inheritance
• AOP adds additional concepts
Š To modularize so called “cross-cutting concerns”
ClassA
ConcernX
ClassB
ClassC
ConcernX
ConcernX
AspectX
ConcernX
Aspect Weaving for OSGi | © 2008 by M. Lippert, H. Seeberger; made available under Creative Commons Att. Nc Nd 2.5 license
AOP today
• Meanwhile AOP is an established concept
Š Useful for many situations
Š Mostly technology-centric usage scenarios
• Established languages and frameworks available
Š AspectJ: powerful language extension to Java
Š Spring-AOP:
Spring AOP: simple to use AOP for enterprise apps
• Used in production:
Š Spring itself makes heavy use of AOP concepts
Š App-servers are using AOP inside
Š Direct AOP selectively used in enterprise apps
Aspect Weaving for OSGi | © 2008 by M. Lippert, H. Seeberger; made available under Creative Commons Att. Nc Nd 2.5 license
AspectJ = AOP for Java
• AspectJ is a powerful language extension for Java
Š Hosted as an Eclipse project
Š Still very active (latest release 1.6.1 in July 2008)
• AJDT:
Š Great tooling for the Eclipse IDE (3.3, 3.4)
Š Comes close to the JDT feeling
• Spring-IDE:
Š Integrates AJDT with Spring-AOP
Š AJDT feeling for Spring apps
Aspect Weaving for OSGi | © 2008 by M. Lippert, H. Seeberger; made available under Creative Commons Att. Nc Nd 2.5 license
The Standard Use Case
ClassA
ConcernX
ClassB
ClassC
ConcernX
ConcernX
AspectX
ConcernX
Project Sources
Single Application Classpath
Java Virtual Machine
Aspect Weaving for OSGi | © 2008 by M. Lippert, H. Seeberger; made available under Creative Commons Att. Nc Nd 2.5 license
Library Aspects
ClassA
ConcernX
ClassB
ClassC
ConcernX
ConcernX
Project Sources
AspectX
ConcernX
JAR
Single Application Classpath
Java Virtual Machine
Aspect Weaving for OSGi | © 2008 by M. Lippert, H. Seeberger; made available under Creative Commons Att. Nc Nd 2.5 license
Aspects for Existing Code
ClassA
ConcernX
JARs
ClassB
ClassC
ConcernX
ConcernX
AspectX
ConcernX
Project Sources
Single Application Classpath
Java Virtual Machine
Aspect Weaving for OSGi | © 2008 by M. Lippert, H. Seeberger; made available under Creative Commons Att. Nc Nd 2.5 license
Java + OSGi
• OSGi:
Š “A dynamic module system for Java”
• Modularity
• Dynamic
• Service-Oriented
Aspect Weaving for OSGi | © 2008 by M. Lippert, H. Seeberger; made available under Creative Commons Att. Nc Nd 2.5 license
What does it mean for us?
• We would like to modularize
Š … classes and interfaces into bundles
Š … and aspects into bundles
• The obvious next step:
Š modularize cross
cross-cutting
cutting concerns into bundles
• Takes modularity to the next level
Aspect Weaving for OSGi | © 2008 by M. Lippert, H. Seeberger; made available under Creative Commons Att. Nc Nd 2.5 license
Intra-Bundle Aspects
ClassA
ClassB
ClassC
ConcernX
AspectX
ConcernX
Bundle A
Bundle B
Bundle-Classpath
Bundle-Classpath
Java Virtual Machine
Aspect Weaving for OSGi | © 2008 by M. Lippert, H. Seeberger; made available under Creative Commons Att. Nc Nd 2.5 license
Co-Op Bundle Aspects
ClassA
ConcernX
ClassB
ClassC
ConcernX
Bundle A
Bundle-Classpath
ConcernX
Bundle B
Bundle-Classpath
AspectX
ConcernX
Bundle C
Bundle-Classpath
Java Virtual Machine
Aspect Weaving for OSGi | © 2008 by M. Lippert, H. Seeberger; made available under Creative Commons Att. Nc Nd 2.5 license
Abstract Aspect Bundles
ClassA
ConcernX
ClassB
Concrete
C
t
Aspect
Abstract
Ab
t t
Aspect
ConcernX
ConcernX
ConcernX
Bundle A
Bundle B
Bundle-Classpath
Bundle-Classpath
Java Virtual Machine
Aspect Weaving for OSGi | © 2008 by M. Lippert, H. Seeberger; made available under Creative Commons Att. Nc Nd 2.5 license
Dynamics for Aspect Bundles
• OSGi allows dynamic bundle
Š … installs
Š … uninstalls
Š … updates
• Same should be possible for aspect bundles
Š … dynamic installs, uninstalls and updates of aspect bundles
Š … dynamic installs, uninstalls and updates of bundles that are
affected
ff t d by
b aspects
t
Aspect Weaving for OSGi | © 2008 by M. Lippert, H. Seeberger; made available under Creative Commons Att. Nc Nd 2.5 license
How could all this possibly work?
Aspect Weaving for OSGi | © 2008 by M. Lippert, H. Seeberger; made available under Creative Commons Att. Nc Nd 2.5 license
Equinox Aspects
• Equinox Incubator Project
Š http://www.eclipse.org/equinox/incubator/aspects
• Enables AspectJ/AOP for OSGi
Š Supports all presented use-cases
Š Ready-to-use
Ready to use
• Setting
Š Works with Eclipse 3.4 (and 3.3 deprecated)
Š Works with AJDT 1.5.2, 1.5.3, 1.6.0, 1.6.1
Aspect Weaving for OSGi | © 2008 by M. Lippert, H. Seeberger; made available under Creative Commons Att. Nc Nd 2.5 license
What can I do?
• Put aspects into standard OSGi bundles
Š Just like Java classes
• Define what and where to weave
Š aop.xml and manifest headers
• Go!
• Feels like a natural combination of AOP and OSGi
OSGi…
Aspect Weaving for OSGi | © 2008 by M. Lippert, H. Seeberger; made available under Creative Commons Att. Nc Nd 2.5 license
Load-Time Weaving for OSGi
• Let the OSGi runtime take care of weaving the aspects
Š (and not the compiler)
Š Leads to load-time weaving within OSGi
• This means:
Š No recompilation of existing bundles necessary
Š Supports “aop.xml” load-time weaving config of AspectJ
Aspect Weaving for OSGi | © 2008 by M. Lippert, H. Seeberger; made available under Creative Commons Att. Nc Nd 2.5 license
Live Demo
• Monitoring Eclipse bundles
bundles…
Aspect Weaving for OSGi | © 2008 by M. Lippert, H. Seeberger; made available under Creative Commons Att. Nc Nd 2.5 license
Caching
• Wasn
Wasn’tt that a fast startup?
• The reason: caching for woven classes
Š
Š
Š
Š
Load-time weaving happens only once
Second time startup is same as without aspects
A il bl ffor standard
Available
t d d JRE
JREs and
d IBM J9 shared
h d classes
l
Supports configuration switching
Aspect Weaving for OSGi | © 2008 by M. Lippert, H. Seeberger; made available under Creative Commons Att. Nc Nd 2.5 license
Dynamics
• Dynamics for aspect bundles
Š Means re- or un-weaving existing bundles
• How is it realized?
Š Silent update of bundles to be woven again
Š Bundles must behave nicely within dynamic situations
Aspect Weaving for OSGi | © 2008 by M. Lippert, H. Seeberger; made available under Creative Commons Att. Nc Nd 2.5 license
Live Demo
• Installing,
Installing
updating,
uninstalling
aspects at runtime…
Aspect Weaving for OSGi | © 2008 by M. Lippert, H. Seeberger; made available under Creative Commons Att. Nc Nd 2.5 license
AOP in Spring
• Spring uses AOP a lot for all kinds of purposes
• @Configurable is one example
• Realized by Spring via load-time aspect weaving
Aspect Weaving for OSGi | © 2008 by M. Lippert, H. Seeberger; made available under Creative Commons Att. Nc Nd 2.5 license
Spring & Equinox Aspects
• Equinox Aspects can do load
load-time
time aspect weaving for
Spring-powered bundles…
• Live Demo
Š @Configurable for Extensions (Views in Eclipse RCP apps)
Aspect Weaving for OSGi | © 2008 by M. Lippert, H. Seeberger; made available under Creative Commons Att. Nc Nd 2.5 license
APIs and Implementation
• org.eclipse.equinox.weaving.hook
org eclipse equinox weaving hook
Š Hooks into the runtime
Š Provides API for injecting weaving and caching
implementations
• org.eclipse.equinox.weaving.aspectj
Š Implements aspect weaving using AspectJ
• org.eclipse.equinox.weaving.caching
Š Implements caching for standard VMs
• org.eclipse.equinox.weaving.caching.j9
Š Implements caching for IBM J9 VMs (shared classes feature)
Aspect Weaving for OSGi | © 2008 by M. Lippert, H. Seeberger; made available under Creative Commons Att. Nc Nd 2.5 license
Conclusions
• Equinox Aspects brings full AOP to OSGi
Š Load-time weaving integrated into OSGi
Š Combines OSGi and AOP modularity features
• Can be used for production systems today
• Give it a try
http://www.eclipse.org/equinox/incubator/aspects
Aspect Weaving for OSGi | © 2008 by M. Lippert, H. Seeberger; made available under Creative Commons Att. Nc Nd 2.5 license
Thank you for your attention!
Q&A
Heiko Seeberger: [email protected]
Martin Lippert:
Lippert [email protected]
lippert@acm org
Aspect Weaving for OSGi | © 2008 by M. Lippert, H. Seeberger; made available under Creative Commons Att. Nc Nd 2.5 license