Class ServiceUtils

java.lang.Object
io.openems.common.utils.ServiceUtils

public class ServiceUtils extends Object
  • Method Details

    • useService

      public static <T> ServiceUtils.CloseableService<T> useService(org.osgi.framework.BundleContext bundleContext, Class<T> clazz)
      Creates a ServiceUtils.CloseableService with the given parameters.

      Usage:

       try (var componentManagerService = ServiceUtils.useService(bundleContext, ComponentManager.class)) {
              var componentManager = componentManagerService.getService();
              // use componentManager here (may be null) ...
       } catch (Exception e) {
       }
       
      Type Parameters:
      T - the type of the service
      Parameters:
      bundleContext - the BundleContext of the service
      clazz - the class type of the service
      Returns:
      the ServiceUtils.CloseableService
    • useService

      public static <T> ServiceUtils.CloseableService<T> useService(org.osgi.framework.BundleContext bundleContext, Class<T> clazz, String filter) throws org.osgi.framework.InvalidSyntaxException
      Creates a ServiceUtils.CloseableService with the given parameters.

      Usage:

       try (var componentManagerService = ServiceUtils.useService(bundleContext, ComponentManager.class)) {
              var componentManager = componentManagerService.getService();
              // use componentManager here (may be null) ...
       } catch (Exception e) {
       }
       
      Type Parameters:
      T - the type of the service
      Parameters:
      bundleContext - the BundleContext of the service
      clazz - the class type of the service
      filter - the filter expression or null for any service
      Returns:
      the ServiceUtils.CloseableService
      Throws:
      org.osgi.framework.InvalidSyntaxException - If the specified filter contains an invalid filter expression that cannot be parsed.