【问题标题】:Blueprint List of Services: Wait for all services服务蓝图列表:等待所有服务
【发布时间】:2013-01-22 16:10:17
【问题描述】:

我正在使用 Eclipse Virgo/Gemini 蓝图,并且有一个包含多个实现的接口:

实施 1:

<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd">

<bean id="MyID1"
    class="ImplementationCLass1">
</bean>

<service ref="MyID1"
    interface="MyInterface" />

实施 2:

<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd">

<bean id="MYID2"
    class="ImplementationClass2">
</bean>

<service ref="MYID2"
    interface="MyInterface" />

实施 3:

<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd">

<bean id="MyID3"
    class="ImplementationClass3">
</bean>

<service ref="MyID3"
    interface="MyInterface" />

还有一个客户:

<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd">

<reference-list id="MyImplementations"
    interface="MyInterface" />

<bean id="clientID" class="ClientClass"
    init-method="startUp">

    <property name="services" ref="MyImplementations"></property>

</bean>

startUp 方法是一个简单的方法,它遍历整个列表并打印出一个简单的字符串(用于测试目的)

问题是,如果我安装客户端捆绑包,我的列表中只有两个树服务。 如果我停止并再次启动 Bundle,所有三个服务都在我的列表中。

任何想法/建议为什么?

是否可以告诉 virgo 列表必须包含所有匹配 MyInterface 的服务?

如果您需要更多信息,请随时询问

【问题讨论】:

    标签: java spring osgi eclipse-virgo blueprint-osgi


    【解决方案1】:

    参考列表的内容是动态的,随着匹配服务的出现和消失,项目将被添加和删除。但是您可以实现一个引用侦听器,当列表更改时通知该侦听器以跟踪可用服务。 Se discussion and examples here.

    【讨论】:

    • 谢谢,我试试看
    【解决方案2】:

    列表确实包含在任意时刻匹配MyInterface...的所有服务。但随后出现了一项新服务。

    真的,“所有服务”这个概念毫无意义。您永远无法真正知道您是否拥有所有服务,因为以后总能有人发布新服务。您能做的最好的事情是获取当前服务的快照,然后随着新服务的出现而动态调整。

    【讨论】:

    • 是的,这似乎总结了它。我忘了提到我将所有捆绑包部署在一个 par 文件中,因此我无法控制何时启动实现和客户端
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-12-21
    • 1970-01-01
    • 2020-09-27
    • 2017-03-31
    • 2015-05-12
    • 2020-06-16
    • 2022-11-06
    相关资源
    最近更新 更多