felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rickh...@apache.org
Subject svn commit: r916617 - /felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver/proto3/Proto3Resolver.java
Date Fri, 26 Feb 2010 08:34:21 GMT
Author: rickhall
Date: Fri Feb 26 08:34:21 2010
New Revision: 916617

URL: http://svn.apache.org/viewvc?rev=916617&view=rev
Log:
A potential approach for reexport visibility support.

Modified:
    felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver/proto3/Proto3Resolver.java

Modified: felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver/proto3/Proto3Resolver.java
URL: http://svn.apache.org/viewvc/felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver/proto3/Proto3Resolver.java?rev=916617&r1=916616&r2=916617&view=diff
==============================================================================
--- felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver/proto3/Proto3Resolver.java
(original)
+++ felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver/proto3/Proto3Resolver.java
Fri Feb 26 08:34:21 2010
@@ -76,6 +76,8 @@
             m_invokeCounts.put(methodName, count);
         }
 
+        Map<Module, List<Wire>> wireMap = new HashMap<Module, List<Wire>>();
+
         Map<Module, Packages> modulePkgMap = new HashMap<Module, Packages>();
 
         if (!module.isResolved())
@@ -121,10 +123,11 @@
                 throw rethrow;
             }
 //dumpModulePkgMap(modulePkgMap);
-        }
 
-        Map<Module, List<Wire>> wireMap =
-            populateWireMap(module, modulePkgMap, new HashMap<Module, List<Wire>>());
+            wireMap =
+                populateWireMap(module, modulePkgMap, wireMap,
+                candidateMap);
+        }
 
         if (m_isInvokeCount)
         {
@@ -153,6 +156,8 @@
         {
             m_candidatePermutations.clear();
 
+            Map<Module, List<Wire>> wireMap = new HashMap<Module, List<Wire>>();
+
             Map<Module, Packages> modulePkgMap = new HashMap<Module, Packages>();
 
 //System.out.println("+++ DYNAMICALLY RESOLVING " + module + " - " + pkgName);
@@ -188,9 +193,9 @@
                 throw rethrow;
             }
 //dumpModulePkgMap(modulePkgMap);
-            Map<Module, List<Wire>> wireMap =
+            wireMap =
                 populateDynamicWireMap(
-                    module, pkgName, modulePkgMap, new HashMap<Module, List<Wire>>());
+                    module, pkgName, modulePkgMap, wireMap, candidateMap);
 
 //System.out.println("+++ DYNAMIC SUCCESS: " + wireMap.get(module));
             return wireMap;
@@ -675,6 +680,12 @@
                     {
 System.out.println("RE: " + ex);
 ex.printStackTrace();
+
+// TODO: FELIX3 RESOLVER - Is it ok to remove the failed candidate? By removing
+//       it we keep the candidateMap up to date with the selected candidate, but
+//       theoretically this eliminates some potential combinations. Are those
+//       combinations guaranteed to be failures so eliminating them is ok?
+                        it.remove();
                         if (!it.hasNext() && !req.isOptional())
                         {
                             throw new ResolveException("Unresolved constraint "
@@ -760,6 +771,11 @@
                 {
 System.out.println("RE: " + ex);
 ex.printStackTrace();
+// TODO: FELIX3 RESOLVER - Is it ok to remove the failed candidate? By removing
+//       it we keep the candidateMap up to date with the selected candidate, but
+//       theoretically this eliminates some potential combinations. Are those
+//       combinations guaranteed to be failures so eliminating them is ok?
+                    it.remove();
                     if (!it.hasNext() && !req.isOptional())
                     {
                         throw new ResolveException("Unresolved constraint "
@@ -866,8 +882,21 @@
                 List<Blame> blames = entry.getValue();
                 for (Blame blame : blames)
                 {
-                    if (blame.m_reqs.get(blame.m_reqs.size() - 1)
-                        .getDirective(Constants.VISIBILITY_DIRECTIVE) != null)
+// TODO: FELIX3 RESOLVER - Since a single module requirement can include many packages,
+//       it is likely we call merge too many times for the same module req. If we knew
+//       which candidates were being used to resolve this candidate's module dependencies,
+//       then we could just try to merge them directly. This info would also help in
+//       in creating wires, since we ultimately want to create wires for the selected
+//       candidates, which we are trying to deduce from the package space, but if we
+//       knew the selected candidates, we'd be done.
+                    if (blame.m_cap.getModule().equals(current))
+                    {
+                        continue;
+                    }
+
+                    Directive dir = blame.m_reqs.get(blame.m_reqs.size() - 1)
+                        .getDirective(Constants.VISIBILITY_DIRECTIVE);
+                    if ((dir != null) && dir.getValue().equals(Constants.VISIBILITY_REEXPORT))
                     {
                         mergeCandidatePackage(
                             current,
@@ -968,7 +997,7 @@
                     currentRequiredBlames = new ArrayList<Blame>();
                     currentPkgsCopy.m_requiredPkgs.put(pkgName, currentRequiredBlames);
                 }
-// TODO: PROTO2 RESOLVER - This is potentially modifying the original, we need to modify
a copy.
+// TODO: PROTO3 RESOLVER - This is potentially modifying the original, we need to modify
a copy.
                 currentRequiredBlames.add(candBlame);
             }
             else
@@ -1253,7 +1282,7 @@
 
     private static Map<Module, List<Wire>> populateWireMap(
         Module module, Map<Module, Packages> modulePkgMap,
-        Map<Module, List<Wire>> wireMap)
+        Map<Module, List<Wire>> wireMap, Map<Requirement, Set<Capability>>
candidateMap)
     {
         if (m_isInvokeCount)
         {
@@ -1270,87 +1299,36 @@
             List<Wire> packageWires = new ArrayList<Wire>();
             List<Wire> moduleWires = new ArrayList<Wire>();
 
-            Packages pkgs = modulePkgMap.get(module);
-            for (Entry<String, Blame> entry : pkgs.m_importedPkgs.entrySet())
-            {
-                if (!entry.getValue().m_cap.getModule().isResolved())
-                {
-                    populateWireMap(entry.getValue().m_cap.getModule(), modulePkgMap, wireMap);
-                }
-
-                // Ignore modules that import themselves.
-                if (!module.equals(entry.getValue().m_cap.getModule()))
-                {
-                    packageWires.add(
-                        new WireImpl(module,
-                            entry.getValue().m_reqs.get(entry.getValue().m_reqs.size() -
1),
-                            entry.getValue().m_cap.getModule(),
-                            entry.getValue().m_cap));
-                }
-            }
-            List<Requirement> rbReqs = new ArrayList<Requirement>();
             for (Requirement req : module.getRequirements())
             {
-                if (req.getNamespace().equals(Capability.MODULE_NAMESPACE))
+                Set<Capability> cands = candidateMap.get(req);
+                if ((cands != null) && (cands.size() > 0))
                 {
-                    rbReqs.add(req);
-                }
-            }
-            if (!rbReqs.isEmpty())
-            {
-                Map<Requirement, Capability> rbMap =
-                    new HashMap<Requirement, Capability>();
-// TODO: FELIX3 - This approach isn't very efficient since it keeps recalculating the
-//       module wire for each package exported by the candidate module.
-                for (Entry<String, List<Blame>> entry : pkgs.m_requiredPkgs.entrySet())
-                {
-                    for (Blame blame : entry.getValue())
+                    Capability cand = cands.iterator().next();
+                    if (!cand.getModule().isResolved())
                     {
-                        // Ignore packages required from self, which can
-                        // happen in cycles.
-                        if (!blame.m_cap.getModule().equals(module))
-                        {
-                            for (Requirement rbReq : rbReqs)
-                            {
-                                if (blame.m_reqs.get(blame.m_reqs.size() - 1).equals(rbReq))
-                                {
-                                    List<Capability> moduleCaps =
-                                        Util.getCapabilityByNamespace(
-                                            blame.m_cap.getModule(), Capability.MODULE_NAMESPACE);
-                                    Capability cap = rbMap.get(rbReq);
-                                    if (cap == null)
-                                    {
-                                        rbMap.put(rbReq, moduleCaps.get(0));
-                                    }
-                                    if (!blame.m_cap.getModule().isResolved())
-                                    {
-                                        populateWireMap(
-                                            blame.m_cap.getModule(), modulePkgMap, wireMap);
-                                    }
-                                    break;
-                                }
-                            }
-                        }
+                        populateWireMap(cand.getModule(),
+                            modulePkgMap, wireMap, candidateMap);
                     }
-                }
-
-                // Loop through RB requirements to keep the wires in the
-                // correct order, which is required by the spec.
-                for (Requirement rbReq : rbReqs)
-                {
-                    Capability cap = rbMap.get(rbReq);
-                    if (cap != null)
+                // Ignore modules that import themselves.
+                    if (req.getNamespace().equals(Capability.PACKAGE_NAMESPACE)
+                        && !module.equals(cand.getModule()))
                     {
-                        // Ignore modules that import themselves.
-                        if (!module.equals(cap.getModule()))
-                        {
-                            moduleWires.add(
-                                new WireModuleImpl(module,
-                                    rbReq,
-                                    cap.getModule(),
-                                    cap,
-                                    pkgs.getRequiredPackages(cap.getModule())));
-                        }
+                        packageWires.add(
+                            new WireImpl(module,
+                                req,
+                                cand.getModule(),
+                                cand));
+                    }
+                    else if (req.getNamespace().equals(Capability.MODULE_NAMESPACE))
+                    {
+                        Packages pkgs = modulePkgMap.get(module);
+                        moduleWires.add(
+                            new WireModuleImpl(module,
+                                req,
+                                cand.getModule(),
+                                cand,
+                                pkgs.getRequiredPackages(cand.getModule())));
                     }
                 }
             }
@@ -1365,7 +1343,7 @@
 
     private static Map<Module, List<Wire>> populateDynamicWireMap(
         Module module, String pkgName, Map<Module, Packages> modulePkgMap,
-        Map<Module, List<Wire>> wireMap)
+        Map<Module, List<Wire>> wireMap, Map<Requirement, Set<Capability>>
candidateMap)
     {
         if (m_isInvokeCount)
         {
@@ -1384,7 +1362,8 @@
         {
             if (!entry.getValue().m_cap.getModule().isResolved())
             {
-                populateWireMap(entry.getValue().m_cap.getModule(), modulePkgMap, wireMap);
+                populateWireMap(entry.getValue().m_cap.getModule(), modulePkgMap, wireMap,
+                    candidateMap);
             }
 
             // Ignore modules that import themselves.



Mime
View raw message