If the service publisher imports the package with the advertised service type, then only bundles which either (a) import the same package or (b) do not import the package at all will normally see the service (unless they use getAllServiceReferences or the all option in ServiceTracker). This is to ensure type safety between the service publisher and service user.
 
A proxy bundle solution as used by ECF can help since the proxy bundle can import the proper version of the package for the service consumers is needs to support. This also allows the support for multiple versions of the package since each proxy bundle can be wired to a different version of the package.
 
The loadClass call in the code link you provide just ensures that the package becomes wired via DynamicImport-Package. At this point you then need to make sure any service objects returned by the ServiceFactory are instances of that loaded interface class since the framework will verify this on the object returned from ServiceFactory.getService.
 
 
--

BJ Hargrave
Senior Technical Staff Member, IBM // office: +1 386 848 1781
OSGi Fellow and CTO of the OSGi Alliance // mobile: +1 386 848 3788
hargr...@us.ibm.com
 
 
----- Original message -----
From: Christian Schneider <ch...@die-schneider.net>
Sent by: osgi-dev-boun...@mail.osgi.org
To: OSGi Developer Mail List <osgi-dev@mail.osgi.org>
Cc:
Subject: [osgi-dev] Creating a ServiceFactory without loading the interface class
Date: Mon, Mar 7, 2016 2:35 PM
 
I have a problem in the implementation of CXF DOSGi.

On the import side I create a ServiceFactory and publish it with the
name of the interface of the remote service.

The problem is that the ServiceFactory is not picked up by consumer
bundles unless I also load the interface class using the bundle that
exports the service:
https://github.com/apache/cxf-dosgi/blob/master/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/RemoteServiceAdminCore.java#L375
I think this causes the bundle to import the respective package. As for
example a ServiceTracker will only pick up the services with the correct
package this seems to do the trick.

The problem though is that I need Dynamic-Import: * to make this work
and I also can not create ServiceFactories for two services with the
same interface in different package versions in this way.

I already asked Peter and he said that it should not be necessary to
load the interface class. Does anyone know why it seems to be necessary
and if there is some way to avoid loading the class?
I also asked Scott Lewis (ECF) about it and he said that he thinks it
works in ECF but it may be related to him using a "proxy" bundles that
is different from the remote service admin bundle and the consumer
bundle. He does not remember in detail how it works though.

Christian

--
Christian Schneider
http://www.liquid-reality.de

Open Source Architect
http://www.talend.com

_______________________________________________
OSGi Developer Mail List
osgi-dev@mail.osgi.org
https://mail.osgi.org/mailman/listinfo/osgi-dev

 

_______________________________________________
OSGi Developer Mail List
osgi-dev@mail.osgi.org
https://mail.osgi.org/mailman/listinfo/osgi-dev

Reply via email to