Permalink
Browse files

organize examples a bit

  • Loading branch information...
1 parent 370bef3 commit 647dff63ba94e3738f446f1e7fc7974c8342bab7 @gleber committed Dec 17, 2011
@@ -0,0 +1,43 @@
+import jade.core.Agent;
+import jade.core.AID;
+import jade.lang.acl.ACLMessage;
+import jade.core.behaviours.CyclicBehaviour;
+import jade.lang.acl.MessageTemplate;
+
+public class JADEAgent extends Agent {
+
+private MessageTemplate template =
+ MessageTemplate.MatchPerformative(ACLMessage.REQUEST);
+
+protected void setup() {
+ System.out.println("[Agent: "+this.getLocalName() +
+ "] Starting");
+
+ addBehaviour(new CyclicBehaviour(this) {
+ public void action() {
+ ACLMessage msg = myAgent.receive(template);
+ if (msg != null) {
+ System.out.println("[Agent: " +
+ myAgent.getLocalName() +
+ "] Request received from agent " +
+ msg.getSender().getName());
+ }
+ else {
+ block();
+ }
+ }
+ } );
+
+ sendMessage();
+}
+
+private void sendMessage() {
+ AID r = new AID ("the_exat_agent@exatplatform", AID.ISGUID);
+ r.addAddresses("http://localhost:7779/acc");
+ ACLMessage aclMessage = new ACLMessage(ACLMessage.REQUEST);
+ aclMessage.addReceiver(r);
+ aclMessage.setContent("ping");
+ this.send(aclMessage);
+}
+}
+
@@ -0,0 +1,33 @@
+-module(exat_agent).
+-export([extends/0]).
+-export([pattern/2,event/2,action/2,on_starting/1,
+ do_request/4,start/0]).
+-include_lib("exat/include/acl.hrl").
+-include_lib("exat/include/fipa_ontology.hrl").
+
+extends()-> nil.
+
+pattern(Self, request)-> [#aclmessage{speechact='REQUEST'}].
+
+event(Self, evt_request)-> {acl, request}.
+
+action(Self, start)-> {evt_request, do_request}.
+
+fellow_agent()-> #'agent-identifier'{
+ name = "jadeagent@jadeplatform",
+ addresses = ["http://localhost:7778/acc"]}.
+
+on_starting(Self)->
+ io:format("[Agent:~w] Starting\n", [object:agentof(Self)]),
+ acl:sendacl(#aclmessage{speechact = 'REQUEST',
+ content = "ping", sender = Self,
+ receiver = fellow_agent()}).
+
+do_request(Self, EventName, Message, ActionName)->
+ io:format("[Agent:~w] Request received from agent ~p\n",
+ [object:agentof(Self), Message#aclmessage.sender]),
+ object:do(Self, start).
+
+start()->
+ agent:new(the_exat_agent,[{behaviour, exat_agent}]).
+
File renamed without changes.
File renamed without changes.

0 comments on commit 647dff6

Please sign in to comment.