Class ConfigurationManager
- All Implemented Interfaces:
EventListener,org.osgi.framework.BundleListener
ConfigurationManager is the central class in this
implementation of the Configuration Admin Service Specification. As such it
has the following tasks:
- It is a
BundleListenerwhich 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
ServiceListenerwhich gets informed whenManagedServiceandManagedServiceFactoryservices are registered and unregistered. This is used to provide configuration to these services. As a service listener it also listens forPersistenceManagerinstances being registered to support different configuration persistence layers. - A
ConfigurationAdminFactoryinstance is registered as theConfigurationAdminservice. - Last but not least this instance manages all tasks laid out in the specification such as maintaining configuration, taking care of configuration events, etc.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionclassclassTheDeleteConfigurationclass is used to informManagedService[Factory]services of a configuration being deleted.private classclassclassTheManagedServiceFactoryUpdateupdates a freshly registeredManagedServiceFactorywith a specific configuration.classTheManagedServiceUpdateupdates a freshly registeredManagedServicewith a specific configuration.classTheUpdateConfigurationis used to updateManagedService[Factory]services with the configuration they are subscribed to. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final org.osgi.framework.BundleContextprivate org.osgi.framework.ServiceRegistration<org.osgi.service.cm.ConfigurationAdmin> private org.osgi.util.tracker.ServiceTracker<org.osgi.service.cm.ConfigurationListener, org.osgi.service.cm.ConfigurationListener> private final HashMap<String, ConfigurationImpl> private Objectprivate final DynamicBindingsThe map of dynamic configuration bindings.private UpdateThreadprivate booleanprivate booleanprivate ManagedServiceFactoryTrackerprivate ManagedServiceTrackerprivate static Randomprivate final ExtPersistenceManagerThe persistence managerprivate Dictionary<String, Object> private org.osgi.util.tracker.ServiceTracker<org.osgi.service.cm.SynchronousConfigurationListener, org.osgi.service.cm.SynchronousConfigurationListener> private UpdateThread -
Constructor Summary
ConstructorsConstructorDescriptionConfigurationManager(ExtPersistenceManager persistenceManager, org.osgi.framework.BundleContext bundleContext) -
Method Summary
Modifier and TypeMethodDescriptionvoidbundleChanged(org.osgi.framework.BundleEvent event) (package private) ConfigurationImplcacheConfiguration(ConfigurationImpl configuration) voidcallPlugins(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.(package private) booleancanReceive(org.osgi.framework.Bundle bundle, String location) Checks whether the bundle is allowed to receive the configuration with the given location binding.voidconfigure(String[] pid, org.osgi.framework.ServiceReference sr, boolean factory, ConfigurationMap<?> configs) Schedules the configuration of the referenced service with configuration for the given PID.(package private) ConfigurationImplcreateConfiguration(String pid, String bundleLocation) Creates a regular (non-factory) configuration for the given PID setting the bundle location accordingly.(package private) ConfigurationImplcreateFactoryConfiguration(String factoryPid, String location) (package private) ConfigurationImplcreateFactoryConfiguration(String pid, String factoryPid, String location) private static StringCreates a PID for the given factoryPid(package private) voiddeleted(ConfigurationImpl config) (package private) voidfireConfigurationEvent(int type, String pid, String factoryPid) org.osgi.framework.BundleContext(package private) ConfigurationImpl(package private) ConfigurationImpl[](package private) ConfigurationImplgetConfiguration(String pid) Returns theConfigurationImplwith the given PID if available in the internal cache or from any persistence manager.(package private) Stringprivate org.osgi.framework.ServiceReference<org.osgi.service.cm.ConfigurationAdmin> (package private) ConfigurationImplgetTargetedConfiguration(String rawPid, org.osgi.framework.ServiceReference target) Returns a targeted configuration for the given service PID and the reference target service.getTargetedFactories(String rawFactoryPid, org.osgi.framework.ServiceReference target) Returns a list ofinstances according to the Configuration Admin 1.5 specification for targeted PIDs (Section 104.3.2)invalid reference
Factoryprivate ConfigurationImplinternalCreateConfiguration(String pid, String factoryPid, String bundleLocation) Factory method to create a new configuration object.(package private) booleanisActive()Returnstrueif this manager is considered active.(package private) ConfigurationImpl[]listConfigurations(ConfigurationAdminImpl configurationAdmin, String filterString) (package private) voidlocationChanged(ConfigurationImpl config, String oldLocation) (package private) voidremoveConfiguration(ConfigurationImpl configuration) voidsetCoordinator(Object service) (package private) voidsetDynamicBundleLocation(String pid, String location) org.osgi.framework.ServiceReference<org.osgi.service.cm.ConfigurationAdmin> start()voidstop()(package private) voidupdated(ConfigurationImpl config, boolean fireEvent) voidupdateRegisteredConfigurationPlugins(String propValue)
-
Field Details
-
numberGenerator
-
bundleContext
private final org.osgi.framework.BundleContext bundleContext -
configurationAdminRegistration
private volatile org.osgi.framework.ServiceRegistration<org.osgi.service.cm.ConfigurationAdmin> configurationAdminRegistration -
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
-
managedServiceFactoryTracker
-
updateThread
-
eventThread
-
persistenceManager
The persistence manager -
configurations
-
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
-
-
Constructor Details
-
ConfigurationManager
public ConfigurationManager(ExtPersistenceManager persistenceManager, org.osgi.framework.BundleContext bundleContext) throws IOException - Throws:
IOException
-
-
Method Details
-
start
public org.osgi.framework.ServiceReference<org.osgi.service.cm.ConfigurationAdmin> start() -
stop
public void stop() -
isActive
boolean isActive()Returnstrueif this manager is considered active. -
getBundleContext
public org.osgi.framework.BundleContext getBundleContext() -
getCachedConfiguration
-
getCachedConfigurations
ConfigurationImpl[] getCachedConfigurations() -
cacheConfiguration
-
removeConfiguration
-
setDynamicBundleLocation
-
getDynamicBundleLocation
-
createFactoryConfiguration
- 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 targetServiceReferenceto get configuration for.- Returns:
- The best matching targeted configuration or
nullif there is no configuration at all. - Throws:
IOException
-
getConfiguration
Returns theConfigurationImplwith the given PID if available in the internal cache or from any persistence manager. Otherwisenullis returned.- Parameters:
pid- The PID for which to return the configuration- Returns:
- The configuration or
nullif non exists - Throws:
IOException- If an error occurs reading from a persistence manager.
-
createConfiguration
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 configurationbundleLocation- The location to set on the new configuration. This may benullto 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:
IOExceptionorg.osgi.framework.InvalidSyntaxException
-
deleted
-
updated
-
locationChanged
-
fireConfigurationEvent
-
bundleChanged
public void bundleChanged(org.osgi.framework.BundleEvent event) - Specified by:
bundleChangedin interfaceorg.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- TheServiceReferenceto the service to be configured.factory-trueIf the service is considered to be aManagedServiceFactory. Otherwise the service is considered to be aManagedService.
-
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 thefactoryPidparameter isnull.- Parameters:
pid- The PID of the new configuration object. Must not benull.factoryPid- The factory PID of the new configuration. Notnullif the new configuration object belongs to a factory. The configuration object will not be persisted if this parameter is notnull.bundleLocation- The bundle location of the bundle to which the configuration belongs ornullif 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 ofinstances according to the Configuration Admin 1.5 specification for targeted PIDs (Section 104.3.2)invalid reference
Factory- Parameters:
rawFactoryPid- The raw factory PID without any targettng.target- TheServiceReferenceof the service to be supplied with targeted configuration.- Returns:
- A list of
instances as listed above. This list will always at least include an instance for the
invalid reference
FactoryrawFactoryPid. Other instances are only included if existing. - Throws:
IOException- If an error occurs reading any of theinstances from persistenceinvalid reference
Factory
-
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
ConfigurationPluginservices registered with acm.targetproperty 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 benull.sr- The service reference of the managed service (factory) which is to be updated with configurationconfigPid- The PID of the configuration object whose properties are to be augmentedfactoryPid- the factory PID of the configuration object whose properties are to be augmented. This is non-nullonly for a factory configuration.
-
createPid
Creates a PID for the given factoryPid- Parameters:
factoryPid-- Returns:
-
canReceive
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.
- If the location is
-
setCoordinator
-
updateRegisteredConfigurationPlugins
-