class KPPMonitorControllerBehaviour extends CyclicBehaviour { KPPMonitorControllerBehaviour(Agent a) { super(a); myAgent = a; } private MessageTemplate getInternalPollingTemplate() { MessageTemplate i1 = MessageTemplate.MatchPerformative(ACLMessage.INFORM); MessageTemplate i2 = MessageTemplate.MatchLanguage("Plain-Text"); MessageTemplate i3 = MessageTemplate.MatchOntology("Ping KPPMonitor"); MessageTemplate i4 = MessageTemplate.and(i1, i2); MessageTemplate i5 = MessageTemplate.and(i4, i3); return i5; } public void action() { block(1000); //debug //System.out.println("KPPMonitor : KPPMonitorControllerBehaviour : action : At the start of the Controller Behaviour action() method"); //set-up a Receiver Behaviour ReceiverBehaviour rb = new ReceiverBehaviour(myAgent, masterHandle, -1); myAgent.addBehaviour(rb); try { //get the incoming message to this agent ACLMessage msg = masterHandle.getMessage(); //need to check the incoming message against known 'patterns' in order to determine behaviour to call //get the templates against which to match //HandleACTCommsBehaviour - template MessageTemplate hACBTemplate = ((KODAgent)myAgent).getACTMessageTemplate(); //Polling Notification Behaviour - template MessageTemplate pNBTemplate = this.getInternalPollingTemplate(); //UpdateConfigItemBehaviour - template MessageTemplate uCIBTemplate = ((KODAgent)myAgent).getUpdateTemplate(); //check the message received against each one of the templates if (hACBTemplate.match(msg)) { //debug System.out.println("KPPMonitor : KPPMonitorControllerBehaviour : action : About to call HandleACTCommsBehaviour"); //call the HandleACTCommsBehaviour myAgent.addBehaviour(new HandleACTCommsBehaviour(myAgent, msg)); } else if (pNBTemplate.match(msg)) { //debug System.out.println("KPPMonitor : KPPMonitorControllerBehaviour : action : About to call PollingNotificationBehaviour"); //call the HandleACTCommsBehaviour myAgent.addBehaviour(new PollingNotificationBehaviour(myAgent)); } else if (uCIBTemplate.match(msg)) { //debug System.out.println("KPPMonitor : KPPMonitorControllerBehaviour : action : About to call UpdateConfigItemBehaviour"); //call the UpdateConfigItemBehaviour myAgent.addBehaviour(new UpdateConfigItemBehaviour(myAgent, msg, KPPMonitor.CONFIG_FILE)); } else { //an unexpected message has been received throw a KODException throw new KODException("1A06-001 : An unexpected message has been received"); } } catch(ReceiverBehaviour.TimedOut rbte) { System.out.println("KPPMonitor : KPPMonitorControllerBehaviour : action : Timed Out => " +rbte.getMessage()); } catch(ReceiverBehaviour.NotYetReady rbnyr) { System.out.println("KPPMonitor : KPPMonitorControllerBehaviour : action : No Message Received"); } catch(KODException ke) { System.err.println("KPPMonitor : KPPMonitorControllerBehaviour : action : KODException : " +ke.getMessage()); writeLog(ke.getMessage()); } finally { rb.reset(); } }