Search in sources :

Example 1 with FilePersistenceManager

use of org.apache.felix.cm.file.FilePersistenceManager in project felix by apache.

the class DynamicBindingsTest method setUp.

protected void setUp() throws Exception {
    super.setUp();
    configLocation = new File("target/config." + System.currentTimeMillis());
    persistenceManager = new FilePersistenceManager(configLocation.getAbsolutePath());
    bindingsFile = new File(configLocation, DynamicBindings.BINDINGS_FILE_NAME + ".config");
}
Also used : FilePersistenceManager(org.apache.felix.cm.file.FilePersistenceManager) File(java.io.File)

Example 2 with FilePersistenceManager

use of org.apache.felix.cm.file.FilePersistenceManager in project felix by apache.

the class ConfigurationManager method start.

@Override
public void start(BundleContext bundleContext) {
    // track the log service using a ServiceTracker
    logTracker = new ServiceTracker(bundleContext, LOG_SERVICE_NAME, null);
    logTracker.open();
    // assign the log level
    String logLevelProp = bundleContext.getProperty(CM_LOG_LEVEL);
    if (logLevelProp == null) {
        logLevel = CM_LOG_LEVEL_DEFAULT;
    } else {
        try {
            logLevel = Integer.parseInt(logLevelProp);
        } catch (NumberFormatException nfe) {
            logLevel = CM_LOG_LEVEL_DEFAULT;
        }
    }
    // set up some fields
    this.bundleContext = bundleContext;
    // configurationlistener support
    configurationListenerTracker = new ServiceTracker(bundleContext, ConfigurationListener.class.getName(), null);
    configurationListenerTracker.open();
    syncConfigurationListenerTracker = new ServiceTracker(bundleContext, SynchronousConfigurationListener.class.getName(), null);
    syncConfigurationListenerTracker.open();
    // initialize the asynchonous updater thread
    ThreadGroup tg = new ThreadGroup("Configuration Admin Service");
    tg.setDaemon(true);
    this.updateThread = new UpdateThread(this, tg, "CM Configuration Updater");
    this.eventThread = new UpdateThread(this, tg, "CM Event Dispatcher");
    // set up the location (might throw IllegalArgumentException)
    try {
        FilePersistenceManager fpm = new FilePersistenceManager(bundleContext, bundleContext.getProperty(CM_CONFIG_DIR));
        Hashtable props = new Hashtable();
        props.put(Constants.SERVICE_PID, fpm.getClass().getName());
        props.put(Constants.SERVICE_DESCRIPTION, "Platform Filesystem Persistence Manager");
        props.put(Constants.SERVICE_VENDOR, "Apache Software Foundation");
        props.put(Constants.SERVICE_RANKING, new Integer(Integer.MIN_VALUE));
        filepmRegistration = bundleContext.registerService(PersistenceManager.class.getName(), fpm, props);
        // setup dynamic configuration bindings
        dynamicBindings = new DynamicBindings(bundleContext, fpm);
    } catch (IOException ioe) {
        log(LogService.LOG_ERROR, "Failure setting up dynamic configuration bindings", ioe);
    } catch (IllegalArgumentException iae) {
        log(LogService.LOG_ERROR, "Cannot create the FilePersistenceManager", iae);
    }
    // register as bundle and service listener
    handleBundleEvents = true;
    bundleContext.addBundleListener(this);
    // get all persistence managers to begin with
    // make sure to get the persistence managers at least once
    pmtCount = 1;
    persistenceManagerTracker = new ServiceTracker(bundleContext, PersistenceManager.class.getName(), null);
    persistenceManagerTracker.open();
    // consider alive now (before clients use Configuration Admin
    // service registered in the next step)
    isActive = true;
    // create and register configuration admin - start after PM tracker ...
    ConfigurationAdminFactory caf = new ConfigurationAdminFactory(this);
    Hashtable<String, Object> props = new Hashtable<String, Object>();
    props.put(Constants.SERVICE_PID, "org.apache.felix.cm.ConfigurationAdmin");
    props.put(Constants.SERVICE_DESCRIPTION, "Configuration Admin Service Specification 1.5 Implementation");
    props.put(Constants.SERVICE_VENDOR, "Apache Software Foundation");
    configurationAdminRegistration = bundleContext.registerService(ConfigurationAdmin.class.getName(), caf, props);
    // start handling ManagedService[Factory] services
    managedServiceTracker = new ManagedServiceTracker(this);
    managedServiceFactoryTracker = new ManagedServiceFactoryTracker(this);
    // start processing the event queues only after registering the service
    // see FELIX-2813 for details
    this.updateThread.start();
    this.eventThread.start();
}
Also used : ManagedServiceFactoryTracker(org.apache.felix.cm.impl.helper.ManagedServiceFactoryTracker) ManagedServiceTracker(org.apache.felix.cm.impl.helper.ManagedServiceTracker) ServiceTracker(org.osgi.util.tracker.ServiceTracker) Hashtable(java.util.Hashtable) IOException(java.io.IOException) FilePersistenceManager(org.apache.felix.cm.file.FilePersistenceManager) ManagedServiceTracker(org.apache.felix.cm.impl.helper.ManagedServiceTracker)

Example 3 with FilePersistenceManager

use of org.apache.felix.cm.file.FilePersistenceManager in project felix by apache.

the class Activator method registerFilePersistenceManager.

private PersistenceManager registerFilePersistenceManager(final BundleContext bundleContext) {
    try {
        final FilePersistenceManager fpm = new FilePersistenceManager(bundleContext, bundleContext.getProperty(CM_CONFIG_DIR));
        final Dictionary<String, Object> props = new Hashtable<>();
        props.put(Constants.SERVICE_DESCRIPTION, "Platform Filesystem Persistence Manager");
        props.put(Constants.SERVICE_VENDOR, "The Apache Software Foundation");
        props.put(Constants.SERVICE_RANKING, new Integer(Integer.MIN_VALUE));
        props.put(PersistenceManager.PROPERTY_NAME, FilePersistenceManager.DEFAULT_PERSISTENCE_MANAGER_NAME);
        filepmRegistration = bundleContext.registerService(PersistenceManager.class, fpm, props);
        return fpm;
    } catch (final IllegalArgumentException iae) {
        Log.logger.log(LogService.LOG_ERROR, "Cannot create the FilePersistenceManager", iae);
    }
    return null;
}
Also used : FilePersistenceManager(org.apache.felix.cm.file.FilePersistenceManager) PersistenceManager(org.apache.felix.cm.PersistenceManager) FilePersistenceManager(org.apache.felix.cm.file.FilePersistenceManager) Hashtable(java.util.Hashtable)

Example 4 with FilePersistenceManager

use of org.apache.felix.cm.file.FilePersistenceManager in project ddf by codice.

the class Activator method start.

@Override
public void start(BundleContext bundleContext) throws Exception {
    persistenceManager = new DelegatingPersistenceManager(new EncryptingPersistenceManager(new FilePersistenceManager(bundleContext, bundleContext.getProperty("felix.cm.dir"))));
    final Dictionary<String, Object> props = new Hashtable<>();
    props.put(Constants.SERVICE_DESCRIPTION, "DDF :: Platform :: OSGi :: Configuration Admin");
    props.put(Constants.SERVICE_VENDOR, "Codice Foundation");
    props.put("name", "CodicePM");
    filepmRegistration = bundleContext.registerService(PersistenceManager.class.getName(), persistenceManager, props);
}
Also used : FilePersistenceManager(org.apache.felix.cm.file.FilePersistenceManager) Hashtable(java.util.Hashtable)

Aggregations

FilePersistenceManager (org.apache.felix.cm.file.FilePersistenceManager)4 Hashtable (java.util.Hashtable)3 File (java.io.File)1 IOException (java.io.IOException)1 PersistenceManager (org.apache.felix.cm.PersistenceManager)1 ManagedServiceFactoryTracker (org.apache.felix.cm.impl.helper.ManagedServiceFactoryTracker)1 ManagedServiceTracker (org.apache.felix.cm.impl.helper.ManagedServiceTracker)1 ServiceTracker (org.osgi.util.tracker.ServiceTracker)1