For those interested, I found this: http://wimpi.coalevo.net/2007/09/osgi-design-practice-loose-coupling.html

Executive Summary:

* Manager has an internal registry (hash with ids as keys)

* Handlers are added / removed from the registry by using a listener


Ittay


Ittay Dror wrote:

Hi,


I'd like to get some advice about design patterns in OSGi, I hope this is appropriate (not being felix specific).


I have a bunch of Handler objects and a Manager that retrieves them by id.


interface Manager {

   Handler get(String id);

}


The Manager implementation is an OSGi service that uses OSGi as the registry of Handlers. So internally, it finds a ServiceReference using a filter containing the id as a value to some property.


The question is how can it return the Handler? If it uses its own bundle context to retrieve the service reference, then it will look as if that bundle is using the service, which is not correct, also, there's a question of how the services are released.


I can rewrite the interface to be OSGi specific, but I don't like that because:

1. it means client code needs to know OSGi

2. it hurts unit testing the client code (with the above interface I can easily create a mock manager implementation)


So, any suggestions as to how to design this case?


Thank you,

Ittay

--
Tikal <http://www.tikalk.com>
Tikal Project <http://tikal.sourceforge.net>

--
Tikal <http://www.tikalk.com>
Tikal Project <http://tikal.sourceforge.net>

Reply via email to