felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pde...@apache.org
Subject svn commit: r1399224 - in /felix/trunk/scr/src: main/java/org/apache/felix/scr/impl/manager/ComponentFactoryImpl.java test/java/org/apache/felix/scr/integration/ComponentFactoryTest.java
Date Wed, 17 Oct 2012 13:20:27 GMT
Author: pderop
Date: Wed Oct 17 13:20:27 2012
New Revision: 1399224

URL: http://svn.apache.org/viewvc?rev=1399224&view=rev
Log:
FELIX-3700: Unregister ComponentFactory when configuration is lost and when
configuration-policy is required.

Modified:
    felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/ComponentFactoryImpl.java
    felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/ComponentFactoryTest.java

Modified: felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/ComponentFactoryImpl.java
URL: http://svn.apache.org/viewvc/felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/ComponentFactoryImpl.java?rev=1399224&r1=1399223&r2=1399224&view=diff
==============================================================================
--- felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/ComponentFactoryImpl.java
(original)
+++ felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/ComponentFactoryImpl.java
Wed Oct 17 13:20:27 2012
@@ -312,9 +312,38 @@ public class ComponentFactoryImpl extend
     {
         if ( pid.equals( getComponentMetadata().getConfigurationPid() ) )
         {
-            // deleting configuration of a component factory is like
-            // providing an empty configuration
-            m_configuration = new Hashtable();
+            log( LogService.LOG_DEBUG, "Handling configuration removal", null );
+
+            boolean release = obtainReadLock( "ComponentFactoryImpl.configurationDeleted"
);
+            try
+            {
+                // nothing to do if there is no configuration currently known.
+                if (! m_isConfigured)
+                {
+                    log( LogService.LOG_DEBUG, "ignoring configuration removal: not currently
configured", null );
+                    return;
+                }
+                
+                // So far, we were configured: clear the current configuration.
+                m_isConfigured = false;
+                m_configuration = new Hashtable();
+
+                log( LogService.LOG_DEBUG, "Current component factory state={0}", new Object[]
{ getState() }, null );
+
+                // And deactivate if we are not currently disposed and if configuration is
required
+                if ( ( getState() & STATE_DISPOSED ) == 0 && getComponentMetadata().isConfigurationRequired()
)
+                {
+                    log( LogService.LOG_DEBUG, "Deactivating component factory (required
configuration has gone)", null );
+                    deactivateInternal( ComponentConstants.DEACTIVATION_REASON_CONFIGURATION_DELETED
);
+                }
+            }
+            finally
+            {
+                if ( release )
+                {
+                    releaseReadLock( "ComponentFactoryImpl.configurationDeleted" );
+                }
+            }
         }
         else
         {

Modified: felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/ComponentFactoryTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/ComponentFactoryTest.java?rev=1399224&r1=1399223&r2=1399224&view=diff
==============================================================================
--- felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/ComponentFactoryTest.java
(original)
+++ felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/ComponentFactoryTest.java
Wed Oct 17 13:20:27 2012
@@ -304,10 +304,10 @@ public class ComponentFactoryTest extend
         final Object instanceManager = getFieldValue( instance, "m_componentManager" );
         TestCase.assertTrue( instanceMap.containsValue( instanceManager ) );
 
-        // delete config, ensure factory still active and component instance, not changed
+        // delete config, ensure factory is not active anymore and component instance not
changed
         deleteConfig( componentname );
         delay();
-        TestCase.assertEquals( Component.STATE_FACTORY, component.getState() );
+        TestCase.assertEquals( Component.STATE_UNSATISFIED, component.getState() );
 
         TestCase.assertNotNull( instance.getInstance() );
         TestCase.assertEquals( SimpleComponent.INSTANCE, instance.getInstance() );



Mime
View raw message