Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the best way to get started with OSGI? [closed]

Tags:

java

spring

osgi

What makes a module/service/bit of application functionality a particularly good candidate for an OSGi module?

I'm interested in using OSGi in my applications. We're a Java shop and we use Spring pretty extensively, so I'm leaning toward using Spring Dynamic Modules for OSGi(tm) Service Platforms. I'm looking for a good way to incorporate a little bit of OSGi into an application as a trial. Has anyone here used this or a similar OSGi technology? Are there any pitfalls?

@Nicolas - Thanks, I've seen that one. It's a good tutorial, but I'm looking more for ideas on how to do my first "real" OSGi bundle, as opposed to a Hello World example.

@david - Thanks for the link! Ideally, with a greenfield app, I'd design the whole thing to be dynamic. What I'm looking for right now, though, is to introduce it in a small piece of an existing application. Assuming I can pick any piece of the app, what are some factors to consider that would make that piece better or worse as an OSGi guinea pig?

like image 216
Nicholas Trandem Avatar asked Aug 19 '08 13:08

Nicholas Trandem


People also ask

What is OSGi start level?

The StartLevel service allows management agents to manage a start level assigned to each bundle and the active start level of the Framework. There is at most one StartLevel service present in the OSGi environment. A start level is defined to be a state of execution in which the Framework exists.

How do I run OSGi?

Getting Started To run an OSGi bundle create a new OSGi run configuration and select the framework that you set up in the first step. Then add the bundles you want to run. The plugin will run all dependencies automatically, so you don't need to manually add them. Finally run the newly created run configuration.

What is activator OSGi?

A bundle activator is nothing but a Java class that implements org. osgi. framework. BundleActivator interface and it is instantiated when a bundle is started. In other words, a bundle gets the access of OSGi framework using a unique instance of BundleContext.

How do I run OSGi bundle?

Procedure. Install the plug-in bundle into the Eclipse Equinox OSGi framework with the OSGi console. Start the Eclipse Equinox framework with the console enabled. Install the plug-in bundle in the Equinox console.


2 Answers

Well, since you can not have one part OSGi and one part non-OSGi you'll need to make your entire app OSGi. In its simplest form you make a single OSGi bundle out of your entire application. Clearly this is not a best practice but it can be useful to get a feel for deploying a bundle in an OSGi container (Equinox, Felix, Knoplerfish, etc).

To take it to the next level you'll want to start splitting your app into components, components should typically have a set of responsibilities that can be isolated from the rest of your application through a set of interfaces and class dependencies. Identifying these purely by hand can range from rather straightforward for a well designed highly cohesive but loosely coupled application to a nightmare for interlocked source code that you are not familiar with.

Some help can come from tools like JDepend which can show you the coupling of Java packages against other packages/classes in your system. A package with low efferent coupling should be easier to extract into an OSGi bundle than one with high efferent coupling. Even more architectural insight can be had with pro tools like Structure 101.

Purely on a technical level, working daily with an application that consists of 160 OSGi bundles and using Spring DM I can confirm that the transition from "normal" Spring to Spring DM is largely pain free. The extra namespace and the fact that you can (and should) isolate your OSGi specific Spring configuration in separate files makes it even easier to have both with and without OSGi deployment scenarios.

OSGi is a deep and wide component model, documentation I recommend:

  • OSGi R4 Specification: Get the PDFs of the Core and Compendium specification, they are canonical, authoritative and very readable. Have a shortcut to them handy at all times, you will consult them.
  • Read up on OSGi best practices, there is a large set of things you can do but a somewhat smaller set of things you should do and there are some things you should never do (DynamicImport: * for example).

Some links:

  • OSGi best practices and using Apache Felix
  • Peter Kriens and BJ Hargrave in a Sun presentation on OSGi best practices
  • one key OSGi concept are Services, learn why and how they supplant the Listener pattern with the Whiteboard pattern
  • The Spring DM Google Group is very responsive and friendly in my experience
    The Spring DM Google Group is no longer active and has moved to Eclipse.org as the Gemini Blueprint project which has a forum here.
like image 142
Boris Terzic Avatar answered Oct 18 '22 04:10

Boris Terzic


When learning a new technology rich tooling gets you into things without big headaches. At this point the community at ops4j.org provides a rich toolset called "PAX" which includes:

  • Pax Runner: Run and switch between Felix, Equinox, Knopflerfish and Concierge easily
  • Pax Construct: Construct, Organize & Build OSGi projects with maven easily
  • Pax Drone: Test your OSGi bundles with Junit while being framework independent (uses PaxRunner)

Then there are many implementations of OSGi compendium services:

  • Pax Logging (logging),
  • Pax Web (http service),
  • Pax Web Extender (war support),
  • Pax Coin (configuration),
  • Pax Shell (shell implementation, part of the next osgi release)
  • and much more.

.. and there is a helpful, framework independend community, - but thats now advertisement ;-)

like image 40
Toni Menzel Avatar answered Oct 18 '22 04:10

Toni Menzel