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));
  protected void execute() {    //clear our new refill list    newRefills.clear();    // 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();        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());      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));        firstTimeThrough = false;      } else {        Collection addedSupply = supplyTaskSubscription.getAddedCollection();        if (!addedSupply.isEmpty()) {          expandIncomingRequisitions(getTasksWithoutPEs(addedSupply)); // fix for bug #1695        }        Collection changedSupply = supplyTaskSubscription.getChangedCollection();        if (!changedSupply.isEmpty()) {          supplyExpander.updateChangedRequisitions(changedSupply);        }        Collection addedProjections = projectionTaskSubscription.getAddedCollection();        if (!addedProjections.isEmpty()) {          // getTasksWithoutPEs is fix for bug #1695          touchedProjections = expandIncomingProjections(getTasksWithoutPEs(addedProjections));        }        Collection changedProjections = projectionTaskSubscription.getChangedCollection();        if (!changedProjections.isEmpty()) {          supplyExpander.updateChangedProjections(changedProjections);          touchedChangedProjections = true;// System.out.println("Touched changed projections in " + getAgentIdentifier() +//                                " type is" + getSupplyType());        }        // 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");          Collection unallocRefill = null;          if (addedSupply.isEmpty() && changedSupply.isEmpty()) {            unallocRefill = getTaskUtils().getUnallocatedTasks(refillSubscription,                                                                Constants.Verb.Supply);            if (!unallocRefill.isEmpty()){              logger.warn("TRYING TO ALLOCATE SUPPLY REFILL TASKS...");              externalAllocator.allocateRefillTasks(unallocRefill);            }          }          if (addedProjections.isEmpty() && changedProjections.isEmpty()) {            unallocRefill = getTaskUtils().getUnallocatedTasks(refillSubscription,                                                               Constants.Verb.ProjectSupply);            if (!unallocRefill.isEmpty()) {              logger.warn("TRYING TO ALLOCATE PROJECTION REFILL TASKS...");              externalAllocator.allocateRefillTasks(unallocRefill);            }          }        }      }      // 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();    }  }