Why should I care about OSGi anyway?

Adrian Colyer

InfoQ has a discussion thread summarizing the reactions to the announcement of the SpringSource Application Plaform. Michael Burke asked a great question on that thread which can be paraphrased as "forgetting the hype surrounding OSGi, what benefits can I expect to see if I port an application currently packaged as an EAR to OSGi bundles?".

I started answering this question on the InfoQ thread, but my answer was growing too long for a comment so instead I'll address it here.

The question is a good one. The main difference you will see in an OSGi-based application versus a traditional JEE EAR-based application is improved modularity. So the question becomes, does this improved modularity bring me any benefits, and if so what are they? The book "Design Rules, The Power of Modularity" gives a very thorough treatment of the question. It's great background but I get that feeling that Michael may be looking for something a little less theoretical than what you'll find in that book! Let's break the modularity benefits down into two categories: benefits you should expect to experience during development time, and benefits you should expect to experience during runtime:

Development time benefits.

  • Strict development time (and runtime) enforcement of module boundaries
  • OSGi has mechanisms to ensure that module boundaries are respected by the development teams. Using OSGi the types exported by a module are explicitly declared (if it's not exported, it's not visible), and the dependencies of a module are also explicitly declared (this can include version-range compatibility information). This means that when using the development tools the team can't code-complete themselves into a violation of module boundaries, and at runtime the OSGi service platform will prevent one module from seeing the private internals of another module. So your application architecture stays clean and protected during the development cycle rather than slowly breaking down through (often inadvertent) unwanted coupling.

  • A service-oriented architecture that works for managing service dependencies between modules.
  • The dependencies between modules aren't restricted to just types of course – modules also need to make available services (think Spring beans) for other modules to use, and may depend on services (think Spring beans again) provided by other modules. Instead of your application essentially being one large application context, think of it as a set of peer contexts interacting via a local service registry. Spring beans (components) are private to the module unless explicitly exported. Bean references across modules are managed by the runtime. Once again this means that developers working on a module are free to make whatever internal changes they like, so long as the external contract (beans published, types exported) stays constant. When using Spring Dynamic Modules both the imported and exported types and the imported and exported services of a module are specified declaratively (the former in the OSGi manifest, the latter in a Spring configuration file).

  • Better ability to structure development teams the way you want to
  • "Organization follows architecture". It's easy to assign a team to work on a given module or modules. It's much harder to ask a team to implement a function that crosscuts many modules. So what naturally tends to happen is that your technical architecture (how you divide a system into modules) dictates your organizational structure – i.e. how effectively you are able to partition the work among teams and individuals. Greater flexibility in modularizing your application means greater flexibility in structuring your team. Sometimes you see the reverse: "architecture follows organization". This tends to happen when there are sets of co-located individuals forming a distributed team. In order to make sensible work assignments you want to align modules with locations if you can. So if you can't move the people, then to a reasonable extent your architecture is dictacted by your organization. The more flexibility you have in module decomposition, the greater the chance you can find something that works well for you.

  • Faster team-based development
  • When modules have clear boundaries – well defined external interfaces, well-specified dependencies, and protected internals, it's much easier for teams working on those modules to develop in parallel without accidentally treading on each others toes. Well-specified interactions are easier to stub and mock, and easier to integrate. This should lead to more productive teams and faster development cycles.

  • Faster testing cycles
  • When you're testing in-container the SpringSource Application Platform development tools for Eclipse take advantage of the OSGi Service Platform's ability to dynamically update a given module in a running system. An incremental builder associated with your project automatically udates the module in a running platform instance whenever you make a change. This can be any change – code or otherwise. So if for example you are working in the web tier, continuously interacting with your web application and testing as you go, the web module will be refreshed on each change – and you won't need to wait for your persistence layer to be reinitialised each time. The smart management of service references between bundles (modules) that Spring Dynamic Modules provides ensures that all inter-module links are repaired after refresh. This development experience is quite addictive: you have been warned!

  • Support for versioning as part of dependency management
  • When a module specifies its dependencies, it can give a version range (which can be restricted to just a single version) for the versions of the dependency that it is compatible with. OSGi allows for multiple versions of a Java package to be present at runtime simultaneously. This allows scenarios whereby the team working on module A need version x of some library, and the team working on module B need version y of some library (and x and y are incompatible). So long as modules A and B never need to exchange types from that library between them this will work without any difficulties. If modules A and B do need to exchange types between them then the OSGi Service Platform will detect this potential conflict at deployment time rather than at runtime (assuming the manifests for the two modules have been correctly generated).

  • Less road-blocks
  • Unlike my other points (which relate to OSGi in general) this point is particular to the SpringSource Application Platform. We're confident that if you start developing Spring and OSGi-based enterprise applications on the SpringSource Application Platform you'll encounter a lot less road-blocks along the way with enterprise libraries not working the way you would expect them to under OSGi than you would if you tried to develop directly to an OSGi Service Platform (even though the programming and deployment model is the same).

Runtime benefits

The runtime benefits stem from the fact that modules in OSGi are not just development time constructs. They very much exist at runtime, have their own lifecycle, and can be inspected in a running system.

  • Full information about the installed modules and their wiring is available at runtime – a level of insight operations teams have never had before.
  • You can list all of the installed bundles and their versions, see the packages they are exporting and importing, and also see the services they are exporing and importing (together with the identity of the bundles providing those services and packages). Previously operations teams have had little or not visibility into a running application beyond the JEE deployment unit level, OSGi changes all of that. (Aside, the SpringSource Application Management Suite provides even more insights, but that's another topic).

  • Isolate changes
  • Since it is possible to install, uninstall, update and refresh modules independently, you can reduce the risk of making changes to production applications by scoping the change to a smaller unit (the bundle). The rest of the application (the other bundles) can remain unchanged. Yes you may well have a long change control process meaning that in real terms making the change is no quicker, but at least you can now make the change with greater certainty that you have not introduced any other unintended differences.

  • Share dependencies
  • OSGi's support for versioning makes it practical to install trusted versions of enterprise libraries once in the platform and then share them between applications.

  • Use just the server facilities you need
  • Since the server platform itself is built on top of OSGi in a modular manner you can configure the platform to have only the services you need to support the application or applications currently running on it.

Non-OSGi related benefits

What if you don't care two hoots about OSGi??? Does the SpringSource Application Platform bring any benefits then?

Yes it does.

I like to think of the SpringSource Application Platform this way:

Firstly it's a server. A lightweight configurable server with a focus on serviceability (see Rob's original post on the platform). It has useful features such as per-application separated tracing and log files, deadlock detection, failure detection and dump-processing, smart thread pools and work stealing etc.. It's a great place to deploy web applications for these reasons.

Secondly, it's a server that understands Spring-based applications. Spring is integrated out of the box, and the deployer can simplify the process of packaging and deploying Spring-based apps – for example by doing away with the need for a boiler-plate web.xml file just to configure Spring's DispatcherServlet.

Thirdly, and only thirdly, it supports OSGi for end-user applications, giving the benefits I already outlined above.

Similar Posts

Share this Post
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • DZone
  • LinkedIn
  • Slashdot
  • Technorati
  • TwitThis
 

12 responses


  1. I see at least one other category of benefits: deployment-time benefits. Right now, I'm working on an enterprise application with 3 heads (REST, SOAP and BlazeDS) so 3 web applications. And of course, all those 3 web applications share a big number of dependencies, so I could probably benefit from the fact that I'm using JBoss as a deployment platform and share those dependencies at the root of the EAR package. But I can't because it poses a whole lot of problems with classpath resource resolution and I have library conflicts so I ended up repackaging libraries in all 3 web apps. Now my EAR is 70MB and deployment to my production platform over my Internet connection takes 40 minutes! So each time I have to update something in my 3MB core module and deploy it, it takes 40 looooong minutes. So would I benefit from uploading just this 3MB jar on each production release? Hell yes!

    Then there is something more: there are all the benefits that OSGi and S2AP bring compared to traditional WAR and EAR applications, but there are also all the possibilities that it is going to open, things that we didn't even dare to dream of in the Java world. Things like extensible applications, CMS's, eCommerce platforms, collaboration suites. The mere concept of an applicative distribution is just astounding. EJB's promised reusable components that you could combine and sell and exchange, but it never really happened. Maybe now it can happen. Open your minds, we can be creative again!


  2. Sebastien

    I totally agree. The fact that users are essentially deploying half their server to the server in every EAR or WAR file–without a sophisticated way of sharing dependencies–is shocking.

    Rgds
    Rod


  3. What about the negatives?

    From what I can see, eclipse is one big failure. How can you possibly use eclipse as a shining example for OSGI given its shocking history for modularisation? It's terrible – plugin management isn't solved, its the PROBLEM in eclipse!

    Anyway, the main negative I can see is writing and maintaining non-java code descriptors for EVERYTHING. Can I say EWW! This leads to huge runtime issues and the need to do integration testing.

    I think OSGI is the biggest overrated steaming pile of ….

    one customer lost.


  4. I think many people see the benefits, but there is a need for showing a migration path. When can we expect example applications? Samples how to work with hibernate/JPA and several bundles which contribute entities. Is there a plan to port the PetStore-Application?

    Well, I like OSGI, but at the moment I have problems to the sell it to my developers or management, because there are many things to change but no proof of concepts.

    best regards.


  5. Rod,

    Isn't the alternative (runtime errors like eclipse is famous for) the alternative to deploying everything at once?
    I will take stability and correctness over runtime errors every time.


  6. [quote comment="106492"]What about the negatives?

    From what I can see, eclipse is one big failure. How can you possibly use eclipse as a shining example for OSGI given its shocking history for modularisation? It's terrible – plugin management isn't solved, its the PROBLEM in eclipse!

    Anyway, the main negative I can see is writing and maintaining non-java code descriptors for EVERYTHING. Can I say EWW! This leads to huge runtime issues and the need to do integration testing.

    [/quote]

    "osgi", you don't have to use OSGi to use the platform – regular war file deployment is also supported, and we will look at providing support for the relevant JEE6 profiles once they have been defined.

    In relation to Eclipse, the first mention of eclipse on this page comes from you! Eclipse retrofitted OSGi underneath an existing plugin model. As a result very very few Eclipse plugins take advantage of OSGi features such as the service registry that help plugins (bundles) to cope with dynamic changes in the Eclipse platform. The Eclipse extension registry (built on top of OSGi, but not part of any OSGi standard) does have support for notification of changes, but again very few plugins use this. I would argue that most of the issues surrounding plugin management in Eclipse are to do with the inability of plugins to cope with dynamic changes (forcing restarts), and the update manager itself.

    Even though these issues exist, I believe Eclipse has still been an amazing success in terms of providing an ecosystem for third parties to integrate new components and capabilities. There are literally thousands of Eclipse plugins out there, and given the number of plugins and the rate of change, the whole thing stands up remarkably well.

    On the second topic you raised, using the Application Platform tools for Eclipse your development time classpath is built from the manifests (in the same way as your runtime classpath) so you can catch any missing imports etc. early.


  7. I really do like the concept of OSGI. The only thing that it needs to really take off is tons of examples and tutorials. Typically there is a Hello World that we are all familiar with(and we all still appreciate!), then for some reason, not sure why, the author will go right from Hello World to a Space Shuttle launch and guidance system that is borderline self aware! Over the years I still revisit OSGI hoping that I will find a bazillion samples to work from, but I never do. Take the Spring Framework, they published a really good document on what to do and how to use it. And as cumbersome as JEE might be, there are tons of tutorials and products like MyEclipse that make it a snap to get up and running pretty fast. Again, I like the concept of OSGI, but I can't just divine the code and figure it all out and hope everyone else on the team does the same.


  8. Adrian, you make a very cogent case for the advantages of modularity in enterprise systems.

    The title is slightly misleading, as the advantages you are talking about are only available when using the Spring Application Platform. OSGi provides the building blocks, but the extra sugar coating needed to make the whole experience smooth is provided by Spring AP.

    It is obvious that you guys at Spring Source appreciate the value of modularity, and that you see OSGi as the way to achieve it. What is disappointing is that you not shown any interest in investigating alternative solutions which don't depend on OSGi.

    The core Spring Framework has necessary features – support for hiearchical application context, a sensible startup and shutdown model, and declarative proxies – to support building a modular system. I started Impala (http://impala.googlecode.com/) initially just to see how far I could take these initial building blocks. The results are clear to me – with Impala you get a dramatically enhanced runtime and development model for Spring, a solution which works out of the box without any special runtime, build or IDE support, and without any modified third party libraries. In my opinion, a much simpler – albeit less perfect system – than is possible to achieve using OSGi. Gain without any real pain. The practical value in this approach is still obvious to me, and hopefully to you too.

    I don't mean to criticise OSGi itself. I've learnt a fair amount about it recently, and it certainly appears a well thought through technology. However, it is undeniably complex, and when a lot of the drivers in our industry are pushing us towards simpler systems, I do questioning whether it is wise to push the entire development community en masse towards OSGi. Dealing with these complexities has forced you guys to embrace a more closed system than originally envisaged
    (requiring GPL/commercial licence, OSGi with Equinox only, and not free tool support) – a movement away from the community-oriented spirit in which Spring software has been developed in the past.

    All this being said, I anticipate a migration towards OSGi, and with Impala I intend to take advantage of OSGi, especially where it adds the most unique value – in third party class versioning.

    In short, my verdict is well done for making OSGi accessible in a way which I thought not even you guys at SpringSource would be able to achieve. A thumbs down, I'm afraid, for not doing more to address the needs of the 90 odd percent
    (not sure what the exact number is) of existing Spring users who are not using OSGi.

    One of the best things about Spring in the past is making the best use of existing technologies in an open, practical way. The Java class loading model is far from perfect, but with a little creativity it is possible to build the key features
    for a dynamic, modular system.


  9. Hi Andrian,
    In the last SpringOne, you mentioned a problem you're facing managing runtime dependencies, a problem that you tried "3-4 solutions" but were unhappy about them all. Can you elaborate on what that problem was? It sounded like something fundamental in the OSGi approach, maybe it also involved updating dependencies, I can't recall. (I know I'm vague, I just hope this will ring a bell anyway!)
    Thanks,
    Dimitris


  10. [quote comment="111085"]Hi Andrian,
    In the last SpringOne, you mentioned a problem you're facing managing runtime dependencies, a problem that you tried "3-4 solutions" but were unhappy about them all. Can you elaborate on what that problem was? It sounded like something fundamental in the OSGi approach, maybe it also involved updating dependencies, I can't recall. (I know I'm vague, I just hope this will ring a bell anyway!)
    Thanks,
    Dimitris[/quote]

    I believe the issue you are referring to is what we call "pinning". OSGi happily allows multiple versions of the same bundle (and the same packages) to exist concurrently. However, any one bundle, once it has been resolved, can be wired to only one version of a given package. Take for example the "spring orm" bundle. Lets suppose that version 2.5.5 of this bundle is wired to packages from version 3.2.6 of Hibernate. An application wishing to use Spring 2.5.5 and Hibernate 3.2.6 will be just fine. A second application wishing to use Spring 2.5.5 and Hibernate 3.2.5 however will not be fine – because the spring orm bundle can't be simultaneously resolved to both the 3.2.6 and 3.2.5 versions of Hibernate. We are looking at a solution involving transparent cloning of "pinning" bundles in scenarios such as this for future version of S2AP.


  11. Hi Andrian,

    in the following statement, can you explain the incremental builder in more detail?

    "An incremental builder associated with your project automatically udates the module in a running platform instance whenever you make a change."

    Wang


  12. Whenever you are working with a Java project in Eclipse, a partial build happens each time you save a file. This is known as an incremental build because instead of building your whole project from scratch, only the changed files are examined. Part of the incremental build process is the generation of "delta" information that other tools in the chain can use to examine the changes and react accordingly. The AP tools for STS use this information to determine whether or not the running copy of a bundle project needs to be updated, and to update it automatically if so.

6 trackbacks

Leave a Reply