Return-Path: Delivered-To: apmail-incubator-felix-commits-archive@www.apache.org Received: (qmail 685 invoked from network); 24 Jan 2007 17:14:33 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 24 Jan 2007 17:14:33 -0000 Received: (qmail 17620 invoked by uid 500); 24 Jan 2007 17:14:39 -0000 Delivered-To: apmail-incubator-felix-commits-archive@incubator.apache.org Received: (qmail 17601 invoked by uid 500); 24 Jan 2007 17:14:38 -0000 Mailing-List: contact felix-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: felix-dev@incubator.apache.org Delivered-To: mailing list felix-commits@incubator.apache.org Received: (qmail 17585 invoked by uid 99); 24 Jan 2007 17:14:38 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 24 Jan 2007 09:14:38 -0800 X-ASF-Spam-Status: No, hits=-9.4 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 24 Jan 2007 09:14:31 -0800 Received: by eris.apache.org (Postfix, from userid 65534) id 6559D1A981A; Wed, 24 Jan 2007 09:13:23 -0800 (PST) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: felix-commits@incubator.apache.org From: rickhall@apache.org X-Mailer: svnmailer-1.1.0 Message-Id: <20070124171323.6559D1A981A@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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); + } } } }