Search code examples
javaosgideclarative-services

How to let a consumer select specific 3party provider


What could be a good osgi implementation of the scenario below ?

I have a general algorithm which is divided in multiple modules. The idea is that each module could be extended by third party with specific configuration needs. My main algorithm is configured by a user mainly to select which module to include. As this configuration file could be difficult to write, I want to create a workbench that help him to do that.

My first idea was to consider my main algorithm as a consumer of multiple module providers using DS. The use case is: the user configure the main algorithm and the submodules he want to use; then when he runs the algorithm I want that the workbench creates the main algorithm service with the good configuration. But if I understand, services in osgi are designed to be provider independent. Does services are useful in my case?


Solution

  • Doing what you want they way you just described will cause you much heartache and issues. Instead I'd suggest you use a more hands-on approach:

    • Define interfaces in your bundles that define the ways that your algorithm can be extended
    • Use the service layer of OSGi to collect the implementations of the interfaces (DS can help you here)
    • Have a configuration class/object that defines which of the above are selected/activated for a specific instance
    • When you algorithm is executed, look up the necessary services from the service layer and use them.

    Also, if you are going to have a full workbench, you could directly use extensions and extension points that help coordinate a bit.