felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From djen...@apache.org
Subject svn commit: r1424316 - in /felix/trunk/scr/src/main/java/org/apache/felix/scr/impl: config/ImmediateComponentHolder.java manager/AbstractComponentManager.java manager/DependencyManager.java
Date Thu, 20 Dec 2012 04:53:27 GMT
Author: djencks
Date: Thu Dec 20 04:53:27 2012
New Revision: 1424316

URL: http://svn.apache.org/viewvc?rev=1424316&view=rev
Log:
FELIX-3729 register the dependency manager service listeners during activate

Modified:
    felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/config/ImmediateComponentHolder.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

Modified: felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/config/ImmediateComponentHolder.java
URL: http://svn.apache.org/viewvc/felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/config/ImmediateComponentHolder.java?rev=1424316&r1=1424315&r2=1424316&view=diff
==============================================================================
--- felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/config/ImmediateComponentHolder.java
(original)
+++ felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/config/ImmediateComponentHolder.java
Thu Dec 20 04:53:27 2012
@@ -297,12 +297,26 @@ public class ImmediateComponentHolder im
                 }
 
                 // configure the component
+                log( LogService.LOG_DEBUG, "ImmediateComponentHolder About to actually configure
the dependency managers for component for pid {0} ",
+                        new Object[] {pid}, null );
                 newIcm.reconfigure( props );
+                log( LogService.LOG_DEBUG, "ImmediateComponentHolder Finished configuring
the dependency managers for component for pid {0} ",
+                        new Object[] {pid}, null );
 
                 // enable the component if it is initially enabled
                 if ( m_enabled && getComponentMetadata().isEnabled() )
                 {
+                    log( LogService.LOG_DEBUG, "ImmediateComponentHolder About to enable
component for pid {0} ",
+                            new Object[] {pid}, null );
                     newIcm.enable( false );
+                    log( LogService.LOG_DEBUG, "ImmediateComponentHolder Finished enabling
component for pid {0} ",
+                            new Object[] {pid}, null );
+                }
+                else
+                {
+                    log( LogService.LOG_DEBUG, "ImmediateComponentHolder Will not enable
component for pid {0}: holder enabled state: {1}, metadata enabled: {2} ",
+                            new Object[] {pid, m_enabled, getComponentMetadata().isEnabled()},
null );
+
                 }
 
                 // store the component in the map

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=1424316&r1=1424315&r2=1424316&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
Thu Dec 20 04:53:27 2012
@@ -97,6 +97,8 @@ public abstract class AbstractComponentM
     protected volatile boolean enabled;
     protected volatile CountDownLatch enabledLatch;
     private final Object enabledLatchLock = new Object();
+
+    protected volatile boolean m_internalEnabled;
     /**
      * synchronizing while creating the service registration is safe as long as the bundle
is not stopped
      * during some service registrations.  So, avoid synchronizing during unregister service
if the component is being
@@ -587,6 +589,7 @@ public abstract class AbstractComponentM
     final void enableInternal()
     {
         m_state.enable( this );
+        m_internalEnabled = true;
     }
 
     final boolean activateInternal( int trackingCount )
@@ -601,6 +604,7 @@ public abstract class AbstractComponentM
 
     final void disableInternal()
     {
+        m_internalEnabled = false;
         m_state.disable( this );
     }
 
@@ -966,20 +970,20 @@ public abstract class AbstractComponentM
 
     private void enableDependencyManagers() throws InvalidSyntaxException
     {
-        if ( !m_componentMetadata.isConfigurationRequired() )
+        if ( !m_componentMetadata.isConfigurationRequired() || hasConfiguration() )
         {
-            for ( DependencyManager dm: getDependencyManagers() )
-            {
-                dm.enable();
-            }
+            updateTargets( getProperties() );
         }
     }
 
     protected void updateTargets(Dictionary properties)
     {
-        for ( DependencyManager dm: getDependencyManagers() )
+        if ( m_internalEnabled )
         {
-            dm.setTargetFilter( properties );
+            for ( DependencyManager dm: getDependencyManagers() )
+            {
+                dm.setTargetFilter( properties );
+            }
         }
     }
 
@@ -1358,20 +1362,8 @@ public abstract class AbstractComponentM
             }
 
             acm.registerComponentId();
-            try
-            {
-                acm.enableDependencyManagers();
-                acm.changeState( Unsatisfied.getInstance() );
-                acm.log( LogService.LOG_DEBUG, "Component enabled", null );
-            }
-            catch ( InvalidSyntaxException ise )
-            {
-                // one of the reference target filters is invalid, fail
-                acm.log( LogService.LOG_ERROR, "Failed enabling Component", ise );
-                acm.disableDependencyManagers();
-                acm.unregisterComponentId();
-                acm.changeState( Disabled.getInstance() );
-            }
+            acm.changeState( Unsatisfied.getInstance() );
+            acm.log( LogService.LOG_DEBUG, "Component enabled", null );
         }
 
         void deactivate( AbstractComponentManager acm, int reason, boolean disable )

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=1424316&r1=1424315&r2=1424316&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
Thu Dec 20 04:53:27 2012
@@ -879,6 +879,58 @@ public class DependencyManager<S, T> imp
         }
     }
 
+    private class NoPermissionsCustomizer implements Customizer<T>
+    {
+
+        public boolean open()
+        {
+            return false;
+        }
+
+        public void close()
+        {
+        }
+
+        public Collection<RefPair<T>> getRefs( AtomicInteger trackingCount )
+        {
+            return null;
+        }
+
+        public boolean isSatisfied()
+        {
+            return isOptional();
+        }
+
+        public void setTracker( ServiceTracker<T, RefPair<T>> tRefPairServiceTracker
)
+        {
+        }
+
+        public void setTrackerOpened()
+        {
+        }
+
+        public void setPreviousRefMap( Map<ServiceReference<T>, RefPair<T>>
previousRefMap )
+        {
+        }
+
+        public RefPair<T> addingService( ServiceReference<T> tServiceReference
)
+        {
+            return null;
+        }
+
+        public void addedService( ServiceReference<T> tServiceReference, RefPair<T>
service, int trackingCount )
+        {
+        }
+
+        public void modifiedService( ServiceReference<T> tServiceReference, RefPair<T>
service, int trackingCount )
+        {
+        }
+
+        public void removedService( ServiceReference<T> tServiceReference, RefPair<T>
service, int trackingCount )
+        {
+        }
+    }
+
     //---------- Reference interface ------------------------------------------
 
     public String getServiceName()
@@ -928,31 +980,6 @@ public class DependencyManager<S, T> imp
 
     //---------- Service tracking support -------------------------------------
 
-    /**
-     * Enables this dependency manager by starting to listen for service
-     * events.
-     * @throws InvalidSyntaxException if the target filter is invalid
-     */
-    void enable() throws InvalidSyntaxException
-    {
-        if ( hasGetPermission() )
-        {
-            // setup the target filter from component descriptor
-            setTargetFilter( m_dependencyMetadata.getTarget() );
-
-            m_componentManager.log( LogService.LOG_DEBUG,
-                    "Registered for service events, currently {0} service(s) match the filter",
new Object[]
-                    {new Integer( size() )}, null );
-        }
-        else
-        {
-            // no services available
-            m_componentManager.log( LogService.LOG_DEBUG,
-                    "Not registered for service events since the bundle has no permission
to get service {0}", new Object[]
-                    {m_dependencyMetadata.getInterface()}, null );
-        }
-    }
-
 
     void deactivate()
     {
@@ -1684,8 +1711,20 @@ public class DependencyManager<S, T> imp
      * @param target The new target filter to be set. This may be
      *      <code>null</code> if no target filtering is to be used.
      */
-    private void setTargetFilter( String target ) throws InvalidSyntaxException
+    private void setTargetFilter( String target) throws InvalidSyntaxException
     {
+        if (!hasGetPermission())
+        {
+            customizerRef.set( new NoPermissionsCustomizer() );
+            m_componentManager.log( LogService.LOG_INFO, "No permission to get services for
{0}", new Object[]
+                    {m_dependencyMetadata.getName()}, null );
+            return;
+        }
+        // if configuration does not set filter, use the value from metadata
+        if (target == null)
+        {
+            target = m_dependencyMetadata.getTarget();
+        }
         // do nothing if target filter does not change
         if ( ( m_target == null && target == null ) || ( m_target != null &&
m_target.equals( target ) ) )
         {



Mime
View raw message