µservices for the rest of us - karl pauls
DESCRIPTION
Many people are drawn into OSGi because it provides class loaders on steroids, however, one of the often overlooked feature of OSGi is the Service Registry and the (µ)service model. µServices provide a much more powerful alternative to the traditional Java factories and listeners in your code or xml, which are the usual culprits for class loading headaches. Alas, you need to migrate your application to OSGi first in order to take advantage of µServices which would make it so much easier to migrate your application to OSGi in the first place. The idea of PojoSR (a.k.a OSGi Lite) is to remedy this situation by providing OSGi without the module layer. PojoSR is based on Apache Felix and runs in any standard Java environment: from the class path, inside a WAR, wherever your current Java runs because it never touches a class loader. It allows any application built in Java to reap the benefits of service-based modularity without first having to rid existing code of any class loader tricks. This approach also allows, many existing bundles work out of the box - just by adding them to the class path (PojoSR will detect bundles on the class path and execute their activators). It works so well that OSGi is thinking of standardizing this approach. This talk will show you how you can take advantage of µServices using PojoSR and present some examples where µServices and PojoSR wore used to modularize and OSGi'fy an existing application.TRANSCRIPT
COPYRIGHT © 2008-2011 OSGi Alliance. All Rights Reserved
µServices For the Rest of Us
Karl Pauls
Luminis
21.09.2011, 12:40-13:30
OSGi Alliance Marketing © 2008-2010 .
All Rights Reserved
Page 1
OSGi Alliance Community Event 2011© 2008-2011. All Rights Reserved Page 2
Karl
• Member Apache Software Foundation • PMC: Felix, Sling, Incubator
• PPMC: Ace, Clerezza, Celix
• Fellow at Luminis
• Project Owner PojoSR
• Co-Author of “OSGi in Action”
Luminis
http://luminis.eu
http://luminis-technologies.com
OSGi Alliance Marketing © 2008-2011 . All Rights Reserved Page 3
HISTORY
OSGi Alliance Marketing © 2008-2011 . All Rights Reserved Page 4
Agenda
• OSGi bootcamp
• OSGi µServices
• µServices For the Rest of Us
• Use Cases
• Implementation / Demo
• Closing Remarks
OSGi Alliance Marketing © 2008-2011 . All Rights Reserved Page 5
BOOTCAMP
OSGi
OSGi Alliance Marketing © 2008-2011 . All Rights Reserved Page 6
OSGi bootcamp
OSGi Alliance Marketing © 2008-2011 . All Rights Reserved Page 7
Define Modules ...
OSGi Alliance Marketing © 2008-2011 . All Rights Reserved Page 8
... Compose Modules ...
OSGi Alliance Marketing © 2008-2011 . All Rights Reserved Page 9
... with OSGi
• L3 – Provides publish/find/bind
service model to decouple
bundles
• L2 – Manages the life cycle of
bundle in a bundle cache
without requiring restarts
• L1 – Creates the concept of
bundles that use classes from
each other in a controlled way
OSGi Alliance Marketing © 2008-2011 . All Rights Reserved Page 10
service
life cycle
module
µSERVICES
OSGi
OSGi Alliance Marketing © 2008-2011 . All Rights Reserved Page 11
OSGi Alliance Marketing © 2008-2011 . All Rights Reserved Page 12
OSGi Alliance Marketing © 2008-2011 . All Rights Reserved Page 13
OSGi Alliance Marketing © 2008-2011 . All Rights Reserved Page 14
OSGi Alliance Marketing © 2008-2011 . All Rights Reserved Page 15
OSGi Alliance Marketing © 2008-2011 . All Rights Reserved Page 16
OSGi Alliance Marketing © 2008-2011 . All Rights Reserved Page 17
WHITEBOARD
OSGi Alliance Marketing © 2008-2011 . All Rights Reserved Page 19
EXTENDER
OSGi Alliance Marketing © 2008-2011 . All Rights Reserved Page 20
SERVICE COMPONENTS
OSGi Alliance Marketing © 2008-2011 . All Rights Reserved Page 21
µSERVICES FOR THE REST OF US
OSGi
OSGi Alliance Marketing © 2008-2011 . All Rights Reserved Page 22
OSGi Alliance Marketing © 2008-2011 . All Rights Reserved Page 23
OSGi Alliance Marketing © 2008-2011 . All Rights Reserved Page 24
OSGi Alliance Marketing © 2008-2011 . All Rights Reserved Page 25
OSGi Alliance Marketing © 2008-2011 . All Rights Reserved Page 26
OSGi Alliance Marketing © 2008-2011 . All Rights Reserved Page 27
OR CAN YOU?
OSGi Alliance Marketing © 2008-2011 . All Rights Reserved Page 28
PojoSR (a.k.a OSGi Lite a.k.a lite a.k.a ???)
• OSGi µServices For the Rest of Us • OSGi without the module layer
• Based on Apache Felix
• Runs in standard Java environment
• Doesn‘t create class loaders
• Apache License 2
• Exposes Service Registry to normal Java • No need for bundles
• But bundles are supported up to a point
• Missing module layer
OSGi Alliance Marketing © 2008-2011 . All Rights Reserved Page 29
USE CASES
OSGi Alliance Marketing © 2008-2011 . All Rights Reserved Page 30
Common discovery (SPI)
OSGi Alliance Marketing © 2008-2011 . All Rights Reserved Page 31
OSGi Alliance Marketing © 2008-2011 . All Rights Reserved Page 32
Migration
OSGi Alliance Marketing © 2008-2011 . All Rights Reserved Page 33
Migration with and without PojoSR
• Start using Service first! • Split into bundles later and work on trunk!
• Without PojoSR • Turn application into one big bundle
• Split into several bundles
• Fix problems
• Split even more bundles (goto split)
• Eventually, start using services
• Allows to remove ugly hacks and crazy meta-data needed
to fix problems
OSGi Alliance Marketing © 2008-2011 . All Rights Reserved Page 34
Use OSGi where you can‘t OSGi (lite) on Google App Engine using PojoSR
OSGi Alliance Marketing © 2008-2011 . All Rights Reserved Page 35
USAGE
OSGi Alliance Marketing © 2008-2011 . All Rights Reserved Page 36
OSGi Alliance Marketing © 2008-2011 . All Rights Reserved Page 37
As an OSGi „light“ framework
OSGi Alliance Marketing © 2008-2011 . All Rights Reserved Page 38
Standalone
OSGi Alliance Marketing © 2008-2011 . All Rights Reserved Page 39
IMPLEMENTATION
OSGi Alliance Marketing © 2008-2011 . All Rights Reserved Page 40
• Classloader.getResources(META-
INF/MANIFEST.MF) • Find bundle on the classpath
• Provide Bundle Revision based on jar:
and file: url schemas (extendable)
• Use and expose Apache Felix service
registry for the rest
OSGi Alliance Marketing © 2008-2011 . All Rights Reserved Page 41
DEMO
OSGi Alliance Marketing © 2008-2011 . All Rights Reserved Page 42
CLOSING REMARKS
OSGi Alliance Marketing © 2008-2011 . All Rights Reserved Page 43
Benefits and Drawbacks
• PojoSR provides part of the power of OSGi • In a non-intrusive way.
• Allows to increase modularity
• without first ridding an existing code base of class loader hacks
• Drawbacks are • Does not enforce module boundaries
• Does not allow multiple versions of the same package
• and other module layer features (so some are supported)
• Not support the Bundle-Classpath
• But you can use µServices to get rid of class loading hacks over time,
after which it will be easier to move to OSGi and get side by side
versioning and real module boundaries.
OSGi Alliance Marketing © 2008-2011 . All Rights Reserved Page 44
QUESTIONS
http://pojosr.googlecode.com
OSGi Alliance Marketing © 2008-2011 . All Rights Reserved Page 45