4 Replies Latest reply on Oct 11, 2012 12:08 PM by Ryan Lunka

    Retrieving OSGi Services by Interface

    Ryan Lunka Level 3

      I may be trying something incorrect in OSGi terms, so if I am, please tell me.  I'm trying to create a generic "IPlugin" interface that will likely have multiple implementation classes, all as separate OSGi services.  In another service, PluginManager, I want to be able to retrieve all active instances of IPlugin (regardless of implementation class) so that I can loop through and call the one method on that interface for each one.  The goal is to set up a framework wherby I can just add/remove services that implement IPlugin as I see fit and as requirements evolve.


      I'm struggling to figure out how to do this.  Should I be using the @Reference annotation somehow?  If not, should I be using the ComponentContext of PluginManager to retrieve the services manually somehow?  I feel like I'm missing something here.  I wondered if anyone had some advice or has implemented something like this before using Apache Felix.  Thanks in advance!



      I'm not doing this on a huge scale.  For the purpose of this discussion I used very generic class/interface names.  This is not something I'm trying to use as some central, global plugin controller for an entire app.  That would probably not be a good thing.  Just thought I'd throw that in there, in case anyone considered that a concern.