From c70f5ee157d248f37b6de5f32a81fe7c0a2e0dfb Mon Sep 17 00:00:00 2001 From: pbarros Date: Fri, 9 Mar 2012 18:12:34 -0300 Subject: [PATCH] Adicionado agente Aprendiz, Mediador e Dominio --- .../org/ufcspa/simdecs/agent/AprendizAgent.java | 53 ++++++++++++++++++++ .../org/ufcspa/simdecs/agent/DominioAgent.java | 53 ++++++++++++++++++++ .../org/ufcspa/simdecs/agent/MediadorAgent.java | 53 ++++++++++++++++++++ 3 files changed, 159 insertions(+), 0 deletions(-) create mode 100644 src/java/org/ufcspa/simdecs/agent/AprendizAgent.java create mode 100644 src/java/org/ufcspa/simdecs/agent/DominioAgent.java create mode 100644 src/java/org/ufcspa/simdecs/agent/MediadorAgent.java diff --git a/src/java/org/ufcspa/simdecs/agent/AprendizAgent.java b/src/java/org/ufcspa/simdecs/agent/AprendizAgent.java new file mode 100644 index 0000000..7030cb1 --- /dev/null +++ b/src/java/org/ufcspa/simdecs/agent/AprendizAgent.java @@ -0,0 +1,53 @@ +package org.ufcspa.simdecs.agent; +/***************************************************************** + +Agent which answers all messages with a "Pong" + +*****************************************************************/ + + +import jade.core.Agent; +import jade.core.behaviours.*; +import jade.lang.acl.*; + +import jade.domain.DFService; +import jade.domain.FIPAAgentManagement.*; +import jade.domain.FIPAException; + +public class AprendizAgent extends Agent +{ + + protected void setup() + { + + // pong behaviour + addBehaviour(new CyclicBehaviour(this) + { + public void action() + { + ACLMessage msg = receive(); + String content= ""; + if (msg!=null) { + content= + "
- " + myAgent.getLocalName() + " received: " + msg.getContent()+ + "
- " + myAgent.getLocalName() + " sent: " + "Pong"; + + ACLMessage reply = msg.createReply(); + reply.setPerformative( ACLMessage.INFORM ); + reply.setContent(content); + send(reply); + System.out.print(content); + } + else block(); + } + }); + + } + + protected void takeDown() + { + try { DFService.deregister(this); } + catch (Exception e) {} + } +} + diff --git a/src/java/org/ufcspa/simdecs/agent/DominioAgent.java b/src/java/org/ufcspa/simdecs/agent/DominioAgent.java new file mode 100644 index 0000000..6d006d6 --- /dev/null +++ b/src/java/org/ufcspa/simdecs/agent/DominioAgent.java @@ -0,0 +1,53 @@ +package org.ufcspa.simdecs.agent; +/***************************************************************** + +Agent which answers all messages with a "Pong" + +*****************************************************************/ + + +import jade.core.Agent; +import jade.core.behaviours.*; +import jade.lang.acl.*; + +import jade.domain.DFService; +import jade.domain.FIPAAgentManagement.*; +import jade.domain.FIPAException; + +public class DominioAgent extends Agent +{ + + protected void setup() + { + + // pong behaviour + addBehaviour(new CyclicBehaviour(this) + { + public void action() + { + ACLMessage msg = receive(); + String content= ""; + if (msg!=null) { + content= + "
- " + myAgent.getLocalName() + " received: " + msg.getContent()+ + "
- " + myAgent.getLocalName() + " sent: " + "Pong"; + + ACLMessage reply = msg.createReply(); + reply.setPerformative( ACLMessage.INFORM ); + reply.setContent(content); + send(reply); + System.out.print(content); + } + else block(); + } + }); + + } + + protected void takeDown() + { + try { DFService.deregister(this); } + catch (Exception e) {} + } +} + diff --git a/src/java/org/ufcspa/simdecs/agent/MediadorAgent.java b/src/java/org/ufcspa/simdecs/agent/MediadorAgent.java new file mode 100644 index 0000000..23dba9d --- /dev/null +++ b/src/java/org/ufcspa/simdecs/agent/MediadorAgent.java @@ -0,0 +1,53 @@ +package org.ufcspa.simdecs.agent; +/***************************************************************** + +Agent which answers all messages with a "Pong" + +*****************************************************************/ + + +import jade.core.Agent; +import jade.core.behaviours.*; +import jade.lang.acl.*; + +import jade.domain.DFService; +import jade.domain.FIPAAgentManagement.*; +import jade.domain.FIPAException; + +public class MediadorAgent extends Agent +{ + + protected void setup() + { + + // pong behaviour + addBehaviour(new CyclicBehaviour(this) + { + public void action() + { + ACLMessage msg = receive(); + String content= ""; + if (msg!=null) { + content= + "
- " + myAgent.getLocalName() + " received: " + msg.getContent()+ + "
- " + myAgent.getLocalName() + " sent: " + "Pong"; + + ACLMessage reply = msg.createReply(); + reply.setPerformative( ACLMessage.INFORM ); + reply.setContent(content); + send(reply); + System.out.print(content); + } + else block(); + } + }); + + } + + protected void takeDown() + { + try { DFService.deregister(this); } + catch (Exception e) {} + } +} + -- 1.7.6.4