Class ServiceAccess


  • public final class ServiceAccess
    extends Object
    Utility methods to get public OSGi services or service suppliers.
    See Also:
    ServiceSupplier, AbstractServiceAwareModule
    Restriction:
    This class is not intended to be sub-classed by clients.
    Restriction:
    This class is not intended to be instantiated by clients.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static <T> T get​(Class<T> serviceType)
      Returns an instance of the single known service for the given type.
      static <T> T get​(Class<T> serviceType, String key, String value)
      Returns an instance of the single known service for the given type and the given property.
      static <T> T get​(Class<T> serviceType, Map<String,​?> properties)
      Returns an instance of the single known service for the given type and the given properties map.
      static <T> ServiceSupplier<T> supplier​(Class<T> serviceType, Class<?> source)
      Returns supplier of an instance of the single known service for the given type.
      static <T> ServiceSupplier<T> supplier​(Class<T> serviceType, Class<?> source, String key, Object value)
      Returns supplier of an instance of the single known service for the given type and the given property.
      static <T> ServiceSupplier<T> supplier​(Class<T> serviceType, Class<?> source, Map<String,​?> properties)
      Returns supplier of an instance of the single known service for the given type and the given properties map.
      static <T> ServiceSupplier<T> supplier​(Class<T> serviceType, org.eclipse.core.runtime.Plugin bundle)
      Returns supplier of an instance of the single known service for the given type.
      static <T> ServiceSupplier<T> supplier​(Class<T> serviceType, org.eclipse.core.runtime.Plugin bundle, String key, Object value)
      Returns supplier of an instance of the single known service for the given type and the given property.
      static <T> ServiceSupplier<T> supplier​(Class<T> serviceType, org.eclipse.core.runtime.Plugin bundle, Map<String,​?> properties)
      Returns supplier of an instance of the single known service for the given type and the given properties map.
      static <T> ServiceSupplier<T> supplier​(Class<T> serviceType, org.osgi.framework.BundleContext context)
      Returns supplier of an instance of the single known service for the given type.
      static <T> ServiceSupplier<T> supplier​(Class<T> serviceType, org.osgi.framework.BundleContext context, String key, Object value)
      Returns supplier of an instance of the single known service for the given type and the given property.
      static <T> ServiceSupplier<T> supplier​(Class<T> serviceType, org.osgi.framework.BundleContext context, Map<String,​?> properties)
      Returns supplier of an instance of the single known service for the given type and the given properties map.
    • Method Detail

      • get

        public static <T> T get​(Class<T> serviceType)
        Returns an instance of the single known service for the given type. Clients should always use supplier(...) methods instead of this if possible, cause it is faster on multiple service methods usage.

        Note, that caller should not hold reference to this service, cause it could become stale, and should always get actual service instance.

        Parameters:
        serviceType - the type of service to get, cannot be null
        Returns:
        an instance of the single known service for the given type, never null
        Throws:
        ServiceUnavailableException - if there is no such service available
      • get

        public static <T> T get​(Class<T> serviceType,
                                String key,
                                String value)
        Returns an instance of the single known service for the given type and the given property. Clients should always use supplier(...) methods instead of this if possible, cause it is faster on multiple service methods usage.

        Note, that caller should not hold reference to this service, cause it could become stale, and should always get actual service instance.

        Parameters:
        serviceType - the type of service to get, cannot be null
        key - the property key, cannot be null
        value - the property value, cannot be null
        Returns:
        an instance of the single known service for the given type, never null
        Throws:
        ServiceUnavailableException - if there is no such service available
      • get

        public static <T> T get​(Class<T> serviceType,
                                Map<String,​?> properties)
        Returns an instance of the single known service for the given type and the given properties map. Clients should always use supplier(...) methods instead of this if possible, cause it is faster on multiple service methods usage.

        Note, that caller should not hold reference to this service, cause it could become stale, and should always get actual service instance.

        Parameters:
        serviceType - the type of service to get, cannot be null
        properties - the service properties map, cannot be null
        Returns:
        an instance of the single known service for the given type, never null
        Throws:
        ServiceUnavailableException - if there is no such service available or multiple services of the serviceType and properties are registered
      • supplier

        public static <T> ServiceSupplier<T> supplier​(Class<T> serviceType,
                                                      Class<?> source)
        Returns supplier of an instance of the single known service for the given type.

        Note, that caller should not hold reference to the supplied service, cause it could become stale, and should always get actual service instance.

        Parameters:
        serviceType - the type of service to get, cannot be null
        source - the caller source class, typically the class of the caller, cannot be null
        Returns:
        supplier of an instance of the single known service for the given type, never null
        See Also:
        ServiceSupplier
      • supplier

        public static <T> ServiceSupplier<T> supplier​(Class<T> serviceType,
                                                      Class<?> source,
                                                      String key,
                                                      Object value)
        Returns supplier of an instance of the single known service for the given type and the given property.

        Note, that caller should not hold reference to the supplied service, cause it could become stale, and should always get actual service instance.

        Parameters:
        serviceType - the type of service to get, cannot be null
        source - the caller source class, typically the class of the caller, cannot be null
        key - the property key, cannot be null
        value - the property value, cannot be null
        Returns:
        supplier of an instance of the single known service for the given type, never null
        See Also:
        ServiceSupplier
      • supplier

        public static <T> ServiceSupplier<T> supplier​(Class<T> serviceType,
                                                      Class<?> source,
                                                      Map<String,​?> properties)
        Returns supplier of an instance of the single known service for the given type and the given properties map.

        Note, that caller should not hold reference to the supplied service, cause it could become stale, and should always get actual service instance.

        Parameters:
        serviceType - the type of service to get, cannot be null
        source - the caller source class, typically the class of the caller, cannot be null
        properties - the service properties map, cannot be null
        Returns:
        supplier of an instance of the single known service for the given type, never null
        See Also:
        ServiceSupplier
      • supplier

        public static <T> ServiceSupplier<T> supplier​(Class<T> serviceType,
                                                      org.osgi.framework.BundleContext context)
        Returns supplier of an instance of the single known service for the given type.

        Note, that caller should not hold reference to the supplied service, cause it could become stale, and should always get actual service instance.

        Parameters:
        serviceType - the type of service to get, cannot be null
        context - the caller bundle context to get service, cannot be null
        Returns:
        supplier of an instance of the single known service for the given type, never null
        See Also:
        ServiceSupplier
      • supplier

        public static <T> ServiceSupplier<T> supplier​(Class<T> serviceType,
                                                      org.osgi.framework.BundleContext context,
                                                      String key,
                                                      Object value)
        Returns supplier of an instance of the single known service for the given type and the given property.

        Note, that caller should not hold reference to the supplied service, cause it could become stale, and should always get actual service instance.

        Parameters:
        serviceType - the type of service to get, cannot be null
        context - the caller bundle context to get service, cannot be null
        key - the property key, cannot be null
        value - the property value, cannot be null
        Returns:
        supplier of an instance of the single known service for the given type, never null
        See Also:
        ServiceSupplier
      • supplier

        public static <T> ServiceSupplier<T> supplier​(Class<T> serviceType,
                                                      org.osgi.framework.BundleContext context,
                                                      Map<String,​?> properties)
        Returns supplier of an instance of the single known service for the given type and the given properties map.

        Note, that caller should not hold reference to the supplied service, cause it could become stale, and should always get actual service instance.

        Parameters:
        serviceType - the type of service to get, cannot be null
        context - the caller bundle context to get service, cannot be null
        properties - the service properties map, cannot be null
        Returns:
        supplier of an instance of the single known service for the given type, never null
        See Also:
        ServiceSupplier
      • supplier

        public static <T> ServiceSupplier<T> supplier​(Class<T> serviceType,
                                                      org.eclipse.core.runtime.Plugin bundle)
        Returns supplier of an instance of the single known service for the given type.

        Note, that caller should not hold reference to the supplied service, cause it could become stale, and should always get actual service instance.

        Parameters:
        serviceType - the type of service to get, cannot be null
        bundle - the caller bundle to get service, cannot be null
        Returns:
        supplier of an instance of the single known service for the given type, never null
        See Also:
        ServiceSupplier
      • supplier

        public static <T> ServiceSupplier<T> supplier​(Class<T> serviceType,
                                                      org.eclipse.core.runtime.Plugin bundle,
                                                      String key,
                                                      Object value)
        Returns supplier of an instance of the single known service for the given type and the given property.

        Note, that caller should not hold reference to the supplied service, cause it could become stale, and should always get actual service instance.

        Parameters:
        serviceType - the type of service to get, cannot be null
        bundle - the caller bundle to get service, cannot be null
        key - the property key, cannot be null
        value - the property value, cannot be null
        Returns:
        supplier of an instance of the single known service for the given type, never null
        See Also:
        ServiceSupplier
      • supplier

        public static <T> ServiceSupplier<T> supplier​(Class<T> serviceType,
                                                      org.eclipse.core.runtime.Plugin bundle,
                                                      Map<String,​?> properties)
        Returns supplier of an instance of the single known service for the given type and the given properties map.

        Note, that caller should not hold reference to the supplied service, cause it could become stale, and should always get actual service instance.

        Parameters:
        serviceType - the type of service to get, cannot be null
        bundle - the caller bundle to get service, cannot be null
        properties - the service properties map, cannot be null
        Returns:
        supplier of an instance of the single known service for the given type, never null
        See Also:
        ServiceSupplier