Class ServiceUtils


  • public abstract class ServiceUtils
    extends Object
    Utility methods to get/unget services, ignoring exceptions that might occur on bundle stop/update
    • Constructor Detail

      • ServiceUtils

        public ServiceUtils()
    • Method Detail

      • safeGetService

        public static <T> T safeGetService​(org.osgi.framework.BundleContext ctx,
                                           org.osgi.framework.ServiceReference<T> ref)
        Get the service
        Returns:
        The service or null
      • safeUngetService

        public static <T> void safeUngetService​(org.osgi.framework.BundleContext ctx,
                                                org.osgi.framework.ServiceReference<T> ref)
        Unget the service
      • safeGetServiceObjects

        public static <T> T safeGetServiceObjects​(org.osgi.framework.BundleContext ctx,
                                                  org.osgi.framework.ServiceReference<T> ref)
        Get the service using ServiceObjects
        Returns:
        The service or null
      • safeUngetServiceObjects

        public static <T> void safeUngetServiceObjects​(org.osgi.framework.BundleContext ctx,
                                                       org.osgi.framework.ServiceReference<T> ref,
                                                       T service)
        Unget the service using ServiceObjects