5 Replies Latest reply on Jan 28, 2010 2:19 PM by kabirkhan

    Uninstall OnDemand context if there are no more dependencies

    kabirkhan

      I have knocked up a prototype for https://jira.jboss.org/jira/browse/JBKERNEL-4. A few of the existing tests fail since the order of uninstall has changed. What I am doing is:

       protected void uninstallContext(ControllerContext context, boolean trace)
       {
       //Existing code
      
       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
       int index = states.indexOf(ControllerMode.ON_DEMAND.getRequiredState());
       index++;
       ControllerState state = states.get(index);
       uninstallContext(other, state, trace);
       }
       }
       }
       }
       }
       }
      


      I'll look into the failing tests and fix those, which might mean needing to change the tests themselves in trunk. The JIRA issue mentions that the uninstall of the OnDemand context should happen asynchronously, which will complicate things, but will be possible if a real requirement, I'll try to fix the tests first though.