|Re: [equinox-dev] Registering two services in the same bundle|
Thank you for your answer,
So once I get ServiceReference = X getServiceReferences using the filter that you told me "(&(objectClass=Interface1)(objectClass=Interface2))", I have to use two castings for getting two different services like Object1 = (Interface1) BundleContext.getReference (X) and Object2= (Interface2) BundleContext.getReference(X), and then use two instances of the same object for using two different interfaces implemented by this same object, am I right? Is there any other mechanism for using the same object for two different interfaces, because really the object provides two different services (2 different interfaces)
Thank you in advance
You can use the registerService(java.lang.String clazzes,java.lang.Object service, java.util.Dictionary properties) to register your service object under multiple service interfaces. This will allow you to control the registration with a single ServiceRegistration object. But in order to get a ServiceReference that is guaranteed to implement both service interfaces then you must use the getServiceReferences(String clazz, String filter) with a null clazz and a filter that looks something like this:
This will ensure that the ServiceReference objects returned implement both Interface1 and Interface2. This should allow you to cast the Object returned from getService(ServiceReference) to both Interface1 and Interface2 in your service using client bundle. But for client code I recommend you use an injection mechanism (like Declarative Services, Spring DM or Blueprint) if possible so you don't have to worry about tracking the services yourself.
"David Conde" ---11/16/2009 02:34:18 AM---Hi,
"David Conde" <dconde@xxxxxxxx>
"'Equinox development mailing list'" <equinox-dev@xxxxxxxxxxx>
11/16/2009 02:34 AM
[equinox-dev] Registering two services in the same bundle
I would like to know what I have to do for registering two different services in a same bundle. I mean, I have two create a service object which implements two different interfaces (registering two different services). I thought about using registerService(java.lang.String clazzes,java.lang.Object service,
java.util.Dictionary properties) by including Interface1.class.getName() and Interface2.class.getName() in String array called clazzes.
However, I found as a problem that if I want to use this object service I have to get two service objects, one for Interface1 and another one for Interface2 by doing BundleContext.getServiceReference(Interface1) & BundleContext.getServiceReference(Interface2), am I missing anything?Does it exist another way to do that?
Thanks in advance _______________________________________________
equinox-dev mailing list
equinox-dev mailing list