felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From djen...@apache.org
Subject svn commit: r1377921 - in /felix/trunk/scr/src: main/java/org/apache/felix/scr/impl/manager/ test/java/org/apache/felix/scr/integration/
Date Tue, 28 Aug 2012 00:32:09 GMT
Author: djencks
Date: Tue Aug 28 00:32:09 2012
New Revision: 1377921

URL: http://svn.apache.org/viewvc?rev=1377921&view=rev
Log:
FELIX-3639 fix up Factory instance behavior when component instance is registered as a service

Modified:
    felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/AbstractComponentManager.java
    felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/ComponentFactoryImpl.java
    felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/ImmediateComponentManager.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/AbstractComponentManager.java
URL: http://svn.apache.org/viewvc/felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/AbstractComponentManager.java?rev=1377921&r1=1377920&r2=1377921&view=diff
==============================================================================
--- felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/AbstractComponentManager.java
(original)
+++ felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/AbstractComponentManager.java
Tue Aug 28 00:32:09 2012
@@ -654,6 +654,8 @@ public abstract class AbstractComponentM
 
     abstract State getSatisfiedState();
 
+    abstract State getActiveState();
+
     /**
      * Registers the service on behalf of the component.
      *
@@ -1344,10 +1346,7 @@ public abstract class AbstractComponentM
                 acm.escalateLock( "AbstractComponentManager.Unsatisifed.activate.1" );
                 try
                 {
-                    if ( acm.isImmediate() )
-                    {
-                        acm.changeState( Active.getInstance() );
-                    }
+                    acm.changeState( acm.getActiveState() );
                     if ( !acm.createComponent() )
                     {
                         // component creation failed, not active now
@@ -1549,17 +1548,16 @@ public abstract class AbstractComponentM
      * deactivated due to not being satisified any longer. See section 112.5.5,
      * Factory Component, for full details.
      */
-    protected static final class FactoryInstance extends Satisfied//Registered
+    protected static final class FactoryInstance extends Satisfied
     {
         private static final FactoryInstance m_inst = new FactoryInstance();
 
 
         private FactoryInstance()
         {
-            super( "Active", STATE_ACTIVE );
+            super("FactoryInstance", STATE_ACTIVE);
         }
 
-
         static State getInstance()
         {
             return m_inst;
@@ -1567,35 +1565,18 @@ public abstract class AbstractComponentM
 
         Object getService( ImmediateComponentManager dcm )
         {
-            if ( dcm.createComponent() )
-            {
-                dcm.changeState( Active.getInstance() );
-                return dcm.getInstance();
-            }
+            return dcm.getInstance();
+        }
 
-            // log that the delayed component cannot be created (we don't
-            // know why at this moment; this should already have been logged)
-            dcm.log( LogService.LOG_ERROR, "Failed creating the component instance; see log
for reason", null );
 
-            // component could not really be created. This may be temporary
-            // so we stay in the registered state but ensure the component
-            // instance is deleted
-            try
-            {
-                dcm.deleteComponent( ComponentConstants.DEACTIVATION_REASON_UNSPECIFIED );
-            }
-            catch ( Throwable t )
-            {
-                dcm.log( LogService.LOG_DEBUG, "Cannot delete incomplete component instance.
Ignoring.", t );
-            }
-
-            // no service can be returned (be prepared for more logging !!)
-            return null;
+        void ungetService( ImmediateComponentManager dcm )
+        {
+            dcm.deleteComponent( ComponentConstants.DEACTIVATION_REASON_UNSPECIFIED );
+            dcm.changeState( Registered.getInstance() );
         }
 
         void deactivate( AbstractComponentManager acm, int reason )
         {
-            acm.changeState( Active.getInstance() );
             acm.disposeInternal( reason );
         }
     }
@@ -1636,7 +1617,7 @@ public abstract class AbstractComponentM
 
         void dispose( AbstractComponentManager acm )
         {
-            throw new IllegalStateException( "dispose: " + this );
+            //factory instance can have dispose called with no effect. 112.5.5
         }
 
         void enable( AbstractComponentManager acm )

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=1377921&r1=1377920&r2=1377921&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
Tue Aug 28 00:32:09 2012
@@ -250,6 +250,11 @@ public class ComponentFactoryImpl extend
         return Factory.getInstance();
     }
 
+    State getActiveState()
+    {
+        return Factory.getInstance();
+    }
+
     //---------- Component interface
 
 
@@ -396,7 +401,7 @@ public class ComponentFactoryImpl extend
             super( activator, componentHolder, metadata );
         }
 
-        State getSatisfiedState()
+        State getActiveState()
         {
             return FactoryInstance.getInstance();
         }

Modified: felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/ImmediateComponentManager.java
URL: http://svn.apache.org/viewvc/felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/ImmediateComponentManager.java?rev=1377921&r1=1377920&r2=1377921&view=diff
==============================================================================
--- felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/ImmediateComponentManager.java
(original)
+++ felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/ImmediateComponentManager.java
Tue Aug 28 00:32:09 2012
@@ -300,6 +300,11 @@ public class ImmediateComponentManager e
         return Registered.getInstance();
     }
 
+    State getActiveState()
+    {
+        return Active.getInstance();
+    }
+
     protected void setFactoryProperties( Dictionary dictionary )
     {
         m_factoryProperties = copyTo( null, dictionary );

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=1377921&r1=1377920&r2=1377921&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
Tue Aug 28 00:32:09 2012
@@ -512,10 +512,10 @@ public class ComponentFactoryTest extend
         TestCase.assertNull( instanceNonMatch.getInstance() );
         TestCase.assertNull( SimpleComponent.INSTANCE );
 
-        //FactoryInstance.deactivate disposes the instance.  Don't do it again
-//        instanceNonMatch.dispose();
-//        TestCase.assertNull( SimpleComponent.INSTANCE );
-//        TestCase.assertNull( instanceNonMatch.getInstance() ); // SCR 112.12.6.2
+        //Check that calling dispose on a deactivated instance has no effect
+        instanceNonMatch.dispose();
+        TestCase.assertNull( SimpleComponent.INSTANCE );
+        TestCase.assertNull( instanceNonMatch.getInstance() ); // SCR 112.12.6.2
     }
 
     @Test



Mime
View raw message