felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pde...@apache.org
Subject svn commit: r1776213 - in /felix/trunk/dependencymanager/org.apache.felix.dependencymanager/src/org/apache/felix/dm/impl/index/multiproperty: MultiPropertyFilterIndex.java Property.java
Date Tue, 27 Dec 2016 23:21:18 GMT
Author: pderop
Date: Tue Dec 27 23:21:18 2016
New Revision: 1776213

URL: http://svn.apache.org/viewvc?rev=1776213&view=rev
Log:
FELIX-5467: Do not create permutation of values for a service property if you specify a "#"
in the filterindex system property 
(Applied patch provided by Jeroen, thank you).

For example, if you use the following configuration:

 org.apache.felix.dependencymanager.filterindex='objectClass,#foo'

and if a service is registered with a foo property having ["bar1", "bar2"] String array value,
then 
the following keys will be used: "[foo=bar1, foo=bar2]".

Without the patch, all keys permutation were used: "[foo=bar1, foo=bar1;foo=bar2, foo=bar2]"


Modified:
    felix/trunk/dependencymanager/org.apache.felix.dependencymanager/src/org/apache/felix/dm/impl/index/multiproperty/MultiPropertyFilterIndex.java
    felix/trunk/dependencymanager/org.apache.felix.dependencymanager/src/org/apache/felix/dm/impl/index/multiproperty/Property.java

Modified: felix/trunk/dependencymanager/org.apache.felix.dependencymanager/src/org/apache/felix/dm/impl/index/multiproperty/MultiPropertyFilterIndex.java
URL: http://svn.apache.org/viewvc/felix/trunk/dependencymanager/org.apache.felix.dependencymanager/src/org/apache/felix/dm/impl/index/multiproperty/MultiPropertyFilterIndex.java?rev=1776213&r1=1776212&r2=1776213&view=diff
==============================================================================
--- felix/trunk/dependencymanager/org.apache.felix.dependencymanager/src/org/apache/felix/dm/impl/index/multiproperty/MultiPropertyFilterIndex.java
(original)
+++ felix/trunk/dependencymanager/org.apache.felix.dependencymanager/src/org/apache/felix/dm/impl/index/multiproperty/MultiPropertyFilterIndex.java
Tue Dec 27 23:21:18 2016
@@ -115,6 +115,9 @@ public class MultiPropertyFilterIndex im
 			if (propertyConfig.startsWith("!")) {
 				property.setNegate(true);
 				key = propertyConfig.substring(1);
+			} else if (propertyConfig.startsWith("#")) {
+				property.setPermute(false);
+				key = propertyConfig.substring(1);
 			} else {
 				key = propertyConfig;
 			}
@@ -154,48 +157,53 @@ public class MultiPropertyFilterIndex im
 		return filter;
     }
     
-    protected List<String> createKeys(ServiceReference reference) {
-    	List<String> results = new ArrayList<>();
-    	List<List<String>> sets = new ArrayList<>();   	
-    	String[] keys = reference.getPropertyKeys();
-    	Arrays.sort(keys, String.CASE_INSENSITIVE_ORDER);
-    	for (int i = 0; i < keys.length; i++) {
-    		List<String> set = new ArrayList<>();
-    		String key = keys[i].toLowerCase();
+	protected List<String> createKeys(ServiceReference reference) {
+		List<String> results = new ArrayList<>();
+		List<List<String>> sets = new ArrayList<>();
+		String[] keys = reference.getPropertyKeys();
+		Arrays.sort(keys, String.CASE_INSENSITIVE_ORDER);
+		for (int i = 0; i < keys.length; i++) {
+			List<String> set = new ArrayList<>();
+			String key = keys[i].toLowerCase();
     		if (m_configProperties.containsKey(key)) {
-	    		Object valueObject = reference.getProperty(key);
-	    		if (valueObject instanceof String[]) {
-	    			set.addAll(getPermutations(key, (String[]) valueObject));
-	    		} else {
-	    			set.add(toKey(key, valueObject));
-	    		}
-	    		sets.add(set);
-    		}
-    	}
-    	
-    	List<List<String>> reversedSets = new ArrayList<>();
-    	int size = sets.size();
-    	for (int i = size - 1; i > -1; i--) {
-    		reversedSets.add(sets.get(i));
-    	}
-    	List<List<String>> products = carthesianProduct(0, reversedSets);
-    	// convert sets into strings
-    	for (int i = 0; i < products.size(); i++) {
-    		List<String> set = products.get(i);
-    		StringBuilder b = new StringBuilder();
-    		for (int j = 0; j < set.size(); j++) {
-    			String item = set.get(j);
-    			b.append(item);
-    			if (j < set.size() - 1) {
-    				b.append(";");
-    			}
+				Object valueObject = reference.getProperty(key);
+				if (valueObject instanceof String[]) {
+					String[] values = (String[]) valueObject;
+					if (m_configProperties.get(key).isPermute()) {
+						set.addAll(getPermutations(key, values));
+					} else {
+						set.addAll(getSingleValues(key, values)); 
+					}
+				} else {
+					set.add(toKey(key, valueObject));
+				}
+				sets.add(set);
     		}
-    		results.add(b.toString());
-    	}
-    	
-    	return results;
-    }
-    
+		}
+
+		List<List<String>> reversedSets = new ArrayList<>();
+		int size = sets.size();
+		for (int i = size - 1; i > -1; i--) {
+			reversedSets.add(sets.get(i));
+		}
+		List<List<String>> products = carthesianProduct(0, reversedSets);
+		// convert sets into strings
+		for (int i = 0; i < products.size(); i++) {
+			List<String> set = products.get(i);
+			StringBuilder b = new StringBuilder();
+			for (int j = 0; j < set.size(); j++) {
+				String item = set.get(j);
+				b.append(item);
+				if (j < set.size() - 1) {
+					b.append(";");
+				}
+			}
+			results.add(b.toString());
+		}
+
+		return results;
+	}
+	   
     /**
      * Note that we calculate the carthesian product for multi value properties. Use filters
on these sparingly since memory
      * consumption can get really high when multiple properties have a lot of values.
@@ -245,6 +253,15 @@ public class MultiPropertyFilterIndex im
 		return results;
     }
     
+	private Collection<? extends String> getSingleValues(String key, String[] values)
{
+		List<String> results = new ArrayList<>();
+		Arrays.sort(values, String.CASE_INSENSITIVE_ORDER);
+		for (int v = 0; v < values.length; v++) {
+			results.add(toKey(key, values[v]));
+		}
+		return results;
+	}
+    
     protected String toKey(String key, List<String> values) {
     	StringBuilder builder = new StringBuilder();
     	for (int i = 0; i < values.size(); i++) {

Modified: felix/trunk/dependencymanager/org.apache.felix.dependencymanager/src/org/apache/felix/dm/impl/index/multiproperty/Property.java
URL: http://svn.apache.org/viewvc/felix/trunk/dependencymanager/org.apache.felix.dependencymanager/src/org/apache/felix/dm/impl/index/multiproperty/Property.java?rev=1776213&r1=1776212&r2=1776213&view=diff
==============================================================================
--- felix/trunk/dependencymanager/org.apache.felix.dependencymanager/src/org/apache/felix/dm/impl/index/multiproperty/Property.java
(original)
+++ felix/trunk/dependencymanager/org.apache.felix.dependencymanager/src/org/apache/felix/dm/impl/index/multiproperty/Property.java
Tue Dec 27 23:21:18 2016
@@ -26,6 +26,7 @@ import java.util.TreeSet;
 
 public class Property {
 	boolean m_negate;
+	boolean m_permute = true;
 	boolean m_valid = true;
 	String m_key;
 	String m_value;
@@ -46,6 +47,10 @@ public class Property {
 		this.m_negate = negate;
 	}
 	
+	public void setPermute(boolean permute) {
+		this.m_permute = permute;
+	}
+	
 	public void setKey(String key) {
 		this.m_key = key.toLowerCase();
 	}
@@ -68,6 +73,10 @@ public class Property {
 		return m_negate;
 	}
 	
+	public boolean isPermute() {
+		return m_permute;
+	}
+	
 	public String getKey() {
 		return m_key;
 	}



Mime
View raw message