if (log.isDebugEnabled()) {
if (log.isInfoEnabled()) {
  public void execute() {    // get the current time    long currTime = currentTimeMillis();    //    // Watch for added Assets    // LocalAssets should all happen at once in the first execute cycle.    // Entitys however will likely dribble in over time    // So create sorted lists of these separately, then combine them    // with entities after local.    // However, if we happen to do an allocation before all the assets    // are around, the rule indexes will be screwy, and we may have used    // the "wrong" rule.  Cant prevent it, but at least can log it.    if (localAssetSub.hasChanged()) {      // verify that the current time is 1      if (this.sortedlocalassets == null) {        // not efficient but okay.  Better would be to use        // a subclass of Subscription that maintains a sort	Collection addedC = localAssetSub.getAddedCollection();	// use Todd's sorting mechanism to sort this list of local assets	// Note that all local assets should arrive simultaneously	sortedlocalassets = sortAssets(addedC);	if (comboassets != null) {	  // UhOh! there are already some orgs in here! Error?	  if (log.isDebugEnabled()) {	    log.warn("execute: " + this + " got Entitys before local assets!");	  }	  // We could:	  //1: ignore the problem that some allocations may have happened,	  // and stick these in the front of the list	  List old = comboassets;	  comboassets = new ArrayList(sortedlocalassets);	  comboassets.addAll(old);	  // 2: we could give up on the original order intended, and put these at	  // the end of the list:	  // comboassets.addAll(sortedlocalassets);	} else {	  // These are the first assets to arrive	  if (log.isDebugEnabled()) {	    log.info("execute: " + this + " got first assets, locals");	  }	  if (haveAllocatedPastLocals) {	    if (log.isDebugEnabled()) {	      log.error("execute: " + this + " failed a previous allocation due to no rules at all, and now there are some. Why did they arrive late?");	    }	  }	  comboassets = sortedlocalassets;	}	if(log.isDebugEnabled()) {	  log.debug("execute:" + "asset size = " + comboassets.size());	}        // save the array of "expanded" rules        //   catch rollback by clobbering the field if already set        this.expandedRules =           handleCreatedAsset((List)comboassets);      } else {        if (log.isDebugEnabled()) {          log.debug(" ignoring assets created at time ("+ currTime+") > 1");        }        // System.exit(-1);      }    } // end of block checking for new Assets    // Handle incoming Entitys    // Note that these will trickle in, as some of them get sent over by tasks    // so we need to be careful in creating our list of expanded rules    if (entitySub.hasChanged()) {      Collection addedC = entitySub.getAddedCollection();      // If the subscription changed but no new entities were created, we dont care      // Although I suppose one might have been removed?      if (addedC == null || addedC.isEmpty()) {	// log something?       } else if (this.entityassets == null) {	// These are the first Entitys that are arriving	entityassets = sortAssets(addedC);	if (comboassets != null) {	  // this is sort of expected. We already have some local assets	  // Tack these on to the end	  // however, its conceivable that a Task will have been allocated already!!!	  // FIXME!!!	  if (log.isDebugEnabled()) {	    log.debug("execute: " + this + " got entities after some local assets. Tasks may have been allocated!");	  }	  if (log.isDebugEnabled()) {	    if (haveAllocatedPastLocals) {	      log.error("execute: " + this +                         " and weve done an allocation that either ran out " +                         "of rules and so would have been failed!");	    }	  }	  comboassets.addAll(entityassets);	} else {	  // Entitys arrived before local assets? Maybe there are none.	  if (log.isDebugEnabled()) {	    log.debug("execute: " + this + " got entities before any locals");	  }	  // Could I have a flag to notice if any tasks have been allocated?	  if (haveAllocatedPastLocals) {	    if (log.isDebugEnabled()) {	      log.error("execute: " + this + " previous allocation used an org or ran out of rules, and so might legitimately have used one of these new orgs. Next re-alloc might do something funny cause of rule index change.");	    }	  }	  // The problem is that I can't really stop the allocations altogether	  // FIXME!!	  comboassets = entityassets;	} // end of checks whether there are previous comboassets	      } else {	// entitys are trickling in.  Its possible we've already allocated a task!!!	if (log.isDebugEnabled()) {	  log.info("execute: " + this + " entitys are trickling in!");	}	if (haveAllocatedPastLocals) {	  if (log.isDebugEnabled()) {	    log.error("execute: " + this + " previously allocated to a non-local, so that allocation likely screwy.");	  }	}	// be sure to use the previous entity assets as well	entityassets.addAll(addedC);	entityassets = sortAssets(entityassets);	// Make combo have locals before these entities	// sortedlocalassets might be empty so far	if (sortedlocalassets != null && ! sortedlocalassets.isEmpty()) {	  comboassets = new ArrayList(sortedlocalassets);	} else {	  comboassets = new ArrayList();	}	comboassets.addAll(entityassets);      } // end of if block checking have entity assets already            if(log.isDebugEnabled()) {	log.debug("execute:" + "asset size = " + comboassets.size());      }            // save the array of "expanded" rules      //   catch rollback by clobbering the field if already set      this.expandedRules = 	handleCreatedAsset((List)comboassets);    } // end of loop over entity assets    //    // Watch for Tasks and generate an Allocation to a matching    // Asset, as specified in our rules.  If no such asset exists then     // generate an immedate "failed" Disposition    //    // Need to also generate a DeadlineTimerEvent on the Allocation.    //    if (taskSub.hasChanged()) {      // for each new task      for (Enumeration en = taskSub.getAddedList();           en.hasMoreElements();           ) {        Task t = (Task)en.nextElement();        if (log.isDebugEnabled()) {          log.debug(" received new task: "+t.getUID());        }        // allocate the task	// So this method we would expect to	// a) Generate an Allocation	// b) Generate a DeadlineTimer	// c) If however there is no rule that matches to allow us to do	// a & b above, then publish a "failed" Disposition.	// d) Else if there is not enought time, pub a Disposition saying so        allocate(t, -1, currTime, null);	if (t.getPlanElement() == null) {	  if (log.isDebugEnabled()) {	    log.error("execute: " + this + " allocated a task, but it says it has not PlanElement! Task: " + t);	  }	}      }      // AMH 7/8/2001: Should I look for removed tasks, to propagate the removal?      for (Enumeration en = taskSub.getRemovedList();	   en.hasMoreElements();) {	Task t = (Task)en.nextElement();	if (log.isDebugEnabled()) {	  log.debug("execute: " + this + " notified of removed Task: " + t.getUID());	}		// Look in my list of Allocations and remove any that match.	for (Enumeration en1 = allocationSub.elements(); en1.hasMoreElements(); ) {	  Allocation alloc = (Allocation)en1.nextElement();	  if (alloc.getTask().equals(t)) {	    // This Allocation must be removed.	    // But also, we could do a search through	    // my subscription for the deadline event, and remove that as well	    for (Enumeration en2 = deadlineSub.elements(); en2.hasMoreElements(); ) {	      DeadlineTimerEvent deadline = (DeadlineTimerEvent)en2.nextElement();	      if (deadline.getRegarding() instanceof Allocation && ((Allocation)deadline.getRegarding()).equals(alloc)) {		// This is the deadline corresponding to the Allocation		rescindDeadlineTimerEvent(deadline);		break;	      }	    } // end of loop to find deadline for this Allocation	    // Now rescind the Allocation	    rescindAllocation(alloc);	    break;	  }	} // end of loop to find Allocation of removed task	// Now I also might have published a Disposition of that Task	// I don't have a subscription to those, but I could query	// the Blackboard	// FIXME!!!      } // end of loop over removed tasks.    } // end of block checking for new tasks to allocate    // Handle changes to published Allocations        //  On getting a change in an Alloc:    //  - If new AR not high-conf, do nothing    //  - else if high conf AR is success, copy reported to Estimated    //  - else if have additional matching rules    //    -- rescind previous Alloc    //    -- pub new Alloc, Deadline    //  - else its a failure with no more matching rules.    //  -- rescind the Allocation and instead publish a failure Disposition,    // whose reason lists the failure reason listed on the Alloc's failed AR.    if (allocationSub.hasChanged()) {      // For each allocation which has changed (new AR)      for (Enumeration en = allocationSub.getChangedList();           en.hasMoreElements();           ) {        Allocation alloc = (Allocation)en.nextElement();	// FIXME! Maybe make sure that the change was a change to the ReportedResult	if (alloc.getReportedResult() == null || alloc.getReportedResult().equals(alloc.getEstimatedResult())) {	  // either there is no reported result or its already the same as the estimated result	  // so ignore this	  if (log.isDebugEnabled()) {	    log.info("execute: " + this + " allocationSub fired but this alloc did not have a ReportedResult or its same as the Estimated, skipping: " + alloc);	  }	  continue;	}	AllocationResult estAR = alloc.getEstimatedResult();	if (estAR != null && estAR.getConfidenceRating() > successBorder) {	  // this Allocation already has a high confidence EstimatedResult - theres nothing	  // to do here	  if (log.isDebugEnabled()) {	    log.info("execute: " + this + " allocationSub fired but this alloc allready has a high conf. Estimated result, skipping: " + alloc);	  }	  continue;	}	if (getAllocRuleIndex(alloc) <= -100) {	  // Our marker that we rescinded an Allocation	  // or propagated its success up is already here	  // dont do anything more	  if (log.isDebugEnabled()) {	    log.error("execute: " + this + " woke up with Allocation Id otherwise try to handle, but it has the rule index marker: " + alloc);	  }	  continue;	}	// What about using changeReports? Only works if Executor fixed//  	if (! PlugInHelper.checkChangeReports(allocationSub.getChangeReports(alloc), PlanElement.ReportedResultChangeReport.class)) {//  	  // This Allocation did not change due to a ReportedResult change//  	  if (log.isDebugEnabled()) {//  	    log.info("execute: " + this + " allocationSub fired but this alloc did not have the ReportedResult change according to the change reports, skipping: " + alloc);//  	  }//  	  continue;//  	}        handleAllocation(            alloc,            currTime);      }    } // end of block checking for new responses    if (deadlineSub.hasChanged()) {      // for each new deadline ExceededEvent      for (Enumeration en = deadlineSub.getAddedList();          en.hasMoreElements();          ) {        DeadlineTimerEvent d =           (DeadlineTimerEvent)en.nextElement();        handleDeadlineEvent(            d,            currTime);      }    } // end of check of new DeadlineTimerEvents//      if (log.isDebugEnabled()) {//        log.debug("execute: " + this + " exitting execute loop");//      }  } // end of execute()