Results 1 to 2 of 2

Thread: Dynamic OSGi bundle dependencies?

Hybrid View

  1. #1
    Join Date
    Jul 2009
    Posts
    2

    Question 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. #2
    Join Date
    Jan 2005
    Location
    Bucharest, Romania
    Posts
    5,403

    Default

    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.
    Costin Leau
    SpringSource - http://www.SpringSource.com- Spring Training, Consulting, and Support - "From the Source"
    http://twitter.com/costinl
    Please use [ c o d e ] [ / c o d e ] tags

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •