felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fmesc...@apache.org
Subject svn commit: r949317 - in /felix/trunk/scr/src/main/java/org/apache/felix/scr/impl: BundleComponentActivator.java ComponentActivatorTask.java manager/AbstractComponentManager.java manager/DependencyManager.java manager/ImmediateComponentManager.java
Date Fri, 28 May 2010 23:13:06 GMT
Author: fmeschbe
Date: Fri May 28 23:13:05 2010
New Revision: 949317

URL: http://svn.apache.org/viewvc?rev=949317&view=rev
Log:
FELIX-2368 make component enablement, activation, deactivation, and disablement synchronous
instead of asynchronous

Removed:
    felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/ComponentActivatorTask.java
Modified:
    felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/BundleComponentActivator.java
    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/DependencyManager.java
    felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/ImmediateComponentManager.java

Modified: felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/BundleComponentActivator.java
URL: http://svn.apache.org/viewvc/felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/BundleComponentActivator.java?rev=949317&r1=949316&r2=949317&view=diff
==============================================================================
--- felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/BundleComponentActivator.java
(original)
+++ felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/BundleComponentActivator.java
Fri May 28 23:13:05 2010
@@ -384,7 +384,7 @@ public class BundleComponentActivator im
      * @param name The name of the component to enable or <code>null</code> to
      *      enable all components.
      */
-    public void enableComponent( String name )
+    public void enableComponent( final String name )
     {
         final ComponentHolder[] holder = getSelectedComponents( name );
         if ( holder == null )
@@ -392,17 +392,35 @@ public class BundleComponentActivator im
             return;
         }
 
-        for ( int i = 0; i < holder.length; i++ )
+		// FELIX-2368; schedule for asynchronous enablement. According to
+        //    112.5.1 the enabled state should be changed immediately but
+        //    the component(s) should be activated asynchronously. Since
+        //    we do not really handle the enabled state separately we
+        //    schedule enablement and activation for asynchronous execution.
+        schedule( new Runnable()
         {
-            try
+            public void run()
             {
-                holder[i].enableComponents();
+                for ( int i = 0; i < holder.length; i++ )
+                {
+                    try
+                    {
+                        log( LogService.LOG_DEBUG, "Enabling Component", holder[i].getComponentMetadata(),
null );
+                        holder[i].enableComponents();
+                    }
+                    catch ( Throwable t )
+                    {
+                        log( LogService.LOG_ERROR, "Cannot enable component", holder[i].getComponentMetadata(),
t );
+                    }
+                }
             }
-            catch ( Throwable t )
+
+
+            public String toString()
             {
-                log( LogService.LOG_ERROR, "Cannot enable component", holder[i].getComponentMetadata(),
t );
+                return "enableComponent(" + name + ")";
             }
-        }
+        } );
     }
 
 
@@ -417,7 +435,7 @@ public class BundleComponentActivator im
      * @param name The name of the component to disable or <code>null</code>
to
      *      disable all components.
      */
-    public void disableComponent( String name )
+    public void disableComponent( final String name )
     {
         final ComponentHolder[] holder = getSelectedComponents( name );
         if ( holder == null )
@@ -425,18 +443,35 @@ public class BundleComponentActivator im
             return;
         }
 
-        for ( int i = 0; i < holder.length; i++ )
+        // FELIX-2368; schedule for asynchronous enablement. According to
+        //    112.5.1 the enabled state should be changed immediately but
+        //    the component(s) should be deactivated asynchronously. Since
+        //    we do not really handle the enabled state separately we
+        //    schedule disablement and deactivation for asynchronous execution.
+        schedule( new Runnable()
         {
-            try
+            public void run()
             {
-                log( LogService.LOG_DEBUG, "Disabling Component", holder[i].getComponentMetadata(),
null );
-                holder[i].disableComponents();
+                for ( int i = 0; i < holder.length; i++ )
+                {
+                    try
+                    {
+                        log( LogService.LOG_DEBUG, "Disabling Component", holder[i].getComponentMetadata(),
null );
+                        holder[i].disableComponents();
+                    }
+                    catch ( Throwable t )
+                    {
+                        log( LogService.LOG_ERROR, "Cannot disable component", holder[i].getComponentMetadata(),
t );
+                    }
+                }
             }
-            catch ( Throwable t )
+
+
+            public String toString()
             {
-                log( LogService.LOG_ERROR, "Cannot disable component", holder[i].getComponentMetadata(),
t );
+                return "disableComponent(" + name + ")";
             }
-        }
+        } );
     }
 
 
@@ -502,7 +537,7 @@ public class BundleComponentActivator im
      *
      * @param task The component task to execute
      */
-    public void schedule( ComponentActivatorTask task )
+    public void schedule( Runnable task )
     {
         if ( isActive() )
         {

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=949317&r1=949316&r2=949317&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
Fri May 28 23:13:05 2010
@@ -30,7 +30,6 @@ import java.util.List;
 import org.apache.felix.scr.Component;
 import org.apache.felix.scr.Reference;
 import org.apache.felix.scr.impl.BundleComponentActivator;
-import org.apache.felix.scr.impl.ComponentActivatorTask;
 import org.apache.felix.scr.impl.metadata.ComponentMetadata;
 import org.apache.felix.scr.impl.metadata.ReferenceMetadata;
 import org.apache.felix.scr.impl.metadata.ServiceMetadata;
@@ -126,37 +125,24 @@ public abstract class AbstractComponentM
      * This method ignores the <i>enabled</i> flag of the component metadata
      * and just enables as requested.
      * <p>
-     * This method schedules the enablement for asynchronous execution.
+     * This method enables and activates the component immediately.
      */
     public final void enable()
     {
         enableInternal();
-
-        getActivator().schedule( new ComponentActivatorTask( "Enable", this )
-        {
-            public void doRun()
-            {
-                activateInternal();
-            }
-        });
+        activateInternal();
     }
 
     /**
      * Disables this component and - if active - first deactivates it. The
      * component may be reenabled by calling the {@link #enable()} method.
      * <p>
-     * This method schedules the disablement for asynchronous execution.
+     * This method deactivates and disables the component immediately.
      */
     public final void disable()
     {
-        getActivator().schedule( new ComponentActivatorTask( "Disable", this )
-        {
-            public void doRun()
-            {
-                deactivateInternal( ComponentConstants.DEACTIVATION_REASON_DISABLED );
-                disableInternal();
-            }
-        });
+        deactivateInternal( ComponentConstants.DEACTIVATION_REASON_DISABLED );
+        disableInternal();
     }
 
     /**
@@ -522,42 +508,6 @@ public abstract class AbstractComponentM
         }
     }
 
-    /**
-     * Activates this component if satisfied. If any of the dependencies is
-     * not met, the component is not activated and remains unsatisfied.
-     * <p>
-     * This method schedules the activation for asynchronous execution.
-     */
-    public final void activate()
-    {
-        getActivator().schedule( new ComponentActivatorTask( "Activate", this ) {
-            public void doRun()
-            {
-                activateInternal();
-            }
-        });
-    }
-
-    /**
-     * Cycles this component by deactivating it and - if still satisfied -
-     * activating it again asynchronously.
-     * <p>
-     * This method schedules the deactivation and reactivation for asynchronous
-     * execution.
-     */
-    public final void reactivate( final int reason )
-    {
-        getActivator().schedule( new ComponentActivatorTask( "Reactivate", this )
-        {
-
-            public void doRun()
-            {
-                deactivateInternal( reason );
-                activateInternal();
-            }
-        } );
-    }
-
 
     public String toString()
     {

Modified: felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/DependencyManager.java
URL: http://svn.apache.org/viewvc/felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/DependencyManager.java?rev=949317&r1=949316&r2=949317&view=diff
==============================================================================
--- felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/DependencyManager.java
(original)
+++ felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/DependencyManager.java
Fri May 28 23:13:05 2010
@@ -203,7 +203,8 @@ public class DependencyManager implement
                                     "Dependency Manager: Service {0} registered, activate
component", new Object[]
                                         { m_dependencyMetadata.getName() }, null );
 
-                                m_componentManager.activate();
+                                // immediately try to activate the component (FELIX-2368)
+                                m_componentManager.activateInternal();
                             }
                         }
                         else if ( isMultiple() )
@@ -278,7 +279,8 @@ public class DependencyManager implement
                 "Dependency Manager: Service {0} registered, activate component", new Object[]
                     { m_dependencyMetadata.getName() }, null );
 
-            m_componentManager.activate();
+            // immediately try to activate the component (FELIX-2368)
+            m_componentManager.activateInternal();
         }
 
         // otherwise check whether the component is in a state to handle the event
@@ -365,7 +367,8 @@ public class DependencyManager implement
                         "Dependency Manager: Static dependency on {0}/{1} is broken", new
Object[]
                             { m_dependencyMetadata.getName(), m_dependencyMetadata.getInterface()
}, null );
                     m_componentManager.deactivateInternal( ComponentConstants.DEACTIVATION_REASON_REFERENCE
);
-                    m_componentManager.activate();
+                    // FELIX-2368: immediately try to reactivate
+                    m_componentManager.activateInternal();
                 }
                 catch ( Exception ex )
                 {

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=949317&r1=949316&r2=949317&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
Fri May 28 23:13:05 2010
@@ -404,7 +404,12 @@ public class ImmediateComponentManager e
             log( LogService.LOG_DEBUG, "Deactivating and Activating to reconfigure from configuration",
null );
             int reason = ( configuration == null ) ? ComponentConstants.DEACTIVATION_REASON_CONFIGURATION_DELETED
                 : ComponentConstants.DEACTIVATION_REASON_CONFIGURATION_MODIFIED;
-            reactivate( reason );
+
+            // FELIX-2368: cycle component immediately, reconfigure() is
+            //     called through ConfigurationListener API which itself is
+            //     called asynchronously by the Configuration Admin Service
+            deactivateInternal( reason );
+            activateInternal();
         }
     }
 



Mime
View raw message