Reputation: 1876
I'm building a caching system in my OSGI application where my initial thought was, ok when a service is registered I want to apply caching to, I just proxy that service and register the proxy with a very high service ranking.
This almost works, depending on in which order my bundles are started. If the consumer is started last everything works, and also if I stop the caching bundle the consumer is fallbacking to the original implementation BUT if I restart the caching bundle then the consumer doesn't get the proxy version of the service.
To make a simple example for proving this I made a simple bundle which registeres a know service by hand with a much higher ranking (ie. not creating proxies etc.) and the problem still remains, when the higher ranked service gets started the consumer still uses the lower ranked service.
Do the dynamism of blueprint only applies in certain circumstances?
Is there any way to get the behavior of 1 and 2 also on the 3:d case?
Or is there a better way to accomplish what I'm trying to do? Ie. with HookEvent or similar?
Thanks
EDIT: I solved this particular problem by updating used bundles after proxy registration, that seems to update the service wirings.
Bundle[] usingBundles = reference.getUsingBundles();
for(.....)
{
b.update();
}
Upvotes: 0
Views: 199
Reputation: 5285
Well, the service ranking is only valid for the time looking for a service. That said you probably need some other way of informing your consuming bundle that the service you're looking for is back again with the caching functionalities. You could try to fire special events when registering your specialized proxy service and consume those in your service-consumer bundle. If those events are seen do a "re-binding" to the favored service. Though all this would probably need more than just a blueprint xml.
Upvotes: 1