有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java蓝图服务列表:等待所有服务

我正在使用Eclipse Virgo/Gemini Blueprint,并且有一个与多个实现的接口:

实施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方法是一个简单的方法,它迭代整个列表并打印出一个简单的字符串(用于测试)

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

有什么想法/建议吗?为什么

可以告诉virgo列表必须包含与MyInterface匹配的所有服务吗

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


共 (2) 个答案

  1. # 1 楼答案

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

  2. # 2 楼答案

    列表不包含与MyInterface匹配的所有服务。。。在某个任意的时刻。但随后出现了一项新的服务

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