[jboss-cvs] JBossAS SVN: r63877 - projects/microcontainer/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/sort.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri Jul 6 12:41:10 EDT 2007


Author: alesj
Date: 2007-07-06 12:41:10 -0400 (Fri, 06 Jul 2007)
New Revision: 63877

Modified:
   projects/microcontainer/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/sort/DominoDeployerSorter.java
   projects/microcontainer/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/sort/DominoOrdering.java
Log:
Managed to get tests working.
Still need to define heuristics and add more tests.

Modified: projects/microcontainer/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/sort/DominoDeployerSorter.java
===================================================================
--- projects/microcontainer/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/sort/DominoDeployerSorter.java	2007-07-06 15:29:48 UTC (rev 63876)
+++ projects/microcontainer/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/sort/DominoDeployerSorter.java	2007-07-06 16:41:10 UTC (rev 63877)
@@ -28,7 +28,6 @@
 
 /**
  * Deployer sorter using domino sorting.
- * 
  * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
  */
 public class DominoDeployerSorter implements DeployerSorter

Modified: projects/microcontainer/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/sort/DominoOrdering.java
===================================================================
--- projects/microcontainer/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/sort/DominoOrdering.java	2007-07-06 15:29:48 UTC (rev 63876)
+++ projects/microcontainer/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/sort/DominoOrdering.java	2007-07-06 16:41:10 UTC (rev 63877)
@@ -30,7 +30,7 @@
 
 /**
  * Simple transition ordering using transitive closure.
- * 
+ *
  * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
  * @param <T> exact domino type
  */
@@ -91,11 +91,15 @@
       // prepare initial transitions
       init(dominoes);
       // do transitive closure
-      fillTransitions(true);
+      int cycle = fillTransitions(true);
+      if (cycle >= 0)
+         throwCycleException(cycle);
       // name compare on 'uncomparable'
       fillCompareNames();
       // just check for possible newly created loops
-      fillTransitions(false);
+      cycle = fillTransitions(false);
+      if (cycle >= 0)
+         throwCycleException(cycle);
 
       List<Integer> indexes = new ArrayList<Integer>();
       for (int i = 0; i < size; i++)
@@ -103,59 +107,55 @@
       Collections.sort(indexes, new IndexComparator());
 
       List<T> list = new ArrayList<T>(size);
-      for(Integer index : indexes)
+      for (Integer index : indexes)
          list.add(dominoes.get(index));
       return list;
    }
 
-   protected void fillTransitions(boolean fillTransition)
+   /**
+    * Fill transitions.
+    *
+    * @param fillTransitions do change
+    * @return index of the domino cycle cause, -1 otherwise
+    */
+   protected int fillTransitions(boolean fillTransitions)
    {
       boolean changed = true;
-      while(changed)
+      while (changed)
       {
          changed = false;
          for (int i = 0; i < size; i++)
          {
             for (int j = 0; j < size; j++)
             {
-               if (j == i || connections[i][j] == 0)
+               int current = connections[i][j];
+               if (j == i || current == 0)
                   continue;
                for (int k = 0; k < size; k++)
                {
                   if (k == i || k == j)
                      continue;
-                  if (connections[i][j] > 0)
+                  int lookup = connections[j][k];
+                  // same signum
+                  if (current * lookup > 0)
                   {
-                     if (connections[j][k] > 0)
+                     int next = connections[i][k];
+                     // cycle
+                     if (next * current < 0)
                      {
-                        // cycle
-                        if (connections[i][k] < 0)
-                           throwCycleException(i);
-                        else if (fillTransition && connections[i][k] == 0)
-                        {
-                           connections[i][k] = 1;
-                           changed = true;
-                        }
+                        return i;
                      }
-                  }
-                  else if (connections[i][j] < 0)
-                  {
-                     if (connections[j][k] < 0)
+                     else if (fillTransitions && next == 0)
                      {
-                        // cycle
-                        if (connections[i][k] > 0)
-                           throwCycleException(i);
-                        else if (fillTransition && connections[i][k] == 0)
-                        {
-                           connections[i][k] = -1;
-                           changed = true;
-                        }
+                        connections[i][k] = current;
+                        changed = true;
                      }
                   }
                }
             }
          }
       }
+      return -1;
    }
 
    protected void fillCompareNames()
@@ -170,6 +170,13 @@
                T two = dominoes.get(j);
                connections[i][j] = COMPARATOR.compare(one, two);
                connections[j][i] = -connections[i][j];
+               int cycle = fillTransitions(false);
+               // we introduced cycle - flip the signum
+               if (cycle >= 0)
+               {
+                  connections[i][j] = -connections[i][j];
+                  connections[j][i] = -connections[i][j];
+               }
             }
          }
       }




More information about the jboss-cvs-commits mailing list