Author: djencks
Date: Tue Feb 23 01:38:34 2016
New Revision: 1731776

URL: http://svn.apache.org/viewvc?rev=1731776&view=rev
Log:
FELIX-5194 Actually pay attention to whether change count changes, and insist 
on R5 ca

Modified:
    felix/trunk/scr/bnd.bnd
    
felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/config/ComponentHolder.java
    
felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/config/ConfigurableComponentHolder.java
    
felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/config/RegionConfigurationSupport.java

Modified: felix/trunk/scr/bnd.bnd
URL: 
http://svn.apache.org/viewvc/felix/trunk/scr/bnd.bnd?rev=1731776&r1=1731775&r2=1731776&view=diff
==============================================================================
--- felix/trunk/scr/bnd.bnd (original)
+++ felix/trunk/scr/bnd.bnd Tue Feb 23 01:38:34 2016
@@ -30,7 +30,7 @@ Private-Package: org.apache.felix.scr.im
 # optional import for Gogo annotations 
 # The Felix Shell support is optional 
 Import-Package: \
- org.osgi.service.cm;version="[1.2,2)";resolution:=optional, \
+ org.osgi.service.cm;version="[1.5,2)";resolution:=optional, \
  org.osgi.service.log;version="[1.3,2)";resolution:=optional, \
  org.osgi.service.metatype;version="[1.1,2)";resolution:=optional, \
  org.osgi.service.packageadmin;version="[1.2,2)";resolution:=optional, \

Modified: 
felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/config/ComponentHolder.java
URL: 
http://svn.apache.org/viewvc/felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/config/ComponentHolder.java?rev=1731776&r1=1731775&r2=1731776&view=diff
==============================================================================
--- 
felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/config/ComponentHolder.java
 (original)
+++ 
felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/config/ComponentHolder.java
 Tue Feb 23 01:38:34 2016
@@ -76,14 +76,6 @@ public interface ComponentHolder<S>
     boolean configurationUpdated( TargetedPID targetedPid, TargetedPID 
factoryTargetedPid, Dictionary<String, Object> props, long changeCount );
     
     /**
-     * Change count (or fake R4 imitation)
-     * @param pid a PID for the component we are interested in.
-     * @param targetedPid For a singleton pid, same as "pid"; for a factory 
pid, the factory pid.
-     * @return the last change count from a configurationUpdated call for the 
given pid.
-     */
-    long getChangeCount( TargetedPID pid, TargetedPID targetedPid );
-    
-    /**
      * Returns the targeted PID used to configure this component
      * @param pid a targetedPID containing the service pid for the component 
desired (the rest of the targeted pid is ignored)
      * @param factoryPid a targetedPID containing the factory pid for the 
component desired.

Modified: 
felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/config/ConfigurableComponentHolder.java
URL: 
http://svn.apache.org/viewvc/felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/config/ConfigurableComponentHolder.java?rev=1731776&r1=1731775&r2=1731776&view=diff
==============================================================================
--- 
felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/config/ConfigurableComponentHolder.java
 (original)
+++ 
felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/config/ConfigurableComponentHolder.java
 Tue Feb 23 01:38:34 2016
@@ -351,14 +351,18 @@ public class ConfigurableComponentHolder
         final Map<AbstractComponentManager<S>, Map<String, Object>> scms = new 
HashMap< AbstractComponentManager<S>, Map<String, Object>>();
         boolean created = false;
 
-        //TODO better change count tracking
         synchronized (m_components) {
             //Find or create the component manager, or return if not satisfied.
             if (factoryPid != null) {
                 checkFactoryPidIndex(factoryPid);
+                Long oldChangeCount = 
m_factoryChangeCount.get(pid.getServicePid());
+                TargetedPID oldTargetedPID = 
m_factoryTargetedPids.get(pid.getServicePid());
+                if (oldChangeCount != null && changeCount <= oldChangeCount && 
factoryPid.equals(oldTargetedPID)) {
+                       return false;
+                }
+                m_factoryChangeCount.put(pid.getServicePid(), changeCount);
                 m_factoryConfigurations.put(pid.getServicePid(), props);
                 m_factoryTargetedPids.put(pid.getServicePid(), factoryPid);
-                m_factoryChangeCount.put(pid.getServicePid(), changeCount);
                 if (m_enabled && isSatisfied()) {
                     if (m_singleComponent != null && 
!m_componentMetadata.isObsoleteFactoryComponentFactory()) {
                         AbstractComponentManager<S> scm = m_singleComponent;
@@ -380,8 +384,11 @@ public class ConfigurableComponentHolder
             } else {
                 //singleton pid
                 int index = getSingletonPidIndex(pid);
-                m_targetedPids[index] = pid;
+                if (m_changeCount[index] != null && changeCount <= 
m_changeCount[index] && pid.equals(m_targetedPids[index])) {
+                       return false;
+                }
                 m_changeCount[index] = changeCount;
+                m_targetedPids[index] = pid;
                 m_configurations[index] = props;
                 if (m_enabled && isSatisfied()) {
                     if (m_singleComponent != null) {
@@ -570,31 +577,6 @@ public class ConfigurableComponentHolder
         return true;
     }
 
-    /**
-     * @param pid the Targeted PID we need the change count for
-     * @param targetedPid the targeted factory pid for a factory configuration 
or the pid for a singleton configuration
-     * @return pid for this service pid.
-     */
-    public long getChangeCount( TargetedPID pid, TargetedPID targetedPid)
-    {
-        int index = m_componentMetadata.getPidIndex(targetedPid);
-        Long result;
-        if ( index == -1 )
-        {
-            throw new IllegalArgumentException("pid not recognized as for this 
component: " + pid);
-        }
-        if ( m_factoryPidIndex != null && index == m_factoryPidIndex )
-        {
-            result = m_factoryChangeCount.get(pid.getServicePid());
-        }
-        else
-        {
-            result = m_changeCount[index];
-        }
-        return result == null? -1: result;
-
-    }
-
     public List<? extends ComponentManager<?>> getComponents()
         {
         synchronized ( m_components )

Modified: 
felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/config/RegionConfigurationSupport.java
URL: 
http://svn.apache.org/viewvc/felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/config/RegionConfigurationSupport.java?rev=1731776&r1=1731775&r2=1731776&view=diff
==============================================================================
--- 
felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/config/RegionConfigurationSupport.java
 (original)
+++ 
felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/config/RegionConfigurationSupport.java
 Tue Feb 23 01:38:34 2016
@@ -49,28 +49,6 @@ import org.osgi.util.tracker.ServiceTrac
 public class RegionConfigurationSupport implements ConfigurationListener
 {
 
-    private static final ChangeCount changeCounter;
-    static
-    {
-        ChangeCount cc = null;
-        try
-        {
-            Configuration.class.getMethod( "getChangeCount", (Class<?>[]) null 
);
-            cc = new R5ChangeCount();
-        }
-        catch ( SecurityException e )
-        {
-        }
-        catch ( NoSuchMethodException e )
-        {
-        }
-        if ( cc == null )
-        {
-            cc = new R4ChangeCount();
-        }
-        changeCounter = cc;
-    }
-
     private final BundleContext caBundleContext;
     private final Long bundleId;
     
@@ -175,7 +153,7 @@ public class RegionConfigurationSupport
                                         config = getConfiguration( ca, 
config.getPid() );
                                         if ( checkBundleLocation( config, 
bundleContext.getBundle() ) )
                                         {
-                                            long changeCount = 
changeCounter.getChangeCount( config, false, -1 );
+                                            long changeCount = 
config.getChangeCount();
                                             created |= 
holder.configurationUpdated( new TargetedPID( config.getPid() ),
                                                        new TargetedPID( 
config.getFactoryPid() ),
                                                     config.getProperties(),
@@ -201,7 +179,7 @@ public class RegionConfigurationSupport
                                         if ( singleton != null
                                                 && checkBundleLocation( 
singleton, bundleContext.getBundle() ) )
                                         {
-                                            long changeCount = 
changeCounter.getChangeCount( singleton, false, -1 );
+                                            long changeCount = 
singleton.getChangeCount();
                                             holder.configurationUpdated( new 
TargetedPID( singleton.getPid() ), null,
                                                     singleton.getProperties(), 
changeCount );
                                         }
@@ -504,7 +482,7 @@ public class RegionConfigurationSupport
                             final ConfigurationAdmin ca = ( ConfigurationAdmin 
) cao;
                             final Configuration config = getConfiguration( ca, 
pid.getRawPid() );
                             return new 
ConfigurationInfo(config.getProperties(), config.getBundleLocation(),
-                                    changeCounter.getChangeCount( config, 
true, componentHolder.getChangeCount( pid, targetedPid ) ) );
+                                       config.getChangeCount());
                         }
                         else
                         {
@@ -687,26 +665,4 @@ public class RegionConfigurationSupport
         return value.replaceAll( "([\\\\\\*\\(\\)])", "\\\\$1" );
     }
 
-
-    private interface ChangeCount {
-        long getChangeCount( Configuration configuration, boolean fromEvent, 
long previous );
-    }
-
-    private static class R5ChangeCount implements ChangeCount {
-
-        public long getChangeCount(Configuration configuration, boolean 
fromEvent, long previous)
-        {
-            return configuration.getChangeCount();
-        }
-    }
-
-    private static class R4ChangeCount implements ChangeCount {
-
-        public long getChangeCount(Configuration configuration, boolean 
fromEvent, long previous)
-        {
-            return fromEvent? previous + 1:0;
-        }
-
-    }
-
 }


Reply via email to