You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by fm...@apache.org on 2009/12/14 11:03:40 UTC

svn commit: r890257 - /felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/AbstractComponentManager.java

Author: fmeschbe
Date: Mon Dec 14 10:03:40 2009
New Revision: 890257

URL: http://svn.apache.org/viewvc?rev=890257&view=rev
Log:
FELIX-1942 Add new state (FactoryInstance) which is like the Active state but disposes off the component on deactivation instead of just deactivating.

Modified:
    felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/AbstractComponentManager.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=890257&r1=890256&r2=890257&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 Mon Dec 14 10:03:40 2009
@@ -379,6 +379,10 @@
     {
         if ( m_componentMetadata.isFactory() )
         {
+            if ( getInstance() != null )
+            {
+                return FactoryInstance.getInstance();
+            }
             return Factory.getInstance();
         }
         else if ( m_componentMetadata.isImmediate() )
@@ -767,9 +771,9 @@
      * There are 12 states in all. They are: Disabled, Unsatisfied,
      * Registered, Factory, Active, Disposed, as well as the transient states
      * Enabling, Activating, Deactivating, Disabling, and Disposing.
-     * The Registered, Factory and Active states are the "Satisfied" state in
-     * concept. The tansient states will be changed to other states
-     * automatically when work is done.
+     * The Registered, Factory, FactoryInstance and Active states are the
+     * "Satisfied" state in concept. The tansient states will be changed to
+     * other states automatically when work is done.
      * <p>
      * The transition cases are listed below.
      * <ul>
@@ -1071,6 +1075,12 @@
         }
     }
 
+    /**
+     * The <code>Active</code> state is the satisified state of an immediate
+     * component after activation. Dealyed and service factory components switch
+     * to this state from the {@link Registered} state once the service
+     * object has (first) been requested.
+     */
     protected static final class Active extends Satisfied
     {
         private static final Active m_inst = new Active();
@@ -1101,6 +1111,12 @@
         }
     }
 
+    /**
+     * The <code>Registered</code> state is the statisfied state of a delayed or
+     * service factory component before the actual service instance is
+     * (first) retrieved. After getting the actualo service instance the
+     * component switches to the {@link Active} state.
+     */
     protected static final class Registered extends Satisfied
     {
         private static final Registered m_inst = new Registered();
@@ -1143,6 +1159,10 @@
         }
     }
 
+    /**
+     * The <code>Factory</code> state is the satisfied state of component
+     * factory components.
+     */
     protected static final class Factory extends Satisfied
     {
         private static final Factory m_inst = new Factory();
@@ -1160,6 +1180,42 @@
         }
     }
 
+
+    /**
+     * The <code>FactoryInstance</code> state is the satisfied state of
+     * instances of component factory components created with the
+     * <code>ComponentFactory.newInstance</code> method. This state acts the
+     * same as the {@link Active} state except that the
+     * {@link #deactivate(AbstractComponentManager, int)} switches to the
+     * real {@link Active} state before actually disposing off the component
+     * because component factory instances are never reactivated after
+     * 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
+    {
+        private static final FactoryInstance m_inst = new FactoryInstance();
+
+
+        private FactoryInstance()
+        {
+            super( "Active", STATE_ACTIVE );
+        }
+
+
+        static State getInstance()
+        {
+            return m_inst;
+        }
+
+
+        void deactivate( AbstractComponentManager acm, int reason )
+        {
+            acm.changeState( Active.getInstance() );
+            acm.dispose( reason );
+        }
+    }
+
     protected static final class Deactivating extends State
     {
         private static final Deactivating m_inst = new Deactivating();