Announcement Announcement Module
Collapse

Spring Dynamic Modules forum decommissioned in favor of Eclipse Gemini Blueprint

With the official first release of Eclipse Gemini Blueprint shipped, the migration of the Spring Dynamic Modules code base to the Eclipse Foundation, as part of the Gemini project, has been completed.

As such, this forum has been decommissioned in favour of the Eclipse Gemini forums.
See more
See less
Dynamic OSGi bundle dependencies? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Dynamic OSGi bundle dependencies?

    Hi,

    I'm a little confused as to how services are wired together with OSGi and Spring DM. Let's say I have a bundle called GoodMovieLister and another called OldMovieLister. Both of these depend on a service to find movies defined by a MovieLocator interface. If there are two services OldMovieLocator and GoodMovieLocator, as far as I understand, we cannot rely on OSGi to find the right service for the right bundle as they both implement the same interface. This means, we need to reference the implementing class of each service directly:

    In OldMovieLister config:
    <reference id="movieLocator" interface="com.xyz.OldMovieLocator"/>

    In GoodMovieLister config:
    <reference id="movieLocator" interface="com.xyz.GoodMovieLocator"/>

    The problem with this comes if I define a new service called AwesomeMovieLocator. I want the GoodMovieLister to use this new locator as obviously, awesome movies are better than good ones. However, I cannot introduce this new service without modifying the configuration of all the services that are dependent on it:

    In GoodMovieLister config:
    <reference id="movieLocator" interface="com.xyz.AwesomeMovieLocator"/>

    Is there a way to dynamically change the service used by the GoodMovieLister to the new AwesomeMovieLocator without modifying its configuration, or the configuration of any other movie listers?

  • #2
    Services are an easy (and powerful) way for different bundles/modules to communicate. There are some materials on the net and the OSGi spec provides a great start so I would recommend that for an in-depth explanation.
    In your case you first have to decide what's the contract that you are looking for - say MovieLocator. You have 2 implementations for it so it depends whether you want to be aware of that or just care for the MovieLocator contract.

    Assume it's the latter then you have 2 choices for the same interface in which case, you have several choices. One supported automatically by OSGi is to use the 'service.ranking' property to give a hint of which service is the most important. Additionally you could add your own property and then use the ldap filters to do sorting (you can add any number of properties and use both string and numeric comparisons).

    In terms of picking up the 'greatest' service Spring DM supports this, adding even a new option in 2.x. In 1.2.x, if a service with a higher priority comes a long, it will be picked automatically. In 2.x, you can customize this through the 'stick-proxy' attribute.

    Comment

    Working...
    X