Class ConfigurationManager

java.lang.Object
org.apache.felix.cm.impl.ConfigurationManager
All Implemented Interfaces:
EventListener, org.osgi.framework.BundleListener

public class ConfigurationManager extends Object implements org.osgi.framework.BundleListener
The ConfigurationManager is the central class in this implementation of the Configuration Admin Service Specification. As such it has the following tasks:
  • It is a BundleListener which gets informed when the states of bundles change. Mostly this is needed to unbind any bound configuration in case a bundle is uninstalled.
  • It is a ServiceListener which gets informed when ManagedService and ManagedServiceFactory services are registered and unregistered. This is used to provide configuration to these services. As a service listener it also listens for PersistenceManager instances being registered to support different configuration persistence layers.
  • A ConfigurationAdminFactory instance is registered as the ConfigurationAdmin service.
  • Last but not least this instance manages all tasks laid out in the specification such as maintaining configuration, taking care of configuration events, etc.
  • Field Details

    • numberGenerator

      private static Random numberGenerator
    • bundleContext

      private final org.osgi.framework.BundleContext bundleContext
    • configurationAdminRegistration

      private volatile org.osgi.framework.ServiceRegistration<org.osgi.service.cm.ConfigurationAdmin> configurationAdminRegistration
    • serviceProperties

      private volatile Dictionary<String,Object> serviceProperties
    • configurationListenerTracker

      private org.osgi.util.tracker.ServiceTracker<org.osgi.service.cm.ConfigurationListener,org.osgi.service.cm.ConfigurationListener> configurationListenerTracker
    • syncConfigurationListenerTracker

      private org.osgi.util.tracker.ServiceTracker<org.osgi.service.cm.SynchronousConfigurationListener,org.osgi.service.cm.SynchronousConfigurationListener> syncConfigurationListenerTracker
    • managedServiceTracker

      private ManagedServiceTracker managedServiceTracker
    • managedServiceFactoryTracker

      private ManagedServiceFactoryTracker managedServiceFactoryTracker
    • updateThread

      private UpdateThread updateThread
    • eventThread

      private UpdateThread eventThread
    • persistenceManager

      private final ExtPersistenceManager persistenceManager
      The persistence manager
    • configurations

      private final HashMap<String,ConfigurationImpl> configurations
    • dynamicBindings

      private final DynamicBindings dynamicBindings
      The map of dynamic configuration bindings. This maps the PID of the dynamically bound configuration or factory to its bundle location.

      On bundle startup this map is loaded from persistence and validated against the locations of installed bundles: Entries pointing to bundle locations not currently installed are removed.

      The map is written to persistence on each change.

    • handleBundleEvents

      private volatile boolean handleBundleEvents
    • isActive

      private volatile boolean isActive
    • coordinator

      private volatile Object coordinator
  • Constructor Details

  • Method Details

    • start

      public org.osgi.framework.ServiceReference<org.osgi.service.cm.ConfigurationAdmin> start()
    • stop

      public void stop()
    • isActive

      boolean isActive()
      Returns true if this manager is considered active.
    • getBundleContext

      public org.osgi.framework.BundleContext getBundleContext()
    • getCachedConfiguration

      ConfigurationImpl getCachedConfiguration(String pid)
    • getCachedConfigurations

      ConfigurationImpl[] getCachedConfigurations()
    • cacheConfiguration

      ConfigurationImpl cacheConfiguration(ConfigurationImpl configuration)
    • removeConfiguration

      void removeConfiguration(ConfigurationImpl configuration)
    • setDynamicBundleLocation

      void setDynamicBundleLocation(String pid, String location)
    • getDynamicBundleLocation

      String getDynamicBundleLocation(String pid)
    • createFactoryConfiguration

      ConfigurationImpl createFactoryConfiguration(String factoryPid, String location) throws IOException
      Throws:
      IOException
    • createFactoryConfiguration

      ConfigurationImpl createFactoryConfiguration(String pid, String factoryPid, String location) throws IOException
      Throws:
      IOException
    • getTargetedConfiguration

      ConfigurationImpl getTargetedConfiguration(String rawPid, org.osgi.framework.ServiceReference target) throws IOException
      Returns a targeted configuration for the given service PID and the reference target service.

      A configuration returned has already been checked for visibility by the bundle registering the referenced service. Additionally, the configuration is also dynamically bound if needed.

      Parameters:
      rawPid - The raw service PID to get targeted configuration for.
      target - The target ServiceReference to get configuration for.
      Returns:
      The best matching targeted configuration or null if there is no configuration at all.
      Throws:
      IOException
    • getConfiguration

      ConfigurationImpl getConfiguration(String pid) throws IOException
      Returns the ConfigurationImpl with the given PID if available in the internal cache or from any persistence manager. Otherwise null is returned.
      Parameters:
      pid - The PID for which to return the configuration
      Returns:
      The configuration or null if non exists
      Throws:
      IOException - If an error occurs reading from a persistence manager.
    • createConfiguration

      ConfigurationImpl createConfiguration(String pid, String bundleLocation) throws IOException
      Creates a regular (non-factory) configuration for the given PID setting the bundle location accordingly.

      This method assumes the configuration to not exist yet and will create it without further checking.

      Parameters:
      pid - The PID of the new configuration
      bundleLocation - The location to set on the new configuration. This may be null to not bind the configuration yet.
      Returns:
      The new configuration persisted in the first persistence manager.
      Throws:
      IOException - If an error occurrs writing the configuration to the persistence.
    • listConfigurations

      ConfigurationImpl[] listConfigurations(ConfigurationAdminImpl configurationAdmin, String filterString) throws IOException, org.osgi.framework.InvalidSyntaxException
      Throws:
      IOException
      org.osgi.framework.InvalidSyntaxException
    • deleted

      void deleted(ConfigurationImpl config)
    • updated

      void updated(ConfigurationImpl config, boolean fireEvent)
    • locationChanged

      void locationChanged(ConfigurationImpl config, String oldLocation)
    • fireConfigurationEvent

      void fireConfigurationEvent(int type, String pid, String factoryPid)
    • bundleChanged

      public void bundleChanged(org.osgi.framework.BundleEvent event)
      Specified by:
      bundleChanged in interface org.osgi.framework.BundleListener
    • getServiceReference

      private org.osgi.framework.ServiceReference<org.osgi.service.cm.ConfigurationAdmin> getServiceReference()
    • configure

      public void configure(String[] pid, org.osgi.framework.ServiceReference sr, boolean factory, ConfigurationMap<?> configs)
      Schedules the configuration of the referenced service with configuration for the given PID.
      Parameters:
      pid - The list of service PID of the configurations to be provided to the referenced service.
      sr - The ServiceReference to the service to be configured.
      factory - true If the service is considered to be a ManagedServiceFactory. Otherwise the service is considered to be a ManagedService.
    • internalCreateConfiguration

      private ConfigurationImpl internalCreateConfiguration(String pid, String factoryPid, String bundleLocation) throws IOException
      Factory method to create a new configuration object. The configuration object returned is not stored in configuration cache and only persisted if the factoryPid parameter is null.
      Parameters:
      pid - The PID of the new configuration object. Must not be null.
      factoryPid - The factory PID of the new configuration. Not null if the new configuration object belongs to a factory. The configuration object will not be persisted if this parameter is not null.
      bundleLocation - The bundle location of the bundle to which the configuration belongs or null if the configuration is not bound yet.
      Returns:
      The new configuration object
      Throws:
      IOException - May be thrown if an error occurrs persisting the new configuration object.
    • getTargetedFactories

      List<String> getTargetedFactories(String rawFactoryPid, org.osgi.framework.ServiceReference target) throws IOException
      Returns a list of
      invalid reference
      Factory
      instances according to the Configuration Admin 1.5 specification for targeted PIDs (Section 104.3.2)
      Parameters:
      rawFactoryPid - The raw factory PID without any targettng.
      target - The ServiceReference of the service to be supplied with targeted configuration.
      Returns:
      A list of
      invalid reference
      Factory
      instances as listed above. This list will always at least include an instance for the rawFactoryPid. Other instances are only included if existing.
      Throws:
      IOException - If an error occurs reading any of the
      invalid reference
      Factory
      instances from persistence
    • callPlugins

      public void callPlugins(Dictionary<String,Object> props, org.osgi.framework.ServiceReference<?> sr, String configPid, String factoryPid)
      Calls the registered configuration plugins on the given configuration properties from the given configuration object.

      The plugins to be called are selected as ConfigurationPlugin services registered with a cm.target property set to * or the factory PID of the configuration (for factory configurations) or the PID of the configuration (for non-factory configurations).

      Parameters:
      props - The configuration properties run through the registered ConfigurationPlugin services. This must not be null.
      sr - The service reference of the managed service (factory) which is to be updated with configuration
      configPid - The PID of the configuration object whose properties are to be augmented
      factoryPid - the factory PID of the configuration object whose properties are to be augmented. This is non-null only for a factory configuration.
    • createPid

      private static String createPid(String factoryPid)
      Creates a PID for the given factoryPid
      Parameters:
      factoryPid -
      Returns:
    • canReceive

      boolean canReceive(org.osgi.framework.Bundle bundle, String location)
      Checks whether the bundle is allowed to receive the configuration with the given location binding.

      This method implements the logic defined CM 1.4 / 104.4.1:

      • If the location is null (the configuration is not bound yet), assume the bundle is allowed
      • If the location is a single location (no leading "?"), require the bundle's location to match
      • If the location is a multi-location (leading "?"), assume the bundle is allowed if there is no security manager. If there is a security manager, check whether the bundle has "target" permission on this location.
    • setCoordinator

      public void setCoordinator(Object service)
    • updateRegisteredConfigurationPlugins

      public void updateRegisteredConfigurationPlugins(String propValue)