FELIX-612 Don't persist newly created factory configuration objects and also
do not cache them internally. Only when the configuration update is first
updated will it be persisted and "registered" with the factory
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@683162 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/configadmin/src/main/java/org/apache/felix/cm/impl/ConfigurationImpl.java b/configadmin/src/main/java/org/apache/felix/cm/impl/ConfigurationImpl.java
index 28047c6..4b04282 100644
--- a/configadmin/src/main/java/org/apache/felix/cm/impl/ConfigurationImpl.java
+++ b/configadmin/src/main/java/org/apache/felix/cm/impl/ConfigurationImpl.java
@@ -143,11 +143,15 @@
this.bundleLocation = bundleLocation;
this.properties = null;
- // this is a new configuration object, store immediately
- Dictionary props = new Hashtable();
- setAutoProperties( props, true );
- props.put( CONFIGURATION_NEW, Boolean.TRUE );
- persistenceManager.store( pid, props );
+ // this is a new configuration object, store immediately unless
+ // the new configuration object is created from a factory, in which
+ // case the configuration is only stored when first updated
+ if (factoryPid == null) {
+ Dictionary props = new Hashtable();
+ setAutoProperties( props, true );
+ props.put( CONFIGURATION_NEW, Boolean.TRUE );
+ persistenceManager.store( pid, props );
+ }
}
@@ -303,6 +307,19 @@
persistenceManager.store( pid, newProperties );
configure( newProperties );
+
+ // if this is a factory configuration, update the factory with
+ String factoryPid = getFactoryPid();
+ if ( factoryPid != null )
+ {
+ Factory factory = configurationManager.getFactory( factoryPid );
+ if ( factory.addPID( getPid() ) )
+ {
+ // only write back if the pid was not already registered
+ // with the factory
+ factory.store();
+ }
+ }
// ensure configuration is being delivered
setDelivered( false );
diff --git a/configadmin/src/main/java/org/apache/felix/cm/impl/ConfigurationManager.java b/configadmin/src/main/java/org/apache/felix/cm/impl/ConfigurationManager.java
index 16bde00..2cc0cc7 100644
--- a/configadmin/src/main/java/org/apache/felix/cm/impl/ConfigurationManager.java
+++ b/configadmin/src/main/java/org/apache/felix/cm/impl/ConfigurationManager.java
@@ -293,9 +293,8 @@
ConfigurationImpl createFactoryConfiguration( ConfigurationAdminImpl configurationAdmin, String factoryPid )
throws IOException
{
- Factory factory = getFactory( factoryPid );
-
// check Persmission if factory is bound to another bundle
+ Factory factory = getFactory( factoryPid );
if ( factory.getBundleLocation() != null
&& !factory.getBundleLocation().equals( configurationAdmin.getBundle().getLocation() ) )
{
@@ -306,10 +305,6 @@
String pid = createPid( factoryPid );
ConfigurationImpl config = createConfiguration( pid, factoryPid, configurationAdmin.getBundle().getLocation() );
- // add the configuration to the factory
- factory.addPID( pid );
- factory.store();
-
return config;
}
@@ -326,11 +321,6 @@
String pid = createPid( factoryPid );
ConfigurationImpl config = createConfiguration( pid, factoryPid, location );
- // add the configuration to the factory
- Factory factory = getFactory( factoryPid );
- factory.addPID( pid );
- factory.store();
-
return config;
}
@@ -369,7 +359,9 @@
}
// else create new configuration also setting the bundle location
- return createConfiguration( pid, null, bundleLocation );
+ // and cache the new configuration
+ config = createConfiguration( pid, null, bundleLocation );
+ return cacheConfiguration( config );
}
@@ -585,13 +577,31 @@
}
+ /**
+ * Factory method to create a new configuration object. The configuration
+ * object returned is not stored in configuration cache and only persisted
+ * if the <code>factoryPid</code> parameter is <code>null</code>.
+ *
+ * @param pid
+ * The PID of the new configuration object. Must not be
+ * <code>null</code>.
+ * @param factoryPid
+ * The factory PID of the new configuration. Not
+ * <code>null</code> if the new configuration object belongs to
+ * a factory. The configuration object will not be persisted if
+ * this parameter is not <code>null</code>.
+ * @param bundleLocation
+ * The bundle location of the bundle to which the configuration
+ * belongs or <code>null</code> if the configuration is not
+ * bound yet.
+ * @return The new configuration object
+ * @throws IOException
+ * May be thrown if an error occurrs persisting the new
+ * configuration object.
+ */
ConfigurationImpl createConfiguration( String pid, String factoryPid, String bundleLocation ) throws IOException
{
- // create the configuration (which will also be stored immediately)
- ConfigurationImpl config = new ConfigurationImpl( this, getPersistenceManagers()[0], pid, factoryPid,
- bundleLocation );
-
- return cacheConfiguration( config );
+ return new ConfigurationImpl( this, getPersistenceManagers()[0], pid, factoryPid, bundleLocation );
}
@@ -996,7 +1006,10 @@
// Configuration has just been created but not yet updated
// we currently just ignore it and have the update mechanism
// provide the configuration to the ManagedServiceFactory
- log( LogService.LOG_DEBUG, "Ignoring new configuration pid=" + pid, null );
+ // As of FELIX-612 (not storing new factory configurations)
+ // this should not happen. We keep this for added stability
+ // but raise the logging level to error.
+ log( LogService.LOG_ERROR, "Ignoring new configuration pid=" + pid, null );
continue;
}
else if ( !factoryPid.equals( cfg.getFactoryPid() ) )