felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rickh...@apache.org
Subject svn commit: r499484 - /incubator/felix/trunk/framework/src/main/java/org/apache/felix/framework/searchpolicy/R4SearchPolicyCore.java
Date Wed, 24 Jan 2007 17:13:23 GMT
Author: rickhall
Date: Wed Jan 24 09:13:22 2007
New Revision: 499484

URL: http://svn.apache.org/viewvc?view=rev&rev=499484
Log:
Optimized dynamic importing to ignore non-matching packages, since 
filter evaluation is expensive.

Modified:
    incubator/felix/trunk/framework/src/main/java/org/apache/felix/framework/searchpolicy/R4SearchPolicyCore.java

Modified: incubator/felix/trunk/framework/src/main/java/org/apache/felix/framework/searchpolicy/R4SearchPolicyCore.java
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/framework/src/main/java/org/apache/felix/framework/searchpolicy/R4SearchPolicyCore.java?view=diff&rev=499484&r1=499483&r2=499484
==============================================================================
--- incubator/felix/trunk/framework/src/main/java/org/apache/felix/framework/searchpolicy/R4SearchPolicyCore.java
(original)
+++ incubator/felix/trunk/framework/src/main/java/org/apache/felix/framework/searchpolicy/R4SearchPolicyCore.java
Wed Jan 24 09:13:22 2007
@@ -505,88 +505,99 @@
             IRequirement[] dynamics = importer.getDefinition().getDynamicRequirements();
             for (int i = 0; (dynamics != null) && (i < dynamics.length); i++)
             {
-                // Constrain the current dynamic requirement to include
-                // the precise package name for which we are searching; this
-                // is necessary because we cannot easily determine which
-                // package name a given dynamic requirement matches, since
-                // it is only a filter.
-                IRequirement req = null;
-                try
+                // Ignore any dynamic requirements whose packages don't match.
+                String dynPkgName = ((Requirement) dynamics[i]).getPackageName();
+                boolean wildcard = (dynPkgName.lastIndexOf(".*") >= 0);
+                dynPkgName = (wildcard)
+                    ? dynPkgName.substring(0, dynPkgName.length() - 2) : dynPkgName;
+                if (dynPkgName.equals("*") ||
+                    pkgName.equals(dynPkgName) ||
+                    (wildcard && pkgName.startsWith(dynPkgName)))
                 {
-                    req = new Requirement(
-                        ICapability.PACKAGE_NAMESPACE,
-                        "(&" + dynamics[i].getFilter().toString()
-                            + "(package=" + pkgName + "))");
-                }
-                catch (InvalidSyntaxException ex)
-                {
-                    // This should never happen.
-                }
-
-                // See if there is a candidate exporter that satisfies the
-                // constrained dynamic requirement.
-                try
-                {
-                    // Lock module manager instance to ensure that nothing changes.
-                    synchronized (m_factory)
+                    // Constrain the current dynamic requirement to include
+                    // the precise package name for which we are searching; this
+                    // is necessary because we cannot easily determine which
+                    // package name a given dynamic requirement matches, since
+                    // it is only a filter.
+    
+                    IRequirement req = null;
+                    try
                     {
-                        // First check "in use" candidates for a match.
-                        ResolverCandidate[] candidates = getInUseCandidates(req, false);
-                        // If there is an "in use" candidate, just take the first one.
-                        if (candidates.length > 0)
-                        {
-                            candidate = candidates[0];
-                        }
-
-                        // If there were no "in use" candidates, then try "available"
-                        // candidates.
-                        if (candidate == null)
+                        req = new Requirement(
+                            ICapability.PACKAGE_NAMESPACE,
+                            "(&" + dynamics[i].getFilter().toString()
+                                + "(package=" + pkgName + "))");
+                    }
+                    catch (InvalidSyntaxException ex)
+                    {
+                        // This should never happen.
+                    }
+    
+                    // See if there is a candidate exporter that satisfies the
+                    // constrained dynamic requirement.
+                    try
+                    {
+                        // Lock module manager instance to ensure that nothing changes.
+                        synchronized (m_factory)
                         {
-                            candidates = getAvailableCandidates(req, false);
-
-                            // Take the first candidate that can resolve.
-                            for (int candIdx = 0;
-                                (candidate == null) && (candIdx < candidates.length);
-                                candIdx++)
+                            // First check "in use" candidates for a match.
+                            ResolverCandidate[] candidates = getInUseCandidates(req, false);
+                            // If there is an "in use" candidate, just take the first one.
+                            if (candidates.length > 0)
                             {
-                                try
-                                {
-                                    resolve(candidates[candIdx].m_module);
-                                    candidate = candidates[candIdx];
-                                }
-                                catch (ResolveException ex)
-                                {
-                                    // Ignore candidates that cannot resolve.
-                                }
+                                candidate = candidates[0];
                             }
-                        }
-
-                        if (candidate != null)
-                        {
-                            IWire[] wires = importer.getWires();
-                            R4Wire[] newWires = null;
-                            if (wires == null)
+    
+                            // If there were no "in use" candidates, then try "available"
+                            // candidates.
+                            if (candidate == null)
                             {
-                                newWires = new R4Wire[1];
+                                candidates = getAvailableCandidates(req, false);
+    
+                                // Take the first candidate that can resolve.
+                                for (int candIdx = 0;
+                                    (candidate == null) && (candIdx < candidates.length);
+                                    candIdx++)
+                                {
+                                    try
+                                    {
+                                        resolve(candidates[candIdx].m_module);
+                                        candidate = candidates[candIdx];
+                                    }
+                                    catch (ResolveException ex)
+                                    {
+                                        // Ignore candidates that cannot resolve.
+                                    }
+                                }
                             }
-                            else
+    
+                            if (candidate != null)
                             {
-                                newWires = new R4Wire[wires.length + 1];
-                                System.arraycopy(wires, 0, newWires, 0, wires.length);
-                            }
-
-                            // Create the wire and add it to the module.
-                            wire = new R4Wire(
-                                importer, candidate.m_module, candidate.m_capability);
-                            newWires[newWires.length - 1] = wire;
-                            ((ModuleImpl) importer).setWires(newWires);
+                                IWire[] wires = importer.getWires();
+                                R4Wire[] newWires = null;
+                                if (wires == null)
+                                {
+                                    newWires = new R4Wire[1];
+                                }
+                                else
+                                {
+                                    newWires = new R4Wire[wires.length + 1];
+                                    System.arraycopy(wires, 0, newWires, 0, wires.length);
+                                }
+    
+                                // Create the wire and add it to the module.
+                                wire = new R4Wire(
+                                    importer, candidate.m_module, candidate.m_capability);
+                                newWires[newWires.length - 1] = wire;
+                                ((ModuleImpl) importer).setWires(newWires);
 m_logger.log(Logger.LOG_DEBUG, "WIRE: " + newWires[newWires.length - 1]);
+                            }
                         }
                     }
-                }
-                catch (Exception ex)
-                {
-                    m_logger.log(Logger.LOG_ERROR, "Unable to dynamically import package.",
ex);
+                    catch (Exception ex)
+                    {
+                        m_logger.log(Logger.LOG_ERROR, "Unable to dynamically import package.",
ex);
+                    }
                 }
             }
         }



Mime
View raw message