boolean touchedRemovedProjections = supplyExpander.handleRemovedProjections(projectWithdrawTaskSubscription.getRemovedCollection()); supplyExpander.handleRemovedRequisitions(withdrawTaskSubscription.getRemovedCollection());  supplyExpander.handleRemovedRealRequisitions(supplyTaskScheduler.getRemovedCollection()); handleRemovedRefills(refillSubscription.getRemovedCollection());
boolean touchedRemovedProjections = processRemoves();
  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 ((detReqHandler.getDetermineRequirementsTask(aggMILSubscription) != null) &&        (logOPlan != null)) {      if (rehydrateInvs) {        addRehydratedInventories(blackboard.query(new InventoryPredicate(supplyType)));        rehydrateInvs = false;      }      boolean touchedRemovedProjections =          supplyExpander.handleRemovedProjections(projectWithdrawTaskSubscription.getRemovedCollection());      supplyExpander.handleRemovedRequisitions(withdrawTaskSubscription.getRemovedCollection());      // The following is here because the above lies about what it does      supplyExpander.handleRemovedRealRequisitions(supplyTaskScheduler.getRemovedCollection());      handleRemovedRefills(refillSubscription.getRemovedCollection());      // If its the first time we've gotten this far we now have our policy, org and others.      // However, we may have missed some tasks on the added list in previous executes.      // If its the first time through use the underlying subscription collection      // instead of the added list.//      if (firstTimeThrough) {//         Enumeration newReqs = supplyTaskSubscription.elements();//         ArrayList newReqsCollection = new ArrayList();//         while (newReqs.hasMoreElements()) {//           newReqsCollection.add(newReqs.nextElement());//         }//         expandIncomingRequisitions(getTasksWithoutPEs(newReqsCollection));//         Enumeration newProjReqs = projectionTaskSubscription.elements();//         ArrayList newProjReqsCollection = new ArrayList();//         while (newProjReqs.hasMoreElements()) {//           newProjReqsCollection.add(newProjReqs.nextElement());//         }//         touchedProjections = expandIncomingProjections(getTasksWithoutPEs(newProjReqsCollection));//        expandIncomingRequisitions(getTasksWithoutPEs(supplyTaskSubscription));//        touchedProjections = expandIncomingProjections(getTasksWithoutPEs(projectionTaskSubscription));//        firstTimeThrough = false;//      } else {      Collection addedSupply = supplyTaskScheduler.getAddedCollection();      TimeSpan timeSpan = null;      if (turnOnTaskSched) {        timeSpan = supplyTaskScheduler.getCurrentTimeSpan();      } else {        timeSpan = new ScheduleElementImpl(getLogOPlanStartTime(),                                           getLogOPlanEndTime());      }      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();      TimeSpan timeSpan2 = null;      if (turnOnTaskSched) {        timeSpan2 = projectionTaskScheduler.getCurrentTimeSpan();      } else {        timeSpan2 = new ScheduleElementImpl(getLogOPlanStartTime(),                                            getLogOPlanEndTime());      }      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));//             unalloc = sortIncomingSupplyTasks(getTaskUtils().getUnallocatedTasks(nonrefillSubscription,// 										       Constants.Verb.Supply));//             if (!unalloc.isEmpty()){// 	      if (logger.isWarnEnabled())// 		logger.warn("TRYING TO ALLOCATE SUPPLY NONREFILL TASKS...");//               externalAllocator.allocateRefillTasks(unalloc);//             }          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));//             unalloc = sortIncomingSupplyTasks(getTaskUtils().getUnallocatedTasks(nonrefillSubscription,// 										       Constants.Verb.ProjectSupply));//             if (!unalloc.isEmpty()) {// 	      if (logger.isWarnEnabled())// 		logger.warn("TRYING TO ALLOCATE PROJECTION NONREFILL TASKS...");//               externalAllocator.allocateRefillTasks(unalloc);//             }          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());      takeInventorySnapshot(getInventoriesWithDeletions());      // touchedInventories and inventoriesWithDeletions should not be cleared until       // the end of transaction      touchedInventories.clear();      inventoriesWithDeletions.clear();      //backwardFlowInventories.clear(); //###      touchedProjections = false;      touchedChangedProjections = false;      OMChange = false;      //testBG();    }  }