|OSGi services:: version resolving issues [message #509770]
||Mon, 25 January 2010 11:02
| thomas menzel
Registered: July 2009
i have another question in regard to OSGi and services.
we all know how OSGi supports side by side deployment of the same bundle at diff. versions and how they are resolved when there are dependencies via require bundle or import statements in the manifest.mf.
the question in this thread is: how to deal with it in the presence of OSGi services?
i havent tried this out myself but the question popped into my head when i couldnt sleep and i need to get it off my chest.
suppose we have a bundle B at version 1.0.0 that exports a (declartive) service. now a later version of this bundle is installed which does exactly the same, except with version 1.2.0.
now, lets us also assume there is a bundle C that consumes the service and gets it via its interface name, e.g.
the manifest of C constraints the version of bundle B to 1.0.0 and disregards version 1.2.0.
having looked/debugged recently some code of the equinox SCR i noticed that this lookup by typename is facilitated by a Map<String, service reference> where the string is the class name.
what i suppose happens is this:
both service references are in the registry and depending on their rank-value one of them gets returned. if i'm lucky this is the service ref. of bundle B @1.0.0 and all is fine.
if i'm not lucky, this is the service reference of version 1.2.0 and i get a class cast exception, b/c bundle C doesnt have bundle B @1.2.0 on its class path and even though the types are the same their classloaders are different.
the question i have:
a) is there some similar mechanism for getting services from the registry already supported by equinox but not part of the standard that honors somehow the version constraints or takes them into account
b) how to solve this concern otherwise.
one solution for b)
i suppose one way of doing this is to put the bundle version # as one of the service properties into the registry and use a filter when requesting the service.
having not worked much with those filters, i wonder if it is possible to have a custom impl. thoat would do an OSGi-style version comparison in respect to a given version string. e.g.
filter: bundle.version=0.0.0 -> get any version
filter: bundle.version=[1.0.0, 2.0.0) -> get any version between 1.0.0 and 2.0.0 excluding the upper bound
thomas menzel aka tom
Powered by FUDForum
. Page generated in 0.03074 seconds