if (logger.isDebugEnabled() && expander.debugAgent()) {
if (logger.isDebugEnabled()) {
  protected void execute() {    //clear our new refill list    newRefills.clear();    // need to call these at beginning of execute cycle    supplyTaskScheduler.initForExecuteCycle();    projectionTaskScheduler.initForExecuteCycle();    // if the OM changed and the window is further out then before    // then mark the flag true so we process previously ignored tasks    // and allocation results.  If it went down - don't undo work    if (!Level6OMSubscription.getChangedCollection().isEmpty()) {      long currentLevel6 = getEndOfLevelSix();      if (logger.isInfoEnabled()) {        logger.info("Inv Mgr got changed OM ... new end of level 6 window is: " +                    currentLevel6 + " in agent: " + getAgentIdentifier() +                    " supply type: " + getSupplyType());      }      if (currentLevel6 > prevLevel6) {        OMChange = true;      }      //reset the previous level 6 to the current      prevLevel6 = currentLevel6;    }    if (inventoryPolicy == null) {      updateInventoryPolicy(inventoryPolicySubscription);    }    updateInventoryPolicy(inventoryPolicySubscription.getChangedCollection());    processDetReq(detReqSubscription.getAddedCollection());    cycleStamp = (new Date()).getTime();    if (inventoryPolicy == null) {      if (logger.isInfoEnabled()) {        logger.info("\n InventoryPlugin " + supplyType +                    " not ready to process tasks yet." +                    " my inv policy is: " + inventoryPolicy + " in " + getMyOrganization());      }      return;    }    if (myOrganization == null) {      myOrganization = getMyOrganization(selfOrganizations.elements());    }    if (myOrganization == null) {      if (logger.isInfoEnabled()) {        logger.info("\n InventoryPlugin " + supplyType +                    " not ready to process tasks yet." +                    " my org is: " + myOrganization);      }      return;    }    if (!initialized) {      myOrgName = myOrganization.getItemIdentificationPG().getItemIdentification();      inventoryFile = getInventoryFile(supplyType);      getInventoryData();      initialized = true;    }    if ((logOPlan == null) || logisticsOPlanSubscription.hasChanged()) {      Collection c = logisticsOPlanSubscription.getCollection();      for (Iterator i = c.iterator(); i.hasNext();) {        logOPlan = (LogisticsOPlan) i.next();        //        System.out.println("logOplan in :" + getAgentIdentifier().toString() +        //                   " is: " + logOPlan);        resetLogOPlanForInventories();        break;      }    }    // if our top level MI task got removed, clean out the references .    if (! aggMILSubscription.getRemovedCollection().isEmpty()) {      detReqHandler.resetAggMITask();    }    if ((detReqHandler.getDetermineRequirementsTask(aggMILSubscription) != null) &&        (logOPlan != null)) {      if (rehydrateInvs) {        addRehydratedInventories(blackboard.query(new InventoryPredicate(supplyType)));        rehydrateInvs = false;      }      boolean touchedRemovedProjections = processRecRemoves();      Collection addedSupply = supplyTaskScheduler.getAddedCollection();      if (! commStatusSub.isEmpty()) {        ReconcileSupplyExpander expander = getSupplyExpander();        if (expander != null) expander.determineCommStatus(commStatusSub, addedSupply);      }      //      Collection addedSupply = supplyTaskScheduler.getAddedCollection();      if (!addedSupply.isEmpty()) {        expandIncomingRequisitions(getTasksWithoutPEs(addedSupply)); // fix for bug #1695      }      Collection changedSupply = supplyTaskScheduler.getChangedCollection();      if (!changedSupply.isEmpty()) {        supplyExpander.updateChangedRequisitions(changedSupply);      }      supplyTaskScheduler.finishedExecuteCycle();      Collection addedProjections = projectionTaskScheduler.getAddedCollection();      if (!addedProjections.isEmpty()) {        // getTasksWithoutPEs is fix for bug #1695        touchedProjections = expandIncomingProjections(getTasksWithoutPEs(addedProjections));      }      Collection changedProjections = projectionTaskScheduler.getChangedCollection();      if (!changedProjections.isEmpty()) {        supplyExpander.updateChangedProjections(changedProjections);        touchedChangedProjections = true;// System.out.println("Touched changed projections in " + getAgentIdentifier() +//                                " type is" + getSupplyType());      }      projectionTaskScheduler.finishedExecuteCycle();      // Rescind tasks that no longer have a provider      // and      // Allocate any refill tasks from previous executions that were not allocated to providers      // but only if we are not about to rip out previous work we have done      if (didOrgRelationshipsChange()) {//        logger.warn("ORG RELATIONSHIPS CHANGED");//	  System.out.println("SDSD myorg: " + myOrganization + " supply type:" +//			       supplyType + " role: " + getRole(supplyType) + "\n");        HashMap providers = getProvidersAndEndDates();        Collection unprovidedTasks = getUnprovidedTasks(refillAllocationSubscription,                                                        Constants.Verb.Supply,                                                        providers);        if (!unprovidedTasks.isEmpty()){          if (logger.isWarnEnabled())            logger.warn("Trying to rescind unprovided supply refill tasks...");          rescindTaskAllocations(unprovidedTasks);          externalAllocator.allocateRefillTasks(unprovidedTasks);        }        unprovidedTasks = getUnprovidedTasks(refillAllocationSubscription,                                             Constants.Verb.ProjectSupply,                                             providers);        if (!unprovidedTasks.isEmpty()){          if (logger.isWarnEnabled())            logger.warn("Trying to rescind unprovided projection refill tasks...");          rescindTaskAllocations(unprovidedTasks);          externalAllocator.allocateRefillTasks(unprovidedTasks);        }        Collection unalloc = null;        if (addedSupply.isEmpty() && changedSupply.isEmpty()) {          sortIncomingSupplyTasks(getTaskUtils().getUnallocatedTasks(nonrefillSubscription,                                                                     Constants.Verb.Supply), "reconcile");          unalloc = getTaskUtils().getUnallocatedTasks(refillSubscription,                                                       Constants.Verb.Supply);          if (!unalloc.isEmpty()){            if (logger.isWarnEnabled())              logger.warn("TRYING TO ALLOCATE SUPPLY REFILL TASKS...");            externalAllocator.allocateRefillTasks(unalloc);          }        }        if (addedProjections.isEmpty() && changedProjections.isEmpty()) {          sortIncomingSupplyTasks(getTaskUtils().getUnallocatedTasks(nonrefillSubscription,                                                                     Constants.Verb.ProjectSupply), "reconcile");          unalloc = getTaskUtils().getUnallocatedTasks(refillSubscription,                                                       Constants.Verb.ProjectSupply);          if (!unalloc.isEmpty()) {            if (logger.isWarnEnabled())              logger.warn("TRYING TO ALLOCATE PROJECTION REFILL TASKS...");            externalAllocator.allocateRefillTasks(unalloc);          }        }      }      // call the Refill Generators if we have new demand      if (!getTouchedInventories().isEmpty()) {        // update the inventory customer hash tables when we have new demand        rebuildPGCustomerHash();        //check to see if we have new projections        if (touchedProjections || touchedRemovedProjections || touchedChangedProjections) {          //check to see if the OM changed.  If it did process all inventories          //since we probably ignored some demand tasks before the change          if (OMChange) {            refillProjGenerator.calculateRefillProjections(getInventories(),                                                           criticalLevel,                                                           getEndOfLevelSix(),                                                           getEndOfLevelTwo(),                                                           refillComparator);          } else {            refillProjGenerator.calculateRefillProjections(getTouchedInventories(),                                                           criticalLevel,                                                           getEndOfLevelSix(),                                                           getEndOfLevelTwo(),                                                           refillComparator);          }        }        refillGenerator.calculateRefills(getTouchedInventories(), refillComparator);        externalAllocator.allocateRefillTasks(newRefills);        //we might get new demand where we don't need to generate any new refills        // such as small demand from the stimulator servlet - when this happens we        // need to kick the allocation assessor to allocate the withdraws        allocationAssessor.reconcileInventoryLevels(getActionableInventories());      }      //        externalAllocator.updateAllocationResult(getActionableRefillAllocations());      //        allocationAssessor.reconcileInventoryLevels(backwardFlowInventories);      // if we are in downward flow ONLY check the withdraw expansion results      // note we may go through the whole list multiple times - but this seems like the      // simplest fix to get rid of places where we miss change reports because the AA      // compares previous results to new ones and leaves the old ones if they are equal.      // note that the updates only occur if the reported result is not equal to the estimated      // so we will not be waking up the whole chain by checking these more than once.      HashSet backwardFlowTouched = null;      if (getTouchedInventories().isEmpty()) {        supplyExpander.updateAllocationResult(expansionSubscription);        backwardFlowTouched =            externalAllocator.updateAllocationResult(refillAllocationSubscription);        // if the OM changed, process ALL inventories for demand projections and        // allocation results since some results were likely ignored before        // the OM level 6 window changed.        if (OMChange) {          refillProjGenerator.calculateRefillProjections(getInventories(),                                                         criticalLevel,                                                         getEndOfLevelSix(),                                                         getEndOfLevelTwo(),                                                         refillComparator);          externalAllocator.allocateRefillTasks(newRefills);          allocationAssessor.reconcileInventoryLevels(getInventories());        } else {          allocationAssessor.reconcileInventoryLevels(backwardFlowTouched);        }      } else {        // if the we are not in backwards flow but the OM changed        // process ARs anyway because we may not get woken up again to        // process them if they have all come in already        if (OMChange) {          allocationAssessor.reconcileInventoryLevels(getInventories());        }      }      // update the Maintain Inventory Expansion results      PluginHelper.updateAllocationResult(MIExpansionSubscription);      PluginHelper.updateAllocationResult(MITopExpansionSubscription);      PluginHelper.updateAllocationResult(DetReqInvExpansionSubscription);      if (backwardFlowTouched != null) {        takeInventorySnapshot(backwardFlowTouched);      }      takeInventorySnapshot(getTouchedInventories());      // touchedInventories should not be cleared until the end of transaction      touchedInventories.clear();      //backwardFlowInventories.clear(); //###      touchedProjections = false;      touchedChangedProjections = false;      OMChange = false;      //testBG();    } else {      // process subscription removes even if we don't have a top level MI as it could have been rescinded      processRecRemoves();    }    // Review: not sure if this is the right place to make this call    ReconcileSupplyExpander expander = getSupplyExpander();    if (expander != null) {      if (logger.isDebugEnabled() && expander.debugAgent()) {        logger.debug("InventoryPlugin checking the comm status alarms for supply type " + supplyType + " time: "                     + new Date(currentTimeMillis()));      }      expander.checkCommStatusAlarms();    }  }