public void execute() { if (!toPublish.isEmpty()) { fireAll(); } for (Iterator it = diagnosisSubscription.getChangedCollection().iterator(); it.hasNext(); ) { AgentLivenessDiagnosis diagnosis = (AgentLivenessDiagnosis) it.next(); if (logger.isDebugEnabled()) { logger.debug("Changed diagnosis: " + diagnosis); } } for (Iterator it = actionSubscription.getChangedCollection().iterator(); it.hasNext(); ) { AgentRestartAction action = (AgentRestartAction) it.next(); Set newPV = action.getNewPermittedValues(); action.clearNewPermittedValues(); if (logger.isDebugEnabled()) { logger.debug("Changed action: " + action); } if (newPV != null && newPV.contains(RESTART_ACTION)) { opmodeEnabled(action.getAssetName()); } } // Detected Coordinator presence if (!coordinatorEnabled) { if (!coordSubscription.isEmpty()) { coordinatorEnabled = true; for (Iterator it = listeners.iterator(); it.hasNext(); ) { CoordinatorListener cl = (CoordinatorListener) it.next(); cl.coordinatorEnabled(); } } } }
public void setupSubscriptions() { diagnosisSubscription = (IncrementalSubscription) getBlackboardService() .subscribe( new UnaryPredicate() { public boolean execute(Object o) { return o instanceof AgentLivenessDiagnosis; } }); actionSubscription = (IncrementalSubscription) getBlackboardService() .subscribe( new UnaryPredicate() { public boolean execute(Object o) { return o instanceof AgentRestartAction; } }); // Check for evidence of Coordinator coordinatorEnabled = !getBlackboardService().query(coordPred).isEmpty(); if (coordinatorEnabled) { for (Iterator it = listeners.iterator(); it.hasNext(); ) { CoordinatorListener cl = (CoordinatorListener) it.next(); cl.coordinatorEnabled(); } } else { // No evidence found, watch for BB publication coordSubscription = (IncrementalSubscription) getBlackboardService().subscribe(coordPred); } }
public void addListener(CoordinatorListener cl) { if (!listeners.contains(cl)) { listeners.add(cl); } if (coordinatorEnabled) { for (Iterator it = listeners.iterator(); it.hasNext(); ) { CoordinatorListener l = (CoordinatorListener) it.next(); l.coordinatorEnabled(); } } }
/** * This method should be invoked when the defense is activated (i.e., restart is initiated). * * @param name the agent to be restarted */ public void opmodeEnabled(String agentName) { if (logger.isDetailEnabled()) { logger.detail("opmodeEnabled: agent=" + agentName); } if (!actionsInProcess.contains(agentName)) { actionsInProcess.add(agentName); Coordination coordObj = (Coordination) agents.get(agentName); if (coordObj != null) { for (Iterator it = listeners.iterator(); it.hasNext(); ) { CoordinatorListener cl = (CoordinatorListener) it.next(); cl.actionEnabled(agentName); } try { coordObj.action.start(RESTART_ACTION); } catch (Exception ex) { logger.error("Exception calling Coordinator start(): " + ex); } } } }