Hi all,
My bundle declares an OSGi list, with a listener as follows
<osgi:list id="serviceList" cardinality="0..N" interface="com.foo.bar.MyService">
<osgi:listener ref="listener"
bind-method="registerService"
unbind-method="unregisterService" />
</osgi:list>
When this bundle is started with no existing instance of service of type com.foo.bar.MyService, the method unregisterService is called on my listener with null value for the service.
I have checked at gemini blueprint source code, and I have found that OsgiServiceCollection is calling listeners with null service reference in afterPropertiesSet method :
public void afterPropertiesSet() {
// create service proxies collection
this.services = createInternalDynamicStorage();
dependency = new DefaultOsgiServiceDependency(sourceName, filter, serviceRequiredAtStartup);
if (log.isTraceEnabled())
log.trace("Adding osgi listener for services matching [" + filter + "]");
OsgiListenerUtils.addServiceListener(context, listener, filter);
synchronized (lock) {
if (services.isEmpty()) {
OsgiServiceBindingUtils.callListenersUnbind(null, null, listeners);
}
}
}
I don't understand why this is done this way.
My problem is that in my bind and unbind method start with Preconditions on the service reference which should not be null... What is a listener supposed to do when unbinding a null reference?
Any help will be appreciated.
Best Regards.