2

I have two osgi service which implements the same interface with a different quality-of-service. One has a default ranking of 0 and the other one has a ranking of 3.

I am searching for a blueprint configuration where the default service acts as a fallback. So every other bundle should use the best available service (highest ranking) and must fallback to the default one if the better service disappears.

That is working right now.

The missing part is to automatically reconnect to the better service, when it comes online again. Is there a way to do it by configuring just the services without changing the consumers (implement ServiceTrackers an so on)?

Guido Zockoll
  • 141
  • 3
  • 11

2 Answers2

1

Declarative Services supports this with the greedy policy option. I don't know that it is possible in Blueprint.

BJ Hargrave
  • 9,324
  • 1
  • 19
  • 27
0

I think this is not directly possible as a simple blueprint <reference>.

You can use the <reference-listener> element though.

 <reference-listener bind-method=”bind” unbind-method=”unbind”>
   <bean class=“MyListenerClass”/>        
  </reference-listener>

It allows to be called back when references change and react on these. So you can for example create a proxy for your service that makes sure the right service is called. This is not very pretty code though. So like BJ suggested declarative services may provide a cleaner solution for this case.

Christian Schneider
  • 19,420
  • 2
  • 39
  • 64
  • So the proxy should have ranking="5" ... but when the proxy dies i am having the same problem again :( And using DS means changing the consumers. Any way, thanks for clarification. – Guido Zockoll Sep 24 '14 at 14:52
  • Not exactly. What I meant is to listen to all services and select the highest ranking yourself. It is a bit more complicated than it should be but doable if you really need it. – Christian Schneider Sep 24 '14 at 17:10