[jboss-cvs] JBossAS SVN: r91285 - projects/kernel/trunk/dependency/src/main/java/org/jboss/dependency/plugins.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Jul 15 05:46:41 EDT 2009


Author: kabir.khan at jboss.com
Date: 2009-07-15 05:46:41 -0400 (Wed, 15 Jul 2009)
New Revision: 91285

Modified:
   projects/kernel/trunk/dependency/src/main/java/org/jboss/dependency/plugins/AbstractController.java
Log:
[JBKERNEL-4] Add the initial work to the controller. It is not enabled yet

Modified: projects/kernel/trunk/dependency/src/main/java/org/jboss/dependency/plugins/AbstractController.java
===================================================================
--- projects/kernel/trunk/dependency/src/main/java/org/jboss/dependency/plugins/AbstractController.java	2009-07-15 09:21:07 UTC (rev 91284)
+++ projects/kernel/trunk/dependency/src/main/java/org/jboss/dependency/plugins/AbstractController.java	2009-07-15 09:46:41 UTC (rev 91285)
@@ -1410,7 +1410,68 @@
       {
          lockWrite();
       }
+//      uninstallUnusedOnDemandContexts(context, trace);
    }
+   
+   protected void uninstallUnusedOnDemandContexts(ControllerContext context, boolean trace)
+   {
+      DependencyInfo dependencies = context.getDependencyInfo();
+      if (dependencies != null)
+      {
+         Set<DependencyItem> iDependOn = dependencies.getIDependOn(null);
+         if (iDependOn.isEmpty() == false)
+         {
+            for (DependencyItem item : iDependOn)
+            {
+               if (item.isResolved()) //TODO Is this check necessary
+               {
+                  Object name = item.getIDependOn();
+                  ControllerContext other = getContext(name, null);
+                  if (other == null)
+                  {
+                     log.warn("Could not find dependency while uninstalling on demand contexts for " + item);
+                     continue;
+                  }
+                  if (other.getMode() != ControllerMode.ON_DEMAND)
+                     continue;
+                  
+                  DependencyInfo otherDependencies = other.getDependencyInfo();
+                  if (otherDependencies == null)
+                     continue;
+                  
+                  Set<DependencyItem> dependsOnOther = otherDependencies.getDependsOnMe(null);
+                  boolean isRequired = false;
+                  for (DependencyItem dependsOnOtherItem : dependsOnOther)
+                  {
+                     ControllerContext dependsContext = getContext(item.getName(), null);
+                     if (dependsContext == null)
+                     {
+                        log.warn("Could not find dependency while uninstalling on demand contexts for " + item);
+                        continue;
+                     }
+                        
+                     int requiredIndex = states.indexOf(item.getWhenRequired());
+                     int actualIndex = states.indexOf(dependsContext.getState());
+                     if (requiredIndex <= actualIndex)
+                     {
+                        isRequired = true;
+                        break;
+                     }
+                  }
+                  if (!isRequired)
+                  {
+                     //For some reason uninstallContext() uninstalls to the state below the passed in one, add one
+                     //TODO This should only really look at the states available to the ControllerContext
+                     int index = states.indexOf(ControllerMode.ON_DEMAND.getRequiredState());
+                     index++;
+                     ControllerState state = states.get(index);
+                     uninstallContext(other, state, trace);
+                  }
+               }
+            }
+         }
+      }
+   }
 
    /**
     * Get all contexts by name,




More information about the jboss-cvs-commits mailing list