在我的 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。
是否可以让服务绑定到两个消费者?有注释吗?
谢谢。