Bind order of OSGi declarative services

时光总嘲笑我的痴心妄想 提交于 2019-12-07 17:40:46

问题


Assuming I use OSGi Declarative Services and I have a service that have a number references with policy = dynamic...

A - Mandatory unary.

B - Mandatory unary.

C - Mandatory multiple.

D - Optional unary.

E - Optional multiple.

All references are available when my service starts. Is there any way to control what order bind is called in?

I'd like to have B bind first and do something to each E that comes in, but I have no way of ensuring that B is bound before E.

Yes, the more logical approach would be to let the service that represents B also bind to E and do whatever it should do, but I can't modify B, I can only use it. If I make a new service that just binds to B and E I'll have the same problem still.

I could do whatever I need to do in the activate method when everything is bound, and then do it as additional (dynamic) E's are bound, but I was wondering if there is another way...


回答1:


Make reference B use the "static" policy, which ensures it will be bound before the activate method is invoked.

If reference E is declared as multiple/optional with the "dynamic" policy -- which is pretty much the only reasonable choice when you have a multiple reference -- then it will be bound/unbound whenever the services are published/unpublished. This can happen from any thread, and can even happen (multiple times!) during the invocation of the activate method.



来源:https://stackoverflow.com/questions/17575679/bind-order-of-osgi-declarative-services

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!