felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fmesc...@apache.org
Subject svn commit: r683162 - in /felix/trunk/configadmin/src/main/java/org/apache/felix/cm/impl: ConfigurationImpl.java ConfigurationManager.java
Date Wed, 06 Aug 2008 08:25:59 GMT
Author: fmeschbe
Date: Wed Aug  6 01:25:58 2008
New Revision: 683162

URL: http://svn.apache.org/viewvc?rev=683162&view=rev
Log:
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

Modified:
    felix/trunk/configadmin/src/main/java/org/apache/felix/cm/impl/ConfigurationImpl.java
    felix/trunk/configadmin/src/main/java/org/apache/felix/cm/impl/ConfigurationManager.java

Modified: felix/trunk/configadmin/src/main/java/org/apache/felix/cm/impl/ConfigurationImpl.java
URL: http://svn.apache.org/viewvc/felix/trunk/configadmin/src/main/java/org/apache/felix/cm/impl/ConfigurationImpl.java?rev=683162&r1=683161&r2=683162&view=diff
==============================================================================
--- felix/trunk/configadmin/src/main/java/org/apache/felix/cm/impl/ConfigurationImpl.java
(original)
+++ felix/trunk/configadmin/src/main/java/org/apache/felix/cm/impl/ConfigurationImpl.java
Wed Aug  6 01:25:58 2008
@@ -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 );

Modified: felix/trunk/configadmin/src/main/java/org/apache/felix/cm/impl/ConfigurationManager.java
URL: http://svn.apache.org/viewvc/felix/trunk/configadmin/src/main/java/org/apache/felix/cm/impl/ConfigurationManager.java?rev=683162&r1=683161&r2=683162&view=diff
==============================================================================
--- felix/trunk/configadmin/src/main/java/org/apache/felix/cm/impl/ConfigurationManager.java
(original)
+++ felix/trunk/configadmin/src/main/java/org/apache/felix/cm/impl/ConfigurationManager.java
Wed Aug  6 01:25:58 2008
@@ -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() ) )



Mime
View raw message