I think there are many possible solutions to your problem:
1) Use the BundleTracker which tracks the bundles carrying the versioned
resource (it might be in a specific place in the JAR, or via a manifest header)
and you pick the one you need (a service just giving a resource is a rather
thin imho and not a good use of services)
2) Use DS's MULTIPLE cardinality. This will inject you with all the services
(where each service MUST have the same version== package version, it is
confusing if you talk about the version of a service when it is actually the
same service type but just gives you a different XML). You can then pick the
right one once you know the device.
3) Once you got the device, look through all bundles to see which one carries
your resource
Your problem sounds awfully close to the problem the Device Access
specification tries to solve. You might want to look there. In this model you
would register a service representing your device. The Device Access manager
would then try to find an appropriate driver for this device, which would then
register a refined service. In the driver service it should not be that hard to
make the connection to the right resource. Or you make an extender that
registers a Driver service for each XML resource.
Kind regards,
Peter Kriens
On 18 jun. 2014, at 01:05, [email protected] wrote:
> Hi everyone,
> I asked this question
> http://stackoverflow.com/questions/22459539/get-declarative-service-at-runtime
> a couple of months ago where I was trying to find a way using Declarative
> Services to be able to decide at runtime which version of a service to use.
> One of the answers there was that DS is a build-time model so that I couldn't
> change this model at runtime ("inject me now version 1.4 instead of version
> 1.8"). This made me go the iPojo route where I finally found a solution: an
> aggregate dependency where instead of having a single service injected, I get
> all of the ones for that interface injected via a list or array and then it
> is up to the consumer to keep that list and decide which version to use when
> the moment comes. This seems to work fine; however, iPojo in eclipse is not
> working very well with java 8, so i am reconsidering if DS would be able to
> do the job. Is there any way to get a list of all the services implementing
> an interface, and have that list be updated when a new provider registers,
> all using DS and avoiding Service Trackers?
>
> The real use-case in case there is a completely different way to approach my
> problem is this. I have multiple bundle versions (A1.0, A1.2, A2.0, A3.0)
> each with a different XML file inside. The bundles expose a service whose job
> is just to return that XML resource. The trick is that our system can have
> multiple hardware devices connected, and only after a new device is connected
> and I query the device for its version, I can know which XML resource (or
> more specifically, which service version) I will need to use. So as you can
> see, I cannot at startup have a service injected and use that one for every
> device.
>
> Any suggestions are appreciated
>
> Thank you,
>
> Alejandro Endo | Software Designer/Concepteur de logiciels
> DISCLAIMER: Privileged and/or Confidential information may be contained in
> this message. If you are not the addressee of this message, you may not copy,
> use or deliver this message to anyone. In such event, you should destroy the
> message and kindly notify the sender by reply e-mail. It is understood that
> opinions or conclusions that do not relate to the official business of the
> company are neither given nor endorsed by the company. Thank You.
>
> _______________________________________________
> OSGi Developer Mail List
> [email protected]
> https://mail.osgi.org/mailman/listinfo/osgi-dev
_______________________________________________
OSGi Developer Mail List
[email protected]
https://mail.osgi.org/mailman/listinfo/osgi-dev