aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jwr...@apache.org
Subject svn commit: r1698360 - in /aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal: AbstractRequirement.java ResourceHelper.java
Date Fri, 28 Aug 2015 16:02:20 GMT
Author: jwross
Date: Fri Aug 28 16:02:20 2015
New Revision: 1698360

URL: http://svn.apache.org/r1698360
Log:
ARIES-1388 Compute requirement filters only once.

ResourceHelper.matches(Requirement, Capability) is an often used method during resolution.
Currently, it recomputes the requirement filter with each call.

The measurements used the same test scenario being developed as part of ARIES-1357. The time
it took to install 50 features was measured. Each feature consists of 10 bundles plus one
application. All features share the same 10 bundles. Each bundle exports 5 unique packages.
Each application consists of 10 unique bundles. The bundles import packages offered by the
containing feature.

The baseline average time for installing all 50 features was 67.9 seconds.

AbstractRequirement will now lazily compute the requirement filter when asked for the first
time. Subsequent calls will return the already computed value.

ResourceHelper now asks whether or not the Requirement is an instance of AbstractRequirement.
If so, it asks for the filter directly. If not, the filter is computed as before.

After these modifications, the average time for installing all 50 features was 46.6 seconds,
a 31.3% improvement.

Modified:
    aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/AbstractRequirement.java
    aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/ResourceHelper.java

Modified: aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/AbstractRequirement.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/AbstractRequirement.java?rev=1698360&r1=1698359&r2=1698360&view=diff
==============================================================================
--- aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/AbstractRequirement.java
(original)
+++ aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/AbstractRequirement.java
Fri Aug 28 16:02:20 2015
@@ -13,6 +13,10 @@
  */
 package org.apache.aries.subsystem.core.internal;
 
+import org.osgi.framework.Constants;
+import org.osgi.framework.Filter;
+import org.osgi.framework.FrameworkUtil;
+import org.osgi.framework.InvalidSyntaxException;
 import org.osgi.resource.Requirement;
 
 public abstract class AbstractRequirement implements Requirement {
@@ -30,6 +34,20 @@ public abstract class AbstractRequiremen
 				getResource()) : getResource() == null;
 	}
 	
+	private Filter filter;
+	public Filter getFilter() throws InvalidSyntaxException {
+	    String filterStr = getDirectives().get(Constants.FILTER_DIRECTIVE);
+	    if (filterStr == null) {
+	        return null;
+	    }
+	    synchronized (this) {
+	        if (filter == null) {
+	            filter = FrameworkUtil.createFilter(filterStr);
+	        }
+	        return filter;
+	    }	    
+	}
+	
 	@Override
 	public int hashCode() {
 		int result = 17;

Modified: aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/ResourceHelper.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/ResourceHelper.java?rev=1698360&r1=1698359&r2=1698360&view=diff
==============================================================================
--- aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/ResourceHelper.java
(original)
+++ aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/ResourceHelper.java
Fri Aug 28 16:02:20 2015
@@ -24,6 +24,7 @@ import java.util.regex.Pattern;
 
 import org.apache.aries.subsystem.core.archive.TypeAttribute;
 import org.osgi.framework.Constants;
+import org.osgi.framework.Filter;
 import org.osgi.framework.FrameworkUtil;
 import org.osgi.framework.InvalidSyntaxException;
 import org.osgi.framework.Version;
@@ -115,17 +116,25 @@ public class ResourceHelper {
 		else if (!capability.getNamespace().equals(requirement.getNamespace())) 
 			return false;
 		else {
-			String filterStr = requirement.getDirectives().get(Constants.FILTER_DIRECTIVE);
-			if (filterStr != null) {
-				try {
-					if (!FrameworkUtil.createFilter(filterStr).matches(capability.getAttributes()))
-						return false;
-				}
-				catch (InvalidSyntaxException e) {
-					logger.debug("Requirement had invalid filter string: " + requirement, e);
-					return false;
-				}
-			}
+		    Filter filter = null;
+		    try {
+    		    if (requirement instanceof AbstractRequirement) {
+    		        filter = ((AbstractRequirement)requirement).getFilter();
+    		    }
+    		    else {
+    		        String filterStr = requirement.getDirectives().get(Constants.FILTER_DIRECTIVE);
+    	            if (filterStr != null) {
+    	                filter = FrameworkUtil.createFilter(filterStr);
+    	            }
+    		    }
+		    }
+		    catch (InvalidSyntaxException e) {
+                logger.debug("Requirement had invalid filter string: " + requirement, e);
+                return false;
+            }
+		    if (filter != null && !filter.matches(capability.getAttributes())) {
+                return false;
+		    }
 		}
 		return matchMandatoryDirective(requirement, capability);
 	}



Mime
View raw message