geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ga...@apache.org
Subject svn commit: r1337021 - /geronimo/server/branches/3.0-beta/plugins/aries/geronimo-aries/src/main/java/org/apache/geronimo/aries/ApplicationGBean.java
Date Fri, 11 May 2012 03:33:09 GMT
Author: gawor
Date: Fri May 11 03:33:08 2012
New Revision: 1337021

URL: http://svn.apache.org/viewvc?rev=1337021&view=rev
Log:
improve bundle sorting algorithm to self wires and cycles

Modified:
    geronimo/server/branches/3.0-beta/plugins/aries/geronimo-aries/src/main/java/org/apache/geronimo/aries/ApplicationGBean.java

Modified: geronimo/server/branches/3.0-beta/plugins/aries/geronimo-aries/src/main/java/org/apache/geronimo/aries/ApplicationGBean.java
URL: http://svn.apache.org/viewvc/geronimo/server/branches/3.0-beta/plugins/aries/geronimo-aries/src/main/java/org/apache/geronimo/aries/ApplicationGBean.java?rev=1337021&r1=1337020&r2=1337021&view=diff
==============================================================================
--- geronimo/server/branches/3.0-beta/plugins/aries/geronimo-aries/src/main/java/org/apache/geronimo/aries/ApplicationGBean.java
(original)
+++ geronimo/server/branches/3.0-beta/plugins/aries/geronimo-aries/src/main/java/org/apache/geronimo/aries/ApplicationGBean.java
Fri May 11 03:33:08 2012
@@ -415,35 +415,47 @@ public class ApplicationGBean implements
      * Sorts bundles in bundle dependency order (i.e. Import-Package, Require-Bundle order).
      */
     private LinkedHashSet<Bundle> getSortedBundles() {
+        LinkedList<Bundle> stack = new LinkedList<Bundle>();
         LinkedHashSet<Bundle> orderedBundles = new LinkedHashSet<Bundle>(applicationBundles.size());
         for (Bundle bundle : applicationBundles) {
-            sortDependentBundles(bundle, orderedBundles);
+            sortDependentBundles(bundle, orderedBundles, stack);
         }
         return orderedBundles;
     }
     
-    private void sortDependentBundles(Bundle bundle, LinkedHashSet<Bundle> sortedBundles)
{
+    private void sortDependentBundles(Bundle bundle, LinkedHashSet<Bundle> sortedBundles,
LinkedList<Bundle> stack) {
         if (sortedBundles.contains(bundle)) {
             return;
         }
         
+        if (stack.contains(bundle)) {
+            // dependency loop detected
+            LOG.warn("Bundle dependency loop detected: {}", stack.subList(stack.indexOf(bundle),
stack.size()));
+            return;
+        }
+        stack.add(bundle);
+        
         BundleWiring wiring = bundle.adapt(BundleWiring.class);
         List<BundleWire> wires;
         wires = wiring.getRequiredWires(BundleRevision.PACKAGE_NAMESPACE);
         for (BundleWire wire : wires) {
             Bundle wiredBundle = wire.getProviderWiring().getBundle();
-            if (applicationBundles.contains(wiredBundle)) {
-                sortDependentBundles(wiredBundle, sortedBundles);
+            // examine wires to other application bundles only
+            if (wiredBundle != bundle && applicationBundles.contains(wiredBundle))
{
+                sortDependentBundles(wiredBundle, sortedBundles, stack);
             }
         }
         wires = wiring.getRequiredWires(BundleRevision.BUNDLE_NAMESPACE);
         for (BundleWire wire : wires) {
             Bundle wiredBundle = wire.getProviderWiring().getBundle();
-            if (applicationBundles.contains(wiredBundle)) {
-                sortDependentBundles(wiredBundle, sortedBundles);
+            // examine wires to other application bundles only
+            if (wiredBundle != bundle && applicationBundles.contains(wiredBundle))
{
+                sortDependentBundles(wiredBundle, sortedBundles, stack);
             }
         }
         
+        stack.removeLast();
+        
         sortedBundles.add(bundle);
     }
     



Mime
View raw message