In general, it depends :-).
I assume you have two components A
and B
, and component A
needs to notify component B
of something, or, in other words, component B
is interested in something that happens in component A
.
One way for the components to cooperate is to use the EventAdmin
service; component A emits events for all possible cases, and component B has registered an EventHandler
with an appropriate filter for these events. Bonus: component A
can specify sync/async handler execution, and there may be multiple components that will be notified without any extra overhead. Both A
and B
need not be services or even objects, if the bundle activators handle all the wiring.
Another way is to use Declarative Services
: components A
and B
are objects, and you have defined an interface IB
that specifies the valid operations on B
, and which B
implements. A
is marked as needing at least one IB
, and the DS service will instantiate both and invoke methods on A with the proper IB references. A can then normally call methods of IB.
As a simplification of DS, you can use normal services: A isn't a service, but it finds instances of IB everytime it needs to invoke methods on IB.
Last but not least, there's the Blueprint Service
that can instantiate complex object graphs using dependency injection, including service proxies, which I have never used and don't feel that I can comment on...