Class OsgiServiceUtil

  • All Implemented Interfaces:
    Stoppable

    public class OsgiServiceUtil
    extends Object
    implements Stoppable
    Utilities for dealing with OSGi environments
    • Constructor Detail

      • OsgiServiceUtil

        public OsgiServiceUtil​(org.osgi.framework.BundleContext context)
    • Method Detail

      • getServiceImpls

        public <T> T[] getServiceImpls​(Class<T> contract)
        Locate all implementors of the given service contract in the given OSGi buindle context. Utilizes ServiceTracker (best practice, automatically handles a lot of boilerplate and error conditions).
        Type Parameters:
        T - The Java type of the service to locate
        Parameters:
        contract - The service contract for which to locate implementors
        Returns:
        All know implementors
      • getServiceImpl

        public <T> T getServiceImpl​(Class<T> contract)
        Locate the single implementor of the given service contract in the given OSGi buindle context. Utilizes ServiceTracker.waitForService(long)
        Type Parameters:
        T - The Java type of the service to locate
        Parameters:
        contract - The service contract for which to locate implementors
        Returns:
        All know implementors
      • stop

        public void stop()
        Description copied from interface: Stoppable
        Stop phase notification
        Specified by:
        stop in interface Stoppable