Package io.openems.common.utils
Class ServiceUtils
java.lang.Object
io.openems.common.utils.ServiceUtils
-
Nested Class Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> ServiceUtils.CloseableService
<T> useService
(org.osgi.framework.BundleContext bundleContext, Class<T> clazz) Creates aServiceUtils.CloseableService
with the given parameters.static <T> ServiceUtils.CloseableService
<T> useService
(org.osgi.framework.BundleContext bundleContext, Class<T> clazz, String filter) Creates aServiceUtils.CloseableService
with the given parameters.
-
Method Details
-
useService
public static <T> ServiceUtils.CloseableService<T> useService(org.osgi.framework.BundleContext bundleContext, Class<T> clazz) Creates aServiceUtils.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
- theBundleContext
of the serviceclazz
- 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 aServiceUtils.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
- theBundleContext
of the serviceclazz
- the class type of the servicefilter
- 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.
-