the blue mountain
the blue mountain

Reputation: 11

resolving osgi service with version

i am currently evaluating osgi (using the felix 4.3 implementation) to manage versionning of services.

i have been creating the following bundles:

bundle-api (version 1.0.0) that defines interface x.y.z.SomeService: it exports x.y.z in version 1.0.0

bundle-impl (version 1.0.0) that implements SomeService (v 1.0.0), imports package x.y.z in specification-version 1.0.0 and that registers the service

bundle-api (version 2.0.0) that defines interface x.y.z.SomeService: it exports x.y.z in version 2.0.0

bundle-impl (version 2.0.0) that implements SomeService (v 2.0.0), imports package x.y.z in specification-version 2.0.0 and that registers the service

now, i have a client, bundle-client (version 1.0.0) that imports bundle-api's x.y.z in version specification-1.0.0.

how do i get the services for x.y.z.SomeService in version 1.0.0 ?

currently, when installing / activating: bundle-api 1.0.0 bundle-impl 1.0.0 bundle-api 2.0.0 bundle-impl 2.0.0 bundle-client 1.0.0

when start bundle-client, it queries for the available x.y.y.SomeService. i get as answer for the available services: bundle-impl 1.0.0 and bundle-impl 2.0.0

i would like to get only the service implementations that do match version 1.0.0.

how should i proceed ?

ps: currently, i'm setting null as filter value.

Upvotes: 1

Views: 933

Answers (3)

Peter Kriens
Peter Kriens

Reputation: 15372

A service is versioned by its interface's Java package. If you version that package correctly according to the OSGi semantic versioning model and do a corresponding package import then the OSGi framework will automatically do the selection for you. All OSGi services are versioned this way.

Maintaining this by hand is like compiling your java code to byte codes by hand, there are tools for that. bnd(tools) has extensive support to minimize handling and verifying these versions.

The whole idea of OSGi is that you are only exposed to compatible packages.

Upvotes: 0

Christian Schneider
Christian Schneider

Reputation: 19606

What you can do is publish the service with a property like version=1.0.0 and version=2.0.0. Then you can filter the service with (version=1.0.0).

I did not know that the services should be filtered by there package versions like Neil mentioned. As Neil really is an expert in this field I trust that he is right. So maybe there is a bug in the felix implementation?

Upvotes: 0

Neil Bartlett
Neil Bartlett

Reputation: 23948

What code or mechanism are you using to query the services? OSGi provides service compatibility filtering automatically, which means that if your client imports version 1.0 of an API then it will only see services that implement version 1.0, and if your client imports version 2.0 of the API then it will only see services that implement version 2.0.... etc.

However there is a method call getAllServiceReferences() that explicitly turns off this compatibility check, and can be used to get all services of all versions. In 99% of cases this is NOT what you want to do. If you have used getAllServiceReferences() then try changing to getServiceReferences().

If you are looking up services in some other way, then I need more detail to help you further.

Upvotes: 5

Related Questions