OSGi:当某个服务可用时,DS 服务消费者是否会得到同步通知

OSGi: Do DS-service consumers get notified synchronously when a certain service become available

我有一个 IFoo 接口的 DS 服务消费者:

@Component
public class IFooListener {

    @Reference(bind = "bind",
               unbind = "unbind",
               referenceInterface = IFoo.class,
               cardinality = ReferenceCardinality.OPTIONAL_MULTIPLE,
               policy = ReferencePolicy.DYNAMIC)
    public static final Map<String, IFoo> allServices = new ConcurrentHashMap<>();

    protected void bind(IFoo service, Map<String, String> properties) {
    ....
    }
    ....
}

我已经注册了 IFoo 服务:

BundleContext ctx = FrameworkUtil.getBundle(IFooListener.class).getBundleContext();
Properties properties = new Properties();
....
ServiceRegistration managementSrv = ctx.registerService(IFoo.class.getName(), iFooImpl, properties);

我想知道的是,是否保证在ctx.registerService(...)方法returns时,所有当时已经可用的DS消费者都会被通知IFoo 服务已注册? 这是 osgi-implementation 特定的东西吗?或者这是DS规范的一部分?

我在规范中找不到确切的答案。不过我刚刚查看了Felix SCR的代码,发现并没有开新线程。它实现了 ServiceListener 接口(因为它总是必须处于最深层次),幸运的是 ServiceListener 的 javadoc 说 addingService 是同步调用的。

简而言之:bind方法在Felix SCR中是同步调用的