Search in sources :

Example 26 with ConfigurationException

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;
}
Also used : ConfigurationException(org.osgi.service.cm.ConfigurationException) Collection(java.util.Collection) Properties(java.util.Properties)

Example 27 with ConfigurationException

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);
        }
    }
}
Also used : ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ConfigurationException(org.osgi.service.cm.ConfigurationException) ConfigurationException(org.osgi.service.cm.ConfigurationException)

Example 28 with ConfigurationException

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;
}
Also used : ConfigurationException(org.osgi.service.cm.ConfigurationException) Collection(java.util.Collection) Properties(java.util.Properties)

Example 29 with ConfigurationException

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;
}
Also used : ConfigurationException(org.osgi.service.cm.ConfigurationException) Collection(java.util.Collection) Properties(java.util.Properties)

Example 30 with ConfigurationException

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();
    }
}
Also used : ConfigurationException(org.osgi.service.cm.ConfigurationException) ModifiableThreadPoolConfig(org.apache.sling.commons.threads.ModifiableThreadPoolConfig) ThreadPoolConfig(org.apache.sling.commons.threads.ThreadPoolConfig)

Aggregations

ConfigurationException (org.osgi.service.cm.ConfigurationException)190 Activate (org.apache.felix.scr.annotations.Activate)31 ServiceReference (org.osgi.framework.ServiceReference)30 Matcher (java.util.regex.Matcher)28 Hashtable (java.util.Hashtable)26 Properties (java.util.Properties)22 IOException (java.io.IOException)21 Test (org.junit.Test)21 ManagedService (org.osgi.service.cm.ManagedService)20 FooService (org.apache.felix.ipojo.runtime.core.services.FooService)19 HashMap (java.util.HashMap)17 File (java.io.File)11 URISyntaxException (java.net.URISyntaxException)11 Collection (java.util.Collection)11 HashSet (java.util.HashSet)11 ServiceTracker (org.osgi.util.tracker.ServiceTracker)10 URI (java.net.URI)9 Dictionary (java.util.Dictionary)9 Map (java.util.Map)9 NotFoundException (org.opencastproject.util.NotFoundException)9