use of org.osgi.service.cm.ConfigurationException in project aries by apache.
the class ManagedServiceFactoryImpl method getJdbcProps.
@SuppressWarnings("unchecked")
private Properties getJdbcProps(String pid, Map<String, Object> properties) throws ConfigurationException {
Object object = properties.getOrDefault(JDBC_PROP_NAMES, JDBC_PROPERTIES);
Collection<String> propnames;
if (object instanceof String) {
propnames = Arrays.asList(((String) object).split(","));
} else if (object instanceof String[]) {
propnames = Arrays.asList((String[]) object);
} else if (object instanceof Collection) {
propnames = (Collection<String>) object;
} else {
LOG.error("The configuration {} contained an invalid list of JDBC property names", pid, object);
throw new ConfigurationException(JDBC_PROP_NAMES, "The jdbc property names must be a String+ or comma-separated String");
}
Properties p = new Properties();
propnames.stream().filter(properties::containsKey).forEach(s -> p.setProperty(s, String.valueOf(properties.get(s))));
return p;
}
use of org.osgi.service.cm.ConfigurationException in project aries by apache.
the class ConfigurationDefinedResourceFactory method updated.
@Override
public void updated(String pid, Dictionary<String, ?> properties) throws ConfigurationException {
Map<String, Object> propsMap = new HashMap<>();
Enumeration<String> keys = properties.keys();
while (keys.hasMoreElements()) {
String key = keys.nextElement();
propsMap.put(key, properties.get(key));
}
try {
LifecycleAware existing = managedInstances.get(pid);
LifecycleAware cdr;
if (existing != null) {
if (existing.update(propsMap)) {
LOG.debug("The Configuration driven resource with pid {} updated successfully", pid);
return;
}
closeCDR(pid, existing);
cdr = getConfigurationDrivenResource(context, pid, propsMap);
if (!managedInstances.replace(pid, existing, cdr)) {
// We lost this race
return;
}
} else {
cdr = getConfigurationDrivenResource(context, pid, propsMap);
if (managedInstances.putIfAbsent(pid, cdr) != null) {
// We lost this race
return;
}
}
cdr.start();
} catch (Exception e) {
LOG.error("The configuration driven resource for pid {} encountered a failure", pid, e);
if (e instanceof ConfigurationException) {
throw (ConfigurationException) e;
} else {
throw new ConfigurationException(null, "A failure occured configuring the resource for pid " + pid, e);
}
}
}
use of org.osgi.service.cm.ConfigurationException in project aries by apache.
the class AbstractJPAManagedServiceFactory method getJdbcProps.
@SuppressWarnings("unchecked")
private Properties getJdbcProps(String pid, Map<String, Object> properties) throws ConfigurationException {
Object object = properties.getOrDefault(JDBC_PROP_NAMES, JDBC_PROPERTIES);
Collection<String> propnames;
if (object instanceof String) {
propnames = Arrays.asList(((String) object).split(","));
} else if (object instanceof String[]) {
propnames = Arrays.asList((String[]) object);
} else if (object instanceof Collection) {
propnames = (Collection<String>) object;
} else {
LOG.error("The configuration {} contained an invalid list of JDBC property names", pid, object);
throw new ConfigurationException(JDBC_PROP_NAMES, "The jdbc property names must be a String+ or comma-separated String");
}
Properties p = new Properties();
propnames.stream().filter(properties::containsKey).forEach(s -> p.setProperty(s, String.valueOf(properties.get(s))));
return p;
}
use of org.osgi.service.cm.ConfigurationException in project aries by apache.
the class ManagedServiceFactoryImpl method getJdbcProps.
@SuppressWarnings("unchecked")
private Properties getJdbcProps(String pid, Map<String, Object> properties) throws ConfigurationException {
Object object = properties.getOrDefault(JDBC_PROP_NAMES, JDBC_PROPERTIES);
Collection<String> propnames;
if (object instanceof String) {
propnames = Arrays.asList(((String) object).split(","));
} else if (object instanceof String[]) {
propnames = Arrays.asList((String[]) object);
} else if (object instanceof Collection) {
propnames = (Collection<String>) object;
} else {
LOG.error("The configuration {} contained an invalid list of JDBC property names", pid, object);
throw new ConfigurationException(JDBC_PROP_NAMES, "The jdbc property names must be a String+ or comma-separated String");
}
Properties p = new Properties();
propnames.stream().filter(properties::containsKey).forEach(s -> p.setProperty(s, String.valueOf(properties.get(s))));
return p;
}
use of org.osgi.service.cm.ConfigurationException in project sling by apache.
the class DefaultThreadPoolManager method updated.
/**
* @see org.osgi.service.cm.ManagedServiceFactory#updated(java.lang.String, java.util.Dictionary)
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
public void updated(String pid, Dictionary properties) throws ConfigurationException {
final String name = (String) properties.get(ModifiableThreadPoolConfig.PROPERTY_NAME);
if (name == null || name.length() == 0) {
throw new ConfigurationException(ModifiableThreadPoolConfig.PROPERTY_NAME, "Property is missing or empty.");
}
this.logger.debug("Updating {} with {}", pid, properties);
Entry createdEntry = null;
synchronized (this.pools) {
final ThreadPoolConfig config = this.createConfig(properties);
Entry foundEntry = null;
// we have to search the config by using the pid first!
for (final Entry entry : this.pools.values()) {
if (pid.equals(entry.getPid())) {
foundEntry = entry;
break;
}
}
// if we haven't found it by pid we search by name
if (foundEntry == null) {
for (final Entry entry : this.pools.values()) {
if (name.equals(entry.getName())) {
foundEntry = entry;
break;
}
}
}
if (foundEntry != null) {
// if the name changed - we have to reregister(!)
if (!name.equals(foundEntry.getName())) {
this.pools.remove(foundEntry.getName());
this.pools.put(name, foundEntry);
}
// update
foundEntry.update(config, name, pid);
} else {
// create
createdEntry = new Entry(pid, config, name, bundleContext);
this.pools.put(name, createdEntry);
}
}
if (createdEntry != null) {
createdEntry.registerMBean();
}
}
Aggregations