[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [equinox-dev] Registering two services in the same bundle

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:

"(&(objectClass=Interface1)(objectClass=Interface2))"

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.

Tom



Inactive hide details for "David Conde" ---11/16/2009 02:34:18 AM---Hi,"David Conde" ---11/16/2009 02:34:18 AM---Hi,


From:

"David Conde" <dconde@xxxxxxxx>

To:

"'Equinox development mailing list'" <equinox-dev@xxxxxxxxxxx>

Date:

11/16/2009 02:34 AM

Subject:

[equinox-dev] Registering two services in the same bundle




Hi,

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@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/equinox-dev


GIF image

GIF image