Is it possible to bind a service to multiple consumers with iPOJO?
Domanda
In my iPOJO application i try to bind a service to two consumers:
Consumers:
@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");
}
}
Services:
@Component(immediate = true)
@Instantiate(name = "com.example.serviceX")
@Provides(specifications = { MyService.class, MyServiceX.class})
public class MyServiceX{
...
}
If I start consumerA, consumerB and serviceA, the service binds only to consumerA. If I start consumerB and serviceA, the service binds to consumerB.
Is it possible to let the services bind to both consumers? Is there an annotation for it?
Thanks.
Soluzione
It is definitely possible for a service to be used by several consumers. Your code looks good, and so it should work.
Did you try to check the current state using the 'instances' command (http://felix.apache.org/site/ipojo-arch-command.html) ?
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow