Class OsgiServiceUtil

  • All Implemented Interfaces:
    Stoppable

    public class OsgiServiceUtil
    extends java.lang.Object
    implements Stoppable
    Utilities for dealing with OSGi environments
    • Constructor Summary

      Constructors 
      Constructor Description
      OsgiServiceUtil​(org.osgi.framework.BundleContext context)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      <T> T getServiceImpl​(java.lang.Class<T> contract)
      Locate the single implementor of the given service contract in the given OSGi buindle context.
      <T> T[] getServiceImpls​(java.lang.Class<T> contract)
      Locate all implementors of the given service contract in the given OSGi buindle context.
      void stop()
      Stop phase notification
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • OsgiServiceUtil

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

      • getServiceImpls

        public <T> T[] getServiceImpls​(java.lang.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​(java.lang.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