felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r1792003 - in /felix/trunk/scr: changelog.txt src/main/java/org/apache/felix/scr/impl/inject/FieldHandler.java src/main/java/org/apache/felix/scr/impl/manager/ComponentContextImpl.java
Date Wed, 19 Apr 2017 23:20:20 GMT
Author: cziegeler
Date: Wed Apr 19 23:20:20 2017
New Revision: 1792003

URL: http://svn.apache.org/viewvc?rev=1792003&view=rev
Log:
FELIX-5572 : Reference target filter fails when using field strategy for multiple cardinality
reference with multiple component instances

Modified:
    felix/trunk/scr/changelog.txt
    felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/inject/FieldHandler.java
    felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/ComponentContextImpl.java

Modified: felix/trunk/scr/changelog.txt
URL: http://svn.apache.org/viewvc/felix/trunk/scr/changelog.txt?rev=1792003&r1=1792002&r2=1792003&view=diff
==============================================================================
--- felix/trunk/scr/changelog.txt (original)
+++ felix/trunk/scr/changelog.txt Wed Apr 19 23:20:20 2017
@@ -1,3 +1,11 @@
+Changes from 2.0.8 to 2.0.10
+----------------------------
+** Improvement
+    * [FELIX-5568] SCR contains compact3 profile code
+** Bug
+    * [FELIX-5572] Reference target filter fails when using field strategy for multiple cardinality
reference with multiple component instances
+
+
 Changes from 2.0.6 to 2.0.8
 ---------------------------
 ** Improvement

Modified: felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/inject/FieldHandler.java
URL: http://svn.apache.org/viewvc/felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/inject/FieldHandler.java?rev=1792003&r1=1792002&r2=1792003&view=diff
==============================================================================
--- felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/inject/FieldHandler.java (original)
+++ felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/inject/FieldHandler.java Wed Apr
19 23:20:20 2017
@@ -26,10 +26,8 @@ import java.security.AccessController;
 import java.security.PrivilegedAction;
 import java.util.ArrayList;
 import java.util.Collection;
-import java.util.Comparator;
 import java.util.List;
 import java.util.Map;
-import java.util.TreeMap;
 import java.util.concurrent.CopyOnWriteArrayList;
 import java.util.concurrent.CopyOnWriteArraySet;
 
@@ -74,17 +72,6 @@ public class FieldHandler
     /** State handling. */
     private volatile State state;
 
-    /** Mapping of ref pairs to value bound */
-    private final Map<RefPair<?, ?>, Object> boundValues = new TreeMap<RefPair<?,?>,
Object>(
-        new Comparator<RefPair<?, ?>>()
-        {
-
-            public int compare(final RefPair<?, ?> o1, final RefPair<?, ?> o2)
-            {
-                return o1.getRef().compareTo(o2.getRef());
-            }
-        });
-
     /**
      * Create a new field handler
      * @param fieldName name of the field
@@ -428,21 +415,25 @@ public class FieldHandler
             this.ref = ref;
         }
 
+        @Override
         public Object getKey()
         {
             return this.key;
         }
 
+        @Override
         public Object getValue()
         {
             return this.value;
         }
 
+        @Override
         public Object setValue(final Object value)
         {
             throw new UnsupportedOperationException();
         }
 
+        @Override
         public int compareTo(final Map.Entry<?, ?> o)
         {
             if ( o == null )
@@ -551,10 +542,10 @@ public class FieldHandler
         return true;
     }
 
-    private Collection<Object> getReplaceCollection()
+    private Collection<Object> getReplaceCollection(final BindParameters bp)
     {
         final List<Object> objects = new ArrayList<Object>();
-        for(final Object val : this.boundValues.values())
+        for(final Object val : bp.getComponentContext().getBoundValues(metadata.getName()).values())
         {
             objects.add(val);
         }
@@ -580,12 +571,12 @@ public class FieldHandler
                 if ( this.metadata.isOptional() && !this.metadata.isStatic() )
                 {
                     // we only reset if it was previously set with this value
-                    if ( this.boundValues.size() == 1 )
+                    if ( bp.getComponentContext().getBoundValues(metadata.getName()).size()
== 1 )
                     {
                         this.setFieldValue(componentInstance, null);
                     }
                 }
-                this.boundValues.remove(refPair);
+                bp.getComponentContext().getBoundValues(metadata.getName()).remove(refPair);
             }
             // updated needs only be done, if the value type is map or tuple
             // If it's a dynamic reference, the value can be updated
@@ -600,7 +591,7 @@ public class FieldHandler
             		}
                     final Object obj = getValue(key, refPair);
                     this.setFieldValue(componentInstance, obj);
-                    this.boundValues.put(refPair, obj);
+                    bp.getComponentContext().getBoundValues(metadata.getName()).put(refPair,
obj);
             	}
             }
             // bind needs always be done
@@ -608,7 +599,7 @@ public class FieldHandler
             {
                 final Object obj = getValue(key, refPair);
                 this.setFieldValue(componentInstance, obj);
-                this.boundValues.put(refPair, obj);
+                bp.getComponentContext().getBoundValues(metadata.getName()).put(refPair,
obj);
             }
         }
         else
@@ -619,10 +610,10 @@ public class FieldHandler
             if ( mType == METHOD_TYPE.BIND )
             {
                 final Object obj = getValue(key, refPair);
-                this.boundValues.put(refPair, obj);
+                bp.getComponentContext().getBoundValues(metadata.getName()).put(refPair,
obj);
                 if ( metadata.isReplace() )
                 {
-                    this.setFieldValue(componentInstance, getReplaceCollection());
+                    this.setFieldValue(componentInstance, getReplaceCollection(bp));
                 }
                 else
                 {
@@ -636,10 +627,10 @@ public class FieldHandler
             {
                 if ( !metadata.isStatic() )
                 {
-                    final Object obj = this.boundValues.remove(refPair);
+                    final Object obj = bp.getComponentContext().getBoundValues(metadata.getName()).remove(refPair);
                     if ( metadata.isReplace() )
                     {
-                        this.setFieldValue(componentInstance, getReplaceCollection());
+                        this.setFieldValue(componentInstance, getReplaceCollection(bp));
                     }
                     else
                     {
@@ -657,11 +648,11 @@ public class FieldHandler
                     if ( !this.metadata.isStatic() )
                     {
 	                    final Object obj = getValue(key, refPair);
-	                    final Object oldObj = this.boundValues.put(refPair, obj);
+	                    final Object oldObj = bp.getComponentContext().getBoundValues(metadata.getName()).put(refPair,
obj);
 
 	                    if ( metadata.isReplace() )
 	                    {
-	                        this.setFieldValue(componentInstance, getReplaceCollection());
+	                        this.setFieldValue(componentInstance, getReplaceCollection(bp));
 	                    }
 	                    else
 	                    {
@@ -783,6 +774,7 @@ public class FieldHandler
     {
         AccessController.doPrivileged( new PrivilegedAction<Object>()
         {
+            @Override
             public Object run()
             {
                 field.setAccessible( true );
@@ -848,6 +840,7 @@ public class FieldHandler
             handler.setField( field, logger );
         }
 
+        @Override
         public MethodResult invoke( final FieldHandler handler,
                 final METHOD_TYPE mType,
                 final Object componentInstance,
@@ -859,6 +852,7 @@ public class FieldHandler
             return handler.state.invoke( handler, mType, componentInstance, rawParameter,
logger );
         }
 
+        @Override
         public boolean fieldExists( final FieldHandler handler, final SimpleLogger logger)
         {
             resolve( handler, logger );
@@ -873,6 +867,7 @@ public class FieldHandler
     {
         private static final State INSTANCE = new NotFound();
 
+        @Override
         public MethodResult invoke( final FieldHandler handler,
                 final METHOD_TYPE mType,
                 final Object componentInstance,
@@ -884,6 +879,7 @@ public class FieldHandler
             return null;
         }
 
+        @Override
         public boolean fieldExists( final FieldHandler handler, final SimpleLogger logger)
         {
             return false;
@@ -897,6 +893,7 @@ public class FieldHandler
     {
         private static final State INSTANCE = new Resolved();
 
+        @Override
         public MethodResult invoke( final FieldHandler handler,
                 final METHOD_TYPE mType,
                 final Object componentInstance,
@@ -907,6 +904,7 @@ public class FieldHandler
             return handler.updateField( mType, componentInstance, rawParameter, logger );
         }
 
+        @Override
         public boolean fieldExists( final FieldHandler handler, final SimpleLogger logger)
         {
             return true;
@@ -932,6 +930,7 @@ public class FieldHandler
             this.handler = handler;
         }
 
+        @Override
         public MethodResult invoke(Object componentInstance,
                                    ComponentContextImpl<?> componentContext,
                                    RefPair<?, ?> refPair,
@@ -970,6 +969,7 @@ public class FieldHandler
             return methodCallFailureResult;
         }
 
+        @Override
         public <S, T> boolean getServiceObject(final ComponentContextImpl<S>
key,
                 final RefPair<S, T> refPair,
                 final BundleContext context,
@@ -1013,6 +1013,7 @@ public class FieldHandler
         return new InitReferenceMethod()
         {
 
+            @Override
             public boolean init(final Object componentInstance, final SimpleLogger logger)
             {
                 if ( fieldExists( logger ) )

Modified: felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/ComponentContextImpl.java
URL: http://svn.apache.org/viewvc/felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/ComponentContextImpl.java?rev=1792003&r1=1792002&r2=1792003&view=diff
==============================================================================
--- felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/ComponentContextImpl.java
(original)
+++ felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/ComponentContextImpl.java
Wed Apr 19 23:20:20 2017
@@ -19,7 +19,11 @@
 package org.apache.felix.scr.impl.manager;
 
 
+import java.util.Comparator;
 import java.util.Dictionary;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.TreeMap;
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.TimeUnit;
 
@@ -47,7 +51,7 @@ public class ComponentContextImpl<S> imp
     private final ComponentInstance m_componentInstance = new ComponentInstanceImpl<S>(this);
 
     private final Bundle m_usingBundle;
-    
+
     private volatile ServiceRegistration<S> m_serviceRegistration;
 
     private volatile S m_implementationObject;
@@ -58,6 +62,11 @@ public class ComponentContextImpl<S> imp
 
     private final ComponentServiceObjectsHelper serviceObjectsHelper;
 
+    /** Mapping of ref pairs to value bound */
+    private Map<String, Map<RefPair<?, ?>, Object>> boundValues;
+
+
+
     public ComponentContextImpl( final SingleComponentManager<S> componentManager,
final Bundle usingBundle, ServiceRegistration<S> serviceRegistration )
     {
         m_componentManager = componentManager;
@@ -70,7 +79,7 @@ public class ComponentContextImpl<S> imp
         }
         this.serviceObjectsHelper = new ComponentServiceObjectsHelper(usingBundle.getBundleContext());
     }
-    
+
     public void unsetServiceRegistration() {
         m_serviceRegistration = null;
     }
@@ -116,6 +125,7 @@ public class ComponentContextImpl<S> imp
         return m_componentManager;
     }
 
+    @Override
     public final Dictionary<String, Object> getProperties()
     {
         // 112.12.3.5 The Dictionary is read-only and cannot be modified
@@ -123,6 +133,7 @@ public class ComponentContextImpl<S> imp
     }
 
 
+    @Override
     public Object locateService( String name )
     {
         m_componentManager.obtainActivationReadLock( );
@@ -138,6 +149,7 @@ public class ComponentContextImpl<S> imp
     }
 
 
+    @Override
     public Object locateService( String name, ServiceReference ref )
     {
         m_componentManager.obtainActivationReadLock(  );
@@ -153,6 +165,7 @@ public class ComponentContextImpl<S> imp
     }
 
 
+    @Override
     public Object[] locateServices( String name )
     {
         m_componentManager.obtainActivationReadLock(  );
@@ -168,24 +181,28 @@ public class ComponentContextImpl<S> imp
     }
 
 
+    @Override
     public BundleContext getBundleContext()
     {
         return m_componentManager.getBundleContext();
     }
 
 
+    @Override
     public Bundle getUsingBundle()
     {
         return m_usingBundle;
     }
 
 
+    @Override
     public ComponentInstance getComponentInstance()
     {
         return m_componentInstance;
     }
 
 
+    @Override
     public void enableComponent( String name )
     {
         ComponentActivator activator = m_componentManager.getActivator();
@@ -196,6 +213,7 @@ public class ComponentContextImpl<S> imp
     }
 
 
+    @Override
     public void disableComponent( String name )
     {
         ComponentActivator activator = m_componentManager.getActivator();
@@ -206,6 +224,7 @@ public class ComponentContextImpl<S> imp
     }
 
 
+    @Override
     public ServiceReference<S> getServiceReference()
     {
         return m_serviceRegistration == null? null: m_serviceRegistration.getReference();
@@ -214,6 +233,7 @@ public class ComponentContextImpl<S> imp
 
     //---------- Speculative MutableProperties interface ------------------------------
 
+    @Override
     public void setServiceProperties(Dictionary<String, ?> properties)
     {
         getComponentManager().setServiceProperties(properties );
@@ -263,12 +283,14 @@ public class ComponentContextImpl<S> imp
         }
 
 
+        @Override
         public Object getInstance()
         {
             return m_componentContext.getImplementationObject(true);
         }
 
 
+        @Override
         public void dispose()
         {
             m_componentContext.getComponentManager().dispose();
@@ -276,4 +298,32 @@ public class ComponentContextImpl<S> imp
 
     }
 
+    public synchronized Map<RefPair<?, ?>, Object> getBoundValues(final String
key)
+    {
+        if ( this.boundValues == null )
+        {
+            this.boundValues = new HashMap<String, Map<RefPair<?,?>,Object>>();
+        }
+        Map<RefPair<?, ?>, Object> map = this.boundValues.get(key);
+        if ( map == null )
+        {
+            map = createNewFieldHandlerMap();
+            this.boundValues.put(key, map);
+        }
+        return map;
+    }
+
+    private Map<RefPair<?, ?>, Object> createNewFieldHandlerMap()
+    {
+        return new TreeMap<RefPair<?,?>, Object>(
+            new Comparator<RefPair<?, ?>>()
+            {
+
+                @Override
+                public int compare(final RefPair<?, ?> o1, final RefPair<?, ?>
o2)
+                {
+                    return o1.getRef().compareTo(o2.getRef());
+                }
+            });
+    }
 }



Mime
View raw message