logger.debug("============= Saw new Diagnosis (with UID="+d.getUID()+") -- Wrapping it.");
if (logger.isDebugEnabled()) logger.debug("============= Saw new Diagnosis (with UID="+d.getUID()+") -- Wrapping it.");
    protected void execute() {        Iterator iter;        boolean mgrJustFound = false;        //First check to see if we know where the manager is. If not, look it up (if shouldRelayDiagnoses == true).        if (managerAddress == null && shouldRelayDiagnoses) {            //Check to see if the Coordinator's address is known...            iter = managerAddressSubscription.getAddedCollection().iterator();            if (iter.hasNext()) {              // find & set the ManagerAgent address               managerAddress = ((RobustnessManagerID)iter.next()).getMessageAddress();               mgrJustFound = true; //signal that there might be unwrapped actions that need to be wrapped                                    // -- They weren't wrapped because the mgr wasn't found.               if (logger.isDebugEnabled()) logger.debug("ManagerAddress: "+managerAddress.toString());                              //Update the knob with status -- we know where the coordinator is               iter = knobSubscription.getCollection().iterator();                       if (iter.hasNext()) {                   diagnosesRelayManagerKnob = (DiagnosesRelayManagerKnob)iter.next();                   diagnosesRelayManagerKnob.setFoundCoordinator(managerAddress);               }                           } else {               if (logger.isDebugEnabled()) logger.debug("++++++++++++++++++++++++++++> ManagerAddress subscription empty.");            }                        }                if (managerAddress == null || !shouldRelayDiagnoses)             return; //we cannot forward diagnoses until we known where the coordinator is        //See if our knob has changed...        iter = knobSubscription.getChangedCollection().iterator();                if (iter.hasNext()) {            diagnosesRelayManagerKnob = (DiagnosesRelayManagerKnob)iter.next();            shouldRelayDiagnoses = diagnosesRelayManagerKnob.getShouldRelay();        }                //Wrap & Relay the diagnoses        if (shouldRelayDiagnoses) {                        Collection added = null;                        if (mgrJustFound) { //then all of the actions should need to be wrapped.                added = diagnosesSubscription.getCollection();                            } else {           //Only need to get all added Actions & wrap them with a ActionsWrapper                added = diagnosesSubscription.getAddedCollection();            }                                                for ( iter = added.iterator(); iter.hasNext() ; )             {                Diagnosis d = (Diagnosis)iter.next();                                if (d.getWrapper() == null) { //Make sure it wasn't already wrapped... just a precaution                    logger.debug("============= Saw new Diagnosis (with UID="+d.getUID()+") -- Wrapping it.");                    UID uid = this.us.nextUID(); //gen UID for this wrapper                    DiagnosesWrapper dw = new DiagnosesWrapper(d, this.agentId, managerAddress, uid); //wrap the diagnosis                    //registerUID(uid); //record all UIDs so we know what wrappers are out there.                    d.setWrapper(dw);                    this.publishAdd(dw);                                    //newWrappers.add(dw);                }            }                        //Now look at changed diagnoses            Collection changed  = diagnosesSubscription.getChangedCollection();                    Collection wrappers = wrapperSubscription.getCollection();  //should include the wrappers we just added!            //added.addAll(changed);            //wrappers.addAll(newWrappers); //add newly created wrappers (that aren't yet on the BB) to the ones from the BB            for ( iter = changed.iterator(); iter.hasNext() ; )             {                Diagnosis d = (Diagnosis)iter.next();                                //Find wrapper for this Diagnosis                DiagnosesWrapper dw = findWrapper(d, wrappers);                //runFilters                if (dw != null && runFilters(dw)) {                    this.publishChange(dw);                }                            }            //newWrappers.clear(); // clear this as these wrappers will now be committed to the BB                    }               }