Class OSGiLocator


  • public final class OSGiLocator
    extends Object
    Maintains a mapping of service names to an ordered set of service providers when running in an OSGi container.
    It is expected that a bundle using Drools will populate this map with properties from its own ClassLoader.
    This is an adaptation of the technique described by Guillaume Nodet in his article Java EE specs in OSGi. The main changes were to add comments. see http://gnodet.blogspot.com/2008/05/jee-specs-in-osgi.html
    • Method Detail

      • unregister

        public static void unregister​(String serviceName,
                                      Callable<Class<?>> factory)
        Removes the given service provider factory from the set of providers for the service.
        Parameters:
        serviceName - The fully qualified name of the service interface.
        factory - A factory for creating a specific type of service provider. May be null in which case this method does nothing.
        Throws:
        IllegalArgumentException - if serviceName is null
      • register

        public static void register​(String serviceName,
                                    Callable<Class<?>> factory)
        Adds the given service provider factory to the set of providers for the service.
        Parameters:
        serviceName - The fully qualified name of the service interface.
        factory - A factory for creating a specific type of service provider. May be null in which case this method does nothing.
        Throws:
        IllegalArgumentException - if serviceName is null
      • locate

        public static Class<?> locate​(String serviceName)
        Finds the preferred provider for the given service. The preferred provider is the last one added to the set of providers.
        Parameters:
        serviceName - The fully qualified name of the service interface.
        Returns:
        The last provider added for the service if any exists. Otherwise, it returns null.
        Throws:
        IllegalArgumentException - if serviceName is null
      • locateAll

        public static List<Class<?>> locateAll​(String serviceName)
        Finds all providers for the given service.
        Parameters:
        serviceName - The fully qualified name of the service interface.
        Returns:
        The ordered set of providers for the service if any exists. Otherwise, it returns an empty list.
        Throws:
        IllegalArgumentException - if serviceName is null