0
OSGi
   Tales from the Trenches
   Bertrand Delacretaz
   Senior R&D Developer, Day Software, www.day.com
   Apache Softwa...
What?
    Share our experience using Apache Felix at
    Day, for a major rewrite of our content
    management products.
...
Ok but what?
                                                           the


                                            ...
Introduction

OSGi tales from the trenches
First a warning
                       is not an OSGi guru!
                      I’m just a poor lonesome user...
OSGi ta...
OSGi ?
  OSGi™
  The Dynamic Module System for Java™
  http://www.osgi.org (see also Wikipedia)
  Consortium founded 1999,...
Trenches?


            family of content
          management products,
          R&D team of about 30


                ...
What we use from OSGi
    Bundles (using Maven plugins)
    Lifecycle, Service Tracker
    Configurations and Felix Web Con...
Famous quotes

OSGi tales from the trenches
Famous Quotes, #1
    “Effectively, OSGi brings many of the
    desirable aims of SOA into the JVM.quot;”




    Paul Fre...
Famous Quotes, #2
    “Each (OSGi) bundle can serve as a micro
    application, having it's own lifecycle,
    having it's...
Famous Quotes, #3
    “OSGi is great, but the tooling is not quite
    there yet. Not every library is a bundle and
    ma...
Famous Quotes, #4
    “The lifecycle model of OSGi makes life
    complicated. Actually, tracking services
    and managin...
Famous Quotes, #5
    “The challenge for the coming year is to
    make OSGi more in line with the
    expectations of the...
Famous Quotes, #6
    “OSGi makes quot;impossiblequot; things easy:
    hot deploy/upgrade, service discovery, ...
    and...
Our opinion

OSGi tales from the trenches
The Good

OSGi tales from the trenches
Modularity
                                                            OSGi bundle
    Classloading
    distinct from     ...
Declarative Services
    /**
    * Excerpts from a Sling Servlet, processes *.query.json requests
    * Uses Felix’s maven...
Clean API




   Just a few
   basic examples...

OSGi tales from the trenches
Dynamic loading / unloading
      Just copy bundle jar
      to Sling’s JCR
      repository (WebDAV)




                ...
Plugins for everything
                                        Content editors based on
       Servlets                   ...
Plugins: ServiceTracker
   // Enumerate currently available AuthenticationHandler
   // services, and select the one to us...
Legacy/customer code
                                                          OSGi bundle
    Ugly or
    incompatible   ...
Private / public packages
    maven-bundle-plugin instructions:
    <Export-Package>
     sling.jcr.jackrabbit.server.secu...
The Bad

OSGi tales from the trenches
Granularity is a hard problem
    How many bundles?
    > 100 currently in cq5

    How to handle “implementation details”...
Clean up those packages!
                                                           OSGi bundle
    Clean
    separation o...
Integration testing required
                     V4.22                                         V4.5      V7.4
      V1.03...
Is OSGi scary?
    “OSGi is difficult to sell - it is adopted in
    some really visible products,like
    websphere, glass...
Is it too early?
    me: Starting two years later might have
    helped avoid initial pains and incomplete
    implementat...
The Ugly

OSGi tales from the trenches
Asynchronous startup
                            7                                               14
                      ...
Unpredictable assemblies
                     V4.22                                         V4.5      V7.4
      V1.03    ...
Testing

OSGi tales from the trenches
Testing?
                                                                   Integration
         JUnit
                   ...
JUnit testing w/mocks
           JUnit                                                  Example, using jmock.org:
        ...
Integration tests, OSGi + HTTP
                                                     Bundles under test
             cargo-...
Integration test: JsonRenderingTest
    public void testRecursiveInfinity() throws IOException {

         final Map<String,...
Unpredictable assemblies
                     V4.22                                         V4.5      V7.4
      V1.03    ...
The Future

OSGi tales from the trenches
OSGi @day, 2 years from now
    Developers got used to it (and
    read the book).

    Frameworks and tools improved.

  ...
Do we need more features?
    Today we use:
    Bundles (using Maven plugins)
    Lifecycle, Service Tracker
    Configurat...
Conclusions
    Good? Bad? Ugly?




OSGi tales from the trenches
Conclusions
               OSGi is great for modularity

               OSGi fosters better structured code

             ...
Upcoming SlideShare
Loading in...5
×

Tales from the OSGi trenches

6,271

Published on

Slides of my "Tales from the OSGi trenches" presentation at ApacheCon Europe 2009

Published in: Technology
2 Comments
13 Likes
Statistics
Notes
No Downloads
Views
Total Views
6,271
On Slideshare
0
From Embeds
0
Number of Embeds
6
Actions
Shares
0
Downloads
292
Comments
2
Likes
13
Embeds 0
No embeds

No notes for slide

Transcript of "Tales from the OSGi trenches"

  1. 1. OSGi Tales from the Trenches Bertrand Delacretaz Senior R&D Developer, Day Software, www.day.com Apache Software Foundation Member and Director bdelacretaz@apache.org blog: http://grep.codeconsult.ch twitter: @bdelacretaz Special thanks to: ApacheCon Europe 2009, Amsterdam Filippo Diotalevi (osgilook.com) slides revision: 2009-03-25 and The Day R&D team for additional input! OSGi tales from the trenches
  2. 2. What? Share our experience using Apache Felix at Day, for a major rewrite of our content management products. More than two years working with OSGi, very high impact on developers, customers, service people, mostly in a positive way. OSGi is no silver bullet either. silve r OSGi tales from the trenches
  3. 3. Ok but what? the GOOD the BAD the UGLY and the FUTURE symbols by ppdigital , o0o0xmods0o0oon and clarita, on morguefile.com OSGi tales from the trenches
  4. 4. Introduction OSGi tales from the trenches
  5. 5. First a warning is not an OSGi guru! I’m just a poor lonesome user... OSGi tales from the trenches
  6. 6. OSGi ? OSGi™ The Dynamic Module System for Java™ http://www.osgi.org (see also Wikipedia) Consortium founded 1999, 100 companies. Initially meant for mobile devices. Now moving to server-side, fast. Eclipse, LinkedIn, GlassFish, WSO2, WebSphere and many others. @apache: Felix, ServiceMix, Sling, CXF, Tuscany and more, growing. OSGi tales from the trenches
  7. 7. Trenches? family of content management products, R&D team of about 30 built on Apache Sling, http://www.day.com/cq5 http://jackrabbit.apache.org uses Apache Felix and http://felix.apache.org Jackrabbit http://incubator.apache.org/sling OSGi tales from the trenches
  8. 8. What we use from OSGi Bundles (using Maven plugins) Lifecycle, Service Tracker Configurations and Felix Web Console Declarative Services (using Maven plugins) Sling’s jcrinstall module (bundles and configs loaded from the JCR repository) Log, HTTP, Event services presented by Carsten at 10:30 OSGi tales from the trenches
  9. 9. Famous quotes OSGi tales from the trenches
  10. 10. Famous Quotes, #1 “Effectively, OSGi brings many of the desirable aims of SOA into the JVM.quot;” Paul Fremantle http://pzf.fremantle.org/2009/02/wso2-carbon- part-1.html OSGi tales from the trenches
  11. 11. Famous Quotes, #2 “Each (OSGi) bundle can serve as a micro application, having it's own lifecycle, having it's own citizens and each bundle can carefully decide which objects to expose to the outside world” Peter Rietzler http://peterrietzler.blogspot.com/2008/12/is-osgi-going- to-become-next-ejb-bubble.html OSGi tales from the trenches
  12. 12. Famous Quotes, #3 “OSGi is great, but the tooling is not quite there yet. Not every library is a bundle and many JARs don’t have OSGi manifests” Matt Raible in http://blog.linkedin.com/2008/06/23/osgi-at-linkedin- integrating-spring-dm-part-1/ OSGi tales from the trenches
  13. 13. Famous Quotes, #4 “The lifecycle model of OSGi makes life complicated. Actually, tracking services and managing all the aspects of what to do when services come and go is nasty” Peter Rietzler http://peterrietzler.blogspot.com/2008/12/is-osgi-going- to-become-next-ejb-bubble.html OSGi tales from the trenches
  14. 14. Famous Quotes, #5 “The challenge for the coming year is to make OSGi more in line with the expectations of the average J2EE programmer because we see that need” Peter Kriens in a comment at http://peterrietzler.blogspot.com/2008/12/is-osgi-going- to-become-next-ejb-bubble.html OSGi tales from the trenches
  15. 15. Famous Quotes, #6 “OSGi makes quot;impossiblequot; things easy: hot deploy/upgrade, service discovery, ... and trivial things hard: hibernate, tag libraries, even deploying a simple war!” But, for the first time in my career, I see software reusability that works: service reusability. Filippo Diotalevi OSGi tales from the trenches
  16. 16. Our opinion OSGi tales from the trenches
  17. 17. The Good OSGi tales from the trenches
  18. 18. Modularity OSGi bundle Classloading distinct from Public packages class visibility. Metadata Bundles as Private packages reusable components. At last! Matchless picture: Alvimann on morguefile.com OSGi tales from the trenches
  19. 19. Declarative Services /** * Excerpts from a Sling Servlet, processes *.query.json requests * Uses Felix’s maven-scr-plugin annotations * @scr.component immediate=quot;truequot; * @scr.service interface=quot;javax.servlet.Servletquot; * @scr.property name=quot;sling.servlet.resourceTypesquot; value=quot;sling/servlet/defaultquot; * @scr.property name=quot;sling.servlet.extensionsquot; value=quot;jsonquot; * @scr.property name=quot;sling.servlet.selectorsquot; value=quot;queryquot; */ public class JsonQueryServlet extends SlingSafeMethodsServlet { /** @scr.reference (injected by framework) */ private SlingRepository repo; // activate(ComponentContext) and deactivate(ComponentContext) // methods are called by framework if present Annotated Java class + ... } Maven plugins == OSGi service OSGi tales from the trenches
  20. 20. Clean API Just a few basic examples... OSGi tales from the trenches
  21. 21. Dynamic loading / unloading Just copy bundle jar to Sling’s JCR repository (WebDAV) Bundle activated and started. (using Sling’s jcrinstall module) OSGi tales from the trenches
  22. 22. Plugins for everything Content editors based on Servlets JCR node properties Mime-type based handlers Debugging/monitoring tools Content renderers and decorators Legacy integration gateways Mail and messaging services etc, etc... OSGi tales from the trenches
  23. 23. Plugins: ServiceTracker // Enumerate currently available AuthenticationHandler // services, and select the one to use ServiceTracker st = new ServiceTracker( bundleContext, AuthenticationHandler.class.getName()); ServiceReference[] sr = st.getServiceReferences(); for (int i = 0; i < sr.length; i++) { AuthenticationHandler h = (AuthenticationHandler) authHandlerTracker.getService(services[i]); // ... OSGi tales from the trenches
  24. 24. Legacy/customer code OSGi bundle Ugly or incompatible Public packages code Metadata segregated via private packages Private packages OSGi tales from the trenches
  25. 25. Private / public packages maven-bundle-plugin instructions: <Export-Package> sling.jcr.jackrabbit.server.security </Export-Package> <Private-Package> sling.jcr.jackrabbit.server.impl.* </Private-Package> OSGi tales from the trenches
  26. 26. The Bad OSGi tales from the trenches
  27. 27. Granularity is a hard problem How many bundles? > 100 currently in cq5 How to handle “implementation details” libraries. Extra bundles or private packages? Strict version management required. Are we there yet? OSGi tales from the trenches
  28. 28. Clean up those packages! OSGi bundle Clean separation of Public packages interface and Metadata implementation packages required Private packages but when done! OSGi tales from the trenches
  29. 29. Integration testing required V4.22 V4.5 V7.4 V1.03 V3.21 V3.22 V4.2 V5.11 V5.3 V2.13 V6.54 V1.05 In-system V1.11 V6.4 V1.03 testing? V3.4 V6.4 V3.2 V5.43 V3.2 V2.4 but when done! V5.6 OSGi tales from the trenches
  30. 30. Is OSGi scary? “OSGi is difficult to sell - it is adopted in some really visible products,like websphere, glassfish, eclipse, but people don't know that.” (Filippo Diotalevi) Why so many bundles? Where’s my J2EE? Is the book ready? Whaddyamean “provisioning”? OSGi tales from the trenches
  31. 31. Is it too early? me: Starting two years later might have helped avoid initial pains and incomplete implementations. Felix Meschberger: If we would have done that, we would be nowhere near where we are now! Server-side OSGi is still fairly new... OSGi tales from the trenches
  32. 32. The Ugly OSGi tales from the trenches
  33. 33. Asynchronous startup 7 14 11 17 V4.22 V4.5 V7.4 15 1 V1.03 V3.21 V3.22 11 3 V4.2 2 10 V5.11 V5.3 V2.13 19 V6.54 16 V1.05 Threading 5 6 “unpredictable” V1.11 18 V6.4 issues? V1.03 13 startup order 8 V3.4 V6.4 12 4 V3.2 9 V5.43 19 V3.2 V2.4 Is the system ready now? 20 V5.6 Caused by Declarative Services, not by OSGi itself. OSGi tales from the trenches
  34. 34. Unpredictable assemblies V4.22 V4.5 V7.4 V1.03 V3.21 V3.22 V4.2 V5.11 V5.3 V2.13 V6.54 V1.05 V1.11 V6.4 V1.03 V3.4 V6.4 V3.2 V5.43 V3.2 V2.4 Spot the monsters! Security and lots of discipline would help V5.6 OSGi tales from the trenches
  35. 35. Testing OSGi tales from the trenches
  36. 36. Testing? Integration JUnit JUnit testing, and mocks, with OSGI OSGi, HTTP no OSGi Test the code Test bundles Test assemblies Required. in realistic in realistic Sufficient? conditions conditions Many examples in Sling We don’t use this at this time. Sling launchpad and jcrinstall OSGi tales from the trenches
  37. 37. JUnit testing w/mocks JUnit Example, using jmock.org: and mocks, JsonReaderTest in Sling’s contentloader module. no OSGi @org.junit.Test public void testEmptyObject() No OSGi needed, throws Exception { fast! this.mockery.checking(new Expectations() {{ But what am I allowing(creator).createNode(null, null, null); testing exactly? inSequence(mySequence); Sometimes hard to allowing(creator).finishNode(); follow or modify. inSequence(mySequence); }}); this.parse(quot;quot;); } https://svn.eu.apache.org/repos/asf/incubator/sling/trunk/bundles/jcr/contentloader/src/test/java/org/apache/sling/jcr/contentloader/internal/JsonReaderTest.java OSGi tales from the trenches
  38. 38. Integration tests, OSGi + HTTP Bundles under test cargo-maven2 plugin starts webapp surefire-plugin runs tests HTTP HTTP Felix OSGi console Felix OSGi framework Sling app (cargo-maven2 plugin) JUnit tests Maven Examples in Sling’s launchpad/testing and jcrinstall modules. OSGi tales from the trenches
  39. 39. Integration test: JsonRenderingTest public void testRecursiveInfinity() throws IOException { final Map<String, String> props = new HashMap<String, String>(); props.put(quot;textquot;, testText); props.put(quot;a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/q/r/s/t/u/v/w/x/yquot;, quot;yesquot;); final String url = testClient.createNode(postUrl, props); final String json = getContent(url + quot;.infinity.jsonquot;, Simulate actual CONTENT_TYPE_JSON); usage! assertJavascript(testText, json, quot;out.print(data.text)quot;); assertJavascript(quot;yesquot;, json, quot;out.print(data.a.b.c.d.e.f.g.h.i.j.k.l.m.n.o.p.q.r.s.t.u.v.w.x.y)quot;); } OSGi tales from the trenches
  40. 40. Unpredictable assemblies V4.22 V4.5 V7.4 V1.03 V3.21 V3.22 V4.2 V5.11 V5.3 V2.13 V6.54 V1.05 V1.11 V6.4 V1.03 V3.4 V6.4 V3.2 V5.43 V3.2 V2.4 Integration testing helps! V5.6 OSGi tales from the trenches
  41. 41. The Future OSGi tales from the trenches
  42. 42. OSGi @day, 2 years from now Developers got used to it (and read the book). Frameworks and tools improved. Distributed OSGi? Maybe. Customers understand OSGi and like it.. Apache Sling paved the way. OSGi tales from the trenches
  43. 43. Do we need more features? Today we use: Bundles (using Maven plugins) Lifecycle, Service Tracker Configurations and Felix Web Console Declarative Services (using Maven plugins) Sling’s jcrinstall module Log, HTTP, Event services Later: Deployment packages. Security maybe. More? Not really - tame what we use! OSGi tales from the trenches
  44. 44. Conclusions Good? Bad? Ugly? OSGi tales from the trenches
  45. 45. Conclusions OSGi is great for modularity OSGi fosters better structured code Dynamic services and plugins Tooling needs to improve, but usable OSGi skills need to improve! Asynchronous startup can be problematic if using declarative services OSGi tales from the trenches
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×