use of org.osgi.service.cm.ManagedServiceFactory in project felix by apache.
the class ManagedServiceFactoryTracker method provideConfiguration.
@Override
public void provideConfiguration(ServiceReference<ManagedServiceFactory> reference, TargetedPID configPid, TargetedPID factoryPid, Dictionary<String, ?> properties, long revision, ConfigurationMap<?> configs) {
// Get the ManagedServiceFactory and terminate here if already
// unregistered from the framework concurrently
ManagedServiceFactory service = getRealService(reference);
if (service == null) {
return;
}
// already unregistered this service concurrently
if (configs == null) {
configs = this.getService(reference);
if (configs == null) {
return;
}
}
if (configs.shallTake(configPid, factoryPid, revision)) {
try {
Dictionary props = getProperties(properties, reference, configPid.toString(), factoryPid.toString());
updated(reference, service, configPid.toString(), props);
configs.record(configPid, factoryPid, revision);
} catch (Throwable t) {
this.handleCallBackError(t, reference, configPid);
} finally {
this.ungetRealService(reference);
}
}
}
use of org.osgi.service.cm.ManagedServiceFactory in project felix by apache.
the class ManagedServiceFactoryTracker method removeConfiguration.
@Override
public void removeConfiguration(ServiceReference<ManagedServiceFactory> reference, TargetedPID configPid, TargetedPID factoryPid) {
final ManagedServiceFactory service = this.getRealService(reference);
final ConfigurationMap configs = this.getService(reference);
if (service != null && configs != null) {
if (configs.removeConfiguration(configPid, factoryPid)) {
try {
deleted(reference, service, configPid.toString());
configs.record(configPid, factoryPid, -1);
} catch (Throwable t) {
this.handleCallBackError(t, reference, configPid);
} finally {
this.ungetRealService(reference);
}
}
}
}
use of org.osgi.service.cm.ManagedServiceFactory in project ddf by codice.
the class ConfigurationAdminImpl method listServices.
@Override
public List<Service> listServices(String serviceFactoryFilter, String serviceFilter) {
List<Service> serviceList = null;
List<Service> serviceFactoryList = null;
Map<Long, MetaTypeInformation> metaTypeInformationByBundle = new HashMap<>();
try {
// Get ManagedService instances
serviceList = getServices(ManagedService.class.getName(), serviceFilter, true);
Map<String, ObjectClassDefinition> configPidToOcdMap = getPidObjectClasses(metaTypeInformationByBundle);
// Get ManagedService Metatypes
List<Metatype> metatypeList = addMetaTypeNamesToMap(configPidToOcdMap, serviceFilter, SERVICE_PID);
// Get ManagedServiceFactory instances
serviceFactoryList = getServices(ManagedServiceFactory.class.getName(), serviceFactoryFilter, true);
// Get ManagedServiceFactory Metatypes
metatypeList.addAll(addMetaTypeNamesToMap(getFactoryPidObjectClasses(metaTypeInformationByBundle), serviceFactoryFilter, SERVICE_FACTORYPID));
for (Service service : serviceFactoryList) {
service.setFactory(true);
for (Metatype metatype : metatypeList) {
if (metatype.getId() != null && metatype.getId().equals(service.getId())) {
service.putAll(metatype);
}
}
Configuration[] configs = configurationAdmin.listConfigurations("(|(service.factoryPid=" + service.getId() + ")(service.factoryPid=" + service.getId() + "_disabled))");
if (configs != null) {
addConfigurationData(service, configs, configPidToOcdMap);
}
}
for (Service service : serviceList) {
service.setFactory(false);
for (Metatype metatype : metatypeList) {
if (metatype.getId() != null && metatype.getId().equals(service.getId())) {
service.putAll(metatype);
}
}
Configuration[] configs = configurationAdmin.listConfigurations("(" + SERVICE_PID + "=" + service.getId() + ")");
if (configs != null) {
addConfigurationData(service, configs, configPidToOcdMap);
}
}
serviceList.addAll(serviceFactoryList);
} catch (IOException e) {
LOGGER.warn("Unable to obtain list of Configuration objects from ConfigurationAdmin.", e);
} catch (InvalidSyntaxException e) {
LOGGER.info("Provided LDAP filter is incorrect: {}", LogSanitizer.sanitize(serviceFilter), e);
}
if (serviceList != null) {
return serviceList.stream().filter(service -> isPermittedToViewService(service.getId())).collect(Collectors.toList());
} else {
return new ArrayList<>();
}
}
Aggregations