Enumeration enum = w.getTasks(); while (enum.hasMoreElements()) { Task subT = (Task)enum.nextElement();
Enumeration en = w.getTasks(); while (en.hasMoreElements()) { Task subT = (Task)en.nextElement();
  public static boolean isTaskConsistent(      MessageAddress self,      Logger logger,      LogPlan logplan,      Task t,      String type) {    // New local tasks should have a parent on the BBoard    // That parent when tracing down should claim this task     // If the parent was expanded, then it's Exp should be same    // as the task's workflow's Exp, and similarly the Workflows    // should be the same. And the Exp should be on the BBoard    // 1: pT on bb (if local task claiming a pT)    // 2: pT has PE    // 3: pT's PE is on bb    // 4: If pT is Exp, it's workflow == t.getWorkflow != null    // 5: if had workflow, it claims this task    // 6: else if pT's PE is All,  it's getAllocationTaskUID() == t.getUID()    // 7: else if pT's PE is Agg???? This task should be the MPTask    // Note: Could put public helper in TaskImpl that takes    // result of logplan.findTask(pUID), logplan.findPlanElement(parent)    // -- or a ref to the logplan I suppose --,    // and the self MessageAddress    // Maybe cleaner that way?    // If using Debug logging, then do all checks    // even after one fails    boolean debug = false;    if (logger.isDebugEnabled())      debug = true;    boolean result = true;    // Infrastructure could have removed this task already,    // leaving it in an inconsistent state not worth checking    Task bT = logplan.findTask(t.getUID());    if (bT == null) {      if (logger.isDebugEnabled())	logger.debug(self + ": " + type + " removed by the time I looked: " + t);      return true;    } else if (bT != t) {      if (logger.isInfoEnabled())	logger.info(self + ": " + type + " doesn't match what logplan had for this UID. Checking task: " + t + ". LogPlan has: " + bT);      if (! debug)	return false;      else	result = false;    }    UID pUID = t.getParentTaskUID();    MessageAddress dest = t.getSource();    Workflow w = t.getWorkflow();    // If pUID is non-null && local,     if (pUID != null && (self == dest || self.equals(dest.getPrimary()))) {      // 1: this UID should be on the LogPlan.      Task parent = logplan.findTask(pUID);      if (parent == null) {	// PROBLEM: Local task claims parent not on LogPlan	if (logger.isInfoEnabled())	  logger.info(self + ": " + type + " (local)'s parent not found on LogPlan: " + t);	// Should later remove this task	if (! debug)	  return false;	else	  result = false;	// Local task with parent avail	if (w == null) {	  // Added task whose parent is missing with no workflow.	  // Nothing more to check.	  return result;	} else {	  // Look at the workflow: Does it contain me?	  boolean hasSub = false;	  synchronized (w) {	    Enumeration enum = w.getTasks();	    while (enum.hasMoreElements()) {	      Task subT = (Task)enum.nextElement();	      if (subT == t) {		hasSub = true;		break;	      }	    }	  }	  	  if (! hasSub) {	    if (logger.isInfoEnabled()) 	      logger.info(self + ": " + type + "'s workflow does not contain this task. Task: " + t + ", workflow: " + w);	    if (! debug)	      return false;	    else	      result = false;	  }	  	  // Does it point to the same task as I point to?	  Task wPTask = w.getParentTask();	  if (wPTask != null) {	    if (wPTask.getUID().equals(pUID)) {	      parent = wPTask;	      if (logger.isDebugEnabled())		logger.debug(self + ": " + type + " whose parent was missing had a workflow that still pointed to the parent task. Task: " + t);	    } else {	      if (logger.isInfoEnabled())		logger.info(self + ": " + type + " whose parent was missing had a workflow that pointed to a different parent task. Task: " + t + ", workflow: " + w);	      // So the parent was not on the LogPlan, and the workflow	      // pointed to a different parent. Bail out.	      // FIXME: Could check to see if that wf's parent task refers back to this workflow and/or is on the bboard & of course it's planelement	      return false;	    }	  } else {	    // local task with no parent but workflow also missing parent	    // is a rescind in progress? From above,	    // this task will be marked inconsistent already	    if (logger.isInfoEnabled())	      logger.info(self + ": " + type + " with missing parent whose workflow's parent link is null. Task: " + t);	    return false;	  }	} // missing parent but had a workflow      } // end of block handling missing parent task      // Get here means the local parent was found.	      // 2: It should also have a non-null PE      PlanElement ppe = parent.getPlanElement();      PlanElement bppe = logplan.findPlanElement(parent);      if (ppe == null) {	// problem	if (logger.isInfoEnabled()) 	  logger.info(self + ": " + type + "'s parent has no PE. Task: " + t + ". Logplan lists pe: " + (bppe != null ? (bppe.getUID() + ":") : "") + bppe);	// Should later remove both this task and the parent!!! FIXME!!!	// Or maybe the parent is OK?	if (! debug)	  return false;	else	  result = false;	// If the parent has no plan element, what else can I check?	if (w == null) {	  // Added task whose parent's planelement is missing with no workflow.	  // Nothing more to check.	  if (logger.isInfoEnabled())	    logger.info(self + " " + type + " whose parent task's planelement is missing and has no workflow. Task: " + t + ", parent: " + parent);	  return result;	} else {	  // Look at the workflow: Does it contain me?	  boolean hasSub = false;	  synchronized (w) {	    Enumeration enum = w.getTasks();	    while (enum.hasMoreElements()) {	      Task subT = (Task)enum.nextElement();	      if (subT == t) {		hasSub = true;		break;	      }	    }	  }	  	  if (! hasSub) {	    if (logger.isInfoEnabled()) 	      logger.info(self + ": " + type + "'s workflow does not contain this task. Task: " + t + ", workflow: " + w);	    if (! debug)	      return false;	    else	      result = false;	  }	  	  // Does it point to the same task as I point to?	  Task wPTask = w.getParentTask();	  if (wPTask != null) {	    if (wPTask == parent) {	      if (logger.isDebugEnabled())		logger.debug(self + ": " + type + " whose parent's PE was missing had a workflow that still pointed to the parent task. Task: " + t);	    } else {	      if (logger.isInfoEnabled())		logger.info(self + ": " + type + " whose parent's PE was missing had a workflow that pointed to a different parent task. Task: " + t + ", workflow: " + w);	      // So the parent's PE was not on the LogPlan, and the workflow	      // pointed to a different parent. Bail out.	      // FIXME: Could check to see if that wf's parent task refers back to this workflow and/or is on the bboard & of course it's planelement	      return false;	    }	  } else {	    // This task's workflow didn't point back to the task's parent!	    if (logger.isInfoEnabled())	      logger.info(self + ": " + type + " had parent missing PE & a workflow without a parent task. Task: " + t + ", workflow: " + w);	    return false;	  }	} // missing parent's PE but had a workflow	return false;      } // handle no PE from parent task