OSGi声明式服务的绑定顺序 [英] Bind order of OSGi declarative services
问题描述
假设我使用OSGi声明式服务,并且我有一个服务,该服务的数字引用的策略为dynamic ...
Assuming I use OSGi Declarative Services and I have a service that have a number references with policy = dynamic...
A-强制性一元制。
B-强制一元。
C-强制倍数。
D-可选一元。
E-可选倍数。
在我的服务启动时,所有引用均可用。
有什么方法可以控制调用绑定的顺序吗?
All references are available when my service starts. Is there any way to control what order bind is called in?
我想让B首先绑定并对每个传入的E进行操作,但我无法确保B在E之前绑定。
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.
是的,更合理的方法是让代表B的服务也绑定到E上,做它应该做的一切,但我不能修改B,只能使用它。如果我提供一个仅绑定到B和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.
我可以在激活方法中做任何事情一切都绑定了,然后像附加的(动态)E绑定了一样,但是我想知道是否还有另一种方法...
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...
推荐答案
使引用B使用静态策略,以确保在调用activate方法之前将其绑定。
Make reference B use the "static" policy, which ensures it will be bound before the activate method is invoked.
如果引用E被声明为Multiple / 动态策略是可选的-当您有多个引用时,这几乎是唯一合理的选择-然后,只要服务已发布/未发布,它将被绑定/取消绑定。这可以从任何线程发生,甚至可以在调用activate方法期间发生(多次!)。
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.
这篇关于OSGi声明式服务的绑定顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!