cwash into software

OSGi-ggity-Giggity

by Chris Wash on Apr.15, 2009, under Java, Software Engineering

Update: A great article on OSGi popped up on Javalobby today. Check it out.

I haven’t yet written any thoughts about OSGi but it’s something that’s increasingly found its way on to my radar over the past year and a half or so. I’ve been doing a little bit of reading and research on it lately, (a quick introduction can be found via Adrian Colyer’s talks on InfoQ about it). Needless to say it’s got me excited. Really excited – to the point where I’m catching myself geeking out uncontrollably like Quagmire from Family Guy. What’s got me all giggity? Let’s take a step back first.

With Java there has always been a focus on modularity, but it’s come up in different intermediate forms. Any typical Java developer can go on for hours about the importance for layering and properly isolating, decoupling and packaging components and subsystems. Java has the idea of a package, and the idea of JARs came about fairly early on in the process. But what became difficult was that often each layer had to have its own supporting infrastructure in place to be built independently, and someone needed to know how all of those JAR dependencies mapped out at build time and runtime. This was a necessary evil so that we could have individually deployable modules or subsystems. Once you got there, it was all worth it.

The problem was that while you may have been diligent and rigorous in your approach to applying how your projects were laid out and built, quite often the framework space solved this problem over and over again in many different ways. Going to upgrade a library was not an easy task, because you had to typically upgrade it across each of your layers, and what’s more, there was no consistent approach to manage transitive dependencies amongst the modules each library used. Library selection and dependency management was the work of a greybeard within your project and it took a while to change a library or upgrade. Not to mention a near certainty that you’d need to execute your entire suite of regression tests to make sure nothing broke.

After seeing many Java frameworks being cajoled into a Maven build in order to manage builds and transitive dependencies, there has been increased awareness on the part of the vendor (be it commercial or open source) space on modularity. But we’ve only focused on the problem of solving modularity from a build-centric view. In other words, “How can I package and manage these build artifacts in such a way that consumers can easily integrate them into their project in a consistent and automated way?” This was the pie-in-the-sky idea behind Maven as I see it, and they pretty much made it happen. You’d be hard pressed to find a framework today that doesn’t support it in some fashion.

But there’s a whole separate piece of modularity that takes place at runtime. In the context of my historical explanation of modularity within Java, you can look at OSGi’s ability to manage dependencies dynamically at runtime (via a header in your JAR MANIFEST file) as a “modularity win” and icing on the cake. But OSGi indeed goes farther than that. OSGi gives you the ability to install/uninstall, start and stop bundles dynamically (think Eclipse plugins) via its lifecycle, and that just plain gives me the “giggities.” To account for truly dynamic modularity OSGi also gives you requires and provides semantics (also declared via headers) akin to the requires and provides semantics you see in dynamic languages like Ruby and some Javascript packaging/dependency management frameworks. While this may seem like its strength is only in making a clear separation between APIs you use and export, its real strength is that this allows you to truly isolate your modules at runtime from trickery that can (and has) happened on a classloader level. “That couldn’t possibly work on an App server,” you say? I was skeptical, too, but not so fast…

If you’re the type that keeps up with the JCP space, you probably know there is a JSR “trinity” (equally as mysterious as its holy counterpart to the outside viewer) to provide a more robust modularization mechanism in varying degrees. That “quagmire” withstanding, OSGi has been mounting a considerable lead as the modularization system of choice in the JavaSE and EE/App server space. (It was already a formidable player in the embedded/mobile space, where it evolved from.) Nearly all major App server vendors have integrated the OSGi model into their core, which means they’ve probably cleaned up any classloader nastiness they’ve resorted to in the past. And now you’re seeing some of the leading frameworks like Spring and Web Beans/Seam 3 (and subsequently have signed up to publish themselves as OSGi bundles.) Not to mention the success that Eclipse has seen since refactoring itself to work off its OSGi implementation, Equinox.

If OSGi can continue to make inroads in the framework space, I think its prospects to the “in the trenches” Java developer are very exciting indeed. Expect me to babble on more about this in the future…

 
 

More Related Content

:, , , , ,
4 comments for this entry:
  1. Alex Buckley

    What JSR “trinity”? If you are the type that keeps up with the JCP space, you’ll know there was JSR 291 (OSGi R4.1) a couple of years ago and there is JSR 294 (Modularity in the Java language) now. JSR 294 offers to OSGi the possibility of true module/bundle-level encapsulation at runtime, and has numerous OSGi experts on its Expert Group. JSR 294 also handles dependency resolution at compile-time as well as runtime. Perhaps you should check it out.

    You’ll also know that JSR 277 is suspended, and that OpenJDK’s Project Jigsaw is developing a small module system capable of bootstrapping the JVM and modularizing the JDK.

  2. Chris Wash

    @Alex – Thanks for filling in the blanks there! I was hoping someone would call out my lack of clarification around the JSRs. I was generally aware of these but definitely not the guy to provide that update or speak intelligently about any of them… :)

    I’ll definitely take a closer look at 294 because I’d really like to see constructs for modularity at the language level. It would be a huge stride in terms of code reuse. Also, the idea of having a concise, bootstrappable JVM “kernel” and modularized supporting JDK… Giggity to that as well!

    My only concern is that some people may be put off by that thinking they have no options for dealing with modularity today or that such a feature is too far out for them to think about now.

  3. Justin Bleach

    I read the post and watched some of the video from the provided link and I have to say it sounds good to me too! Definitely going to have to find some more resources on it.

  4. Chris Wash

    @Justin – Yeah, I think it provides what’s needed to get code reuse right. Stay tuned!

Leave a comment

GoogleYahooWordpressAOLFlickrBloggerLivejournalMyOpenIDTechnoratiVerisignVidoopClaimIDOpenId



Enter your comment

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

Visit our friends!

A few highly recommended friends...

Archives

All entries, chronologically...