- private void possiblyAddConfigModuleIdentifier(ServiceReference<?> reference,
- List<Entry<String, ModuleIdentifier>> configModules) {
- Object moduleNamespace = reference.getProperty(CONFIG_MODULE_NAMESPACE_PROP);
- if(moduleNamespace == null) {
- return;
- }
-
- String moduleName = getRequiredConfigModuleProperty(CONFIG_MODULE_NAME_PROP, moduleNamespace,
- reference);
- String instanceName = getRequiredConfigModuleProperty(CONFIG_INSTANCE_NAME_PROP, moduleNamespace,
- reference);
- if(moduleName == null || instanceName == null) {
- return;
- }
-
- LOG.debug("Found service with config module: namespace {}, module name {}, instance {}",
- moduleNamespace, moduleName, instanceName);
-
- configModules.add(new SimpleEntry<>(moduleNamespace.toString(),
- new ModuleIdentifier(moduleName, instanceName)));
- }
-
- @Nullable
- private String getRequiredConfigModuleProperty(String propName, Object moduleNamespace,
- ServiceReference<?> reference) {
- Object value = reference.getProperty(propName);
- if(value == null) {
- LOG.warn("OSGi service with {} property is missing property {} therefore the config module can't be restarted",
- CONFIG_MODULE_NAMESPACE_PROP, propName);
- return null;
- }
-
- return value.toString();
- }
-
- private ServiceRegistration<?> registerEventHandler(BundleContext bundleContext, EventHandler handler) {
- Dictionary<String, Object> props = new Hashtable<>();
- props.put(org.osgi.service.event.EventConstants.EVENT_TOPIC,
- new String[]{EventConstants.TOPIC_CREATED, EventConstants.TOPIC_FAILURE});
- return bundleContext.registerService(EventHandler.class.getName(), handler, props);