if (! Level6OMSubscription.getChangedCollection().isEmpty()) { long currentLevel6 = getEndOfLevelSix(); if (currentLevel6 > prevLevel6) { OMChange = true; }  prevLevel6 = currentLevel6; }
  protected void execute() {    //clear our new refill list    newRefills.clear();    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 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 (currentLevel6 > prevLevel6) {          OMChange = true;        }        //reset the previous level 6 to the current        prevLevel6 = currentLevel6;       }      // 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());	}        // call the Refill Generators if we have new demand        if (! getTouchedInventories().isEmpty()) {	  //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);           }        }                  // 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();      }    }  }