【问题标题】:Is it possible to bind a service to multiple consumers with iPOJO?是否可以使用 iPOJO 将服务绑定到多个消费者?
【发布时间】:2012-04-23 09:30:09
【问题描述】:

在我的 iPOJO 应用程序中,我尝试将服务绑定到两个消费者:

消费者:

@Component(immediate = true)
@Instantiate(name = "com.example.consumerX")
@Provides
public class consumerX{
    @Requires(id="ms",optional=true)
    private MyService[] services;

    @Bind(id = "ms", aggregate = true, optional = true)
    public synchronized void register(MyService service) {
            System.out.println("service bind to consumer");
    }

    @Unbind(id = "ms")
    public synchronized void unregister(MyService service) {
            System.out.println("service unbind from consumer");
    }
}

服务:

@Component(immediate = true)
@Instantiate(name = "com.example.serviceX")
@Provides(specifications = { MyService.class, MyServiceX.class})
public class MyServiceX{
    ...
}

如果我启动consumerA、consumerB 和serviceA,服务只绑定到consumerA。如果我启动 consumerB 和 serviceA,服务将绑定到 consumerB。

是否可以让服务绑定到两个消费者?有注释吗?

谢谢。

【问题讨论】:

    标签: osgi ipojo


    【解决方案1】:

    一个服务绝对有可能被多个消费者使用。您的代码看起来不错,因此它应该可以工作。

    您是否尝试使用“实例”命令 (http://felix.apache.org/site/ipojo-arch-command.html) 检查当前状态?

    【讨论】:

    • 感谢您的回答。所有实例都是有效的,错误必须在其他地方。我试着找到它。
    猜你喜欢
    • 1970-01-01
    • 2012-07-16
    • 2019-07-12
    • 1970-01-01
    • 1970-01-01
    • 2021-08-18
    • 1970-01-01
    • 2011-09-14
    • 1970-01-01
    相关资源
    最近更新 更多