Search in sources :

Example 1 with ManagedServiceTracker

use of org.apache.felix.cm.impl.helper.ManagedServiceTracker 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 2 with ManagedServiceTracker

use of org.apache.felix.cm.impl.helper.ManagedServiceTracker in project felix by apache.

the class ConfigurationManager method start.

public ServiceReference<ConfigurationAdmin> start() {
    // configurationlistener support
    configurationListenerTracker = new ServiceTracker<>(bundleContext, ConfigurationListener.class, null);
    configurationListenerTracker.open();
    syncConfigurationListenerTracker = new ServiceTracker<>(bundleContext, SynchronousConfigurationListener.class, null);
    syncConfigurationListenerTracker.open();
    // initialize the asynchonous updater thread
    ThreadGroup tg = new ThreadGroup("Configuration Admin Service");
    tg.setDaemon(true);
    this.updateThread = new UpdateThread(tg, "CM Configuration Updater");
    this.eventThread = new UpdateThread(tg, "CM Event Dispatcher");
    // register as bundle and service listener
    handleBundleEvents = true;
    bundleContext.addBundleListener(this);
    // 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);
    Dictionary<String, Object> props = new Hashtable<>();
    props.put(Constants.SERVICE_PID, "org.apache.felix.cm.ConfigurationAdmin");
    props.put(Constants.SERVICE_DESCRIPTION, "Configuration Admin Service Specification 1.6 Implementation");
    props.put(Constants.SERVICE_VENDOR, "The Apache Software Foundation");
    configurationAdminRegistration = bundleContext.registerService(ConfigurationAdmin.class, 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();
    return configurationAdminRegistration.getReference();
}
Also used : ManagedServiceFactoryTracker(org.apache.felix.cm.impl.helper.ManagedServiceFactoryTracker) Hashtable(java.util.Hashtable) SynchronousConfigurationListener(org.osgi.service.cm.SynchronousConfigurationListener) SynchronousConfigurationListener(org.osgi.service.cm.SynchronousConfigurationListener) ConfigurationListener(org.osgi.service.cm.ConfigurationListener) ManagedServiceTracker(org.apache.felix.cm.impl.helper.ManagedServiceTracker) ConfigurationAdmin(org.osgi.service.cm.ConfigurationAdmin)

Aggregations

Hashtable (java.util.Hashtable)2 ManagedServiceFactoryTracker (org.apache.felix.cm.impl.helper.ManagedServiceFactoryTracker)2 ManagedServiceTracker (org.apache.felix.cm.impl.helper.ManagedServiceTracker)2 IOException (java.io.IOException)1 FilePersistenceManager (org.apache.felix.cm.file.FilePersistenceManager)1 ConfigurationAdmin (org.osgi.service.cm.ConfigurationAdmin)1 ConfigurationListener (org.osgi.service.cm.ConfigurationListener)1 SynchronousConfigurationListener (org.osgi.service.cm.SynchronousConfigurationListener)1 ServiceTracker (org.osgi.util.tracker.ServiceTracker)1