Reputation: 17
I want to send file fron one agent to an other agent using JADE on same PC. Here some error which is occur during execution.
*** Uncaught Exception for agent a ***
ERROR: Agent a died without being properly terminated !!!
java.lang.RuntimeException: Uncompilable source code - incompatible types: java.lang.String cannot be converted to byte[]
State was 2
ERROR: Agent b died without being properly terminated !!!
State was 2
at sendmessage.A.sendMessage(A.java:36)
at sendmessage.A.setup(A.java:25)
at jade.core.Agent$ActiveLifeCycle.init(Agent.java:1490)
at jade.core.Agent.run(Agent.java:1436)
at java.lang.Thread.run(Thread.java:745)
Nov 20, 2015 4:21:34 PM jade.core.messaging.MessagingService removeLocalAliases
INFO: Removing all local alias entries for agent a
Nov 20, 2015 4:21:34 PM jade.core.messaging.MessagingService removeGlobalAliases
INFO: Removing all global alias entries for agent a
*** Uncaught Exception for agent b ***
java.lang.RuntimeException: Uncompilable source code - Erroneous sym type: sendmessage.B.MyBehaviour.receive
at sendmessage.B$MyBehaviour.action(B.java:40)
at jade.core.behaviours.Behaviour.actionWrapper(Behaviour.java:344)
at jade.core.Agent$ActiveLifeCycle.execute(Agent.java:1500)
at jade.core.Agent.run(Agent.java:1439)
at java.lang.Thread.run(Thread.java:745)
Nov 20, 2015 4:21:34 PM jade.core.messaging.MessagingService removeLocalAliases
INFO: Removing all local alias entries for agent b
Nov 20, 2015 4:21:34 PM jade.core.messaging.MessagingService removeGlobalAliases
INFO: Removing all global alias entries for agent b
Nov 20, 2015 4:21:42 PM jade.core.messaging.MessagingService removeLocalAliases
INFO: Removing all local alias entries for agent rma
Nov 20, 2015 4:21:42 PM jade.core.messaging.MessagingService removeGlobalAliases
INFO: Removing all global alias entries for agent rma
Sender:Who send file to another agent via using JADE. package sendmessage;
import jade.core.AID;
import jade.core.Agent;
import jade.core.behaviours.Behaviour;
import jade.lang.acl.ACLMessage;
import jade.lang.acl.MessageTemplate;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
/**
*
* @author Administrator
*/
public class A extends Agent {
protected void setup() {
sendMessage();
this.addBehaviour(new MyBehaviour(this));
}
private void sendMessage() {
AID r = new AID("b", AID.ISLOCALNAME);
// ACLMessage acl = new ACLMessage(ACLMessage.REQUEST);
// acl.addReceiver(r);
// acl.setContent("hello, my name is sender!");
// this.send(acl);
String fileName = "a.txt";// get file name
byte[] fileContent = "f://a.txt";// read file content
ACLMessage msg = new ACLMessage(ACLMessage.INFORM);
msg.addReceiver(r);
msg.setByteSequenceContent(fileContent);
msg.addUserDefinedParameter("file-name", fileName);
send(msg);
}
private static class MyBehaviour extends Behaviour {
MessageTemplate mt = MessageTemplate.MatchPerformative(ACLMessage.INFORM);
private static int finish;
public MyBehaviour(A aThis) {
}
@Override
public void action() {
ACLMessage acl = myAgent.receive(mt);
if (acl != null) {
System.out.println(myAgent.getLocalName() + " received a reply: " + acl.getContent() + "from " + acl.getSender());
finish = 1;
} else {
this.block();
}
}
@Override
public boolean done() {
return finish == 1;
}
}
}
Receiver: who receive file from send agent via using JADE
package sendmessage;
import jade.core.Agent;
import jade.core.behaviours.Behaviour;
import jade.lang.acl.ACLMessage;
import jade.lang.acl.MessageTemplate;
import java.io.File;
/**
*
* @author Administrator
*/
public class B extends Agent {
protected void setup() {
this.addBehaviour(new MyBehaviour(this));
}
private static class MyBehaviour extends Behaviour {
MessageTemplate mt = MessageTemplate.MatchPerformative(ACLMessage.REQUEST);
public MyBehaviour(B aThis) {
}
@Override
public void action() {
// ACLMessage acl = myAgent.receive(mt);
// if (acl!= null) {
// System.out.println(myAgent.getLocalName()+ " received a message: "+acl.getContent());
// ACLMessage rep = acl.createReply();
// rep.setPerformative(ACLMessage.INFORM);
// rep.setContent("ok, i received a message!");
// myAgent.send(rep);
ACLMessage msg = receive("Yes Received your file");
if (msg != null) {
String fileName = msg.getUserDefinedParameter("a.txt");
File f = "a.txt"; // create file called fileName
byte[] fileContent = msg.getByteSequenceContent();
// write fileContent to f
}
else {
this.block();
}
}
@Override
public boolean done() {
return false;
}
}
}
Upvotes: 1
Views: 1150
Reputation: 43
It is probably an idea to create an Ontology for your agent system if you are going to be exchanging files around alot. JADE offers the ability to use OntologyBean classes as representation of the Agent communication methods(which really simplifies things).
the BeanOntology class adds custom language in the form of predicates, concepts, etc. Inside these custom language descriptions you can place an object and any other information you may want to specify alongside it. It is actually quite simple if you follow the documentation provided from JADE --> tutorial here
good luck!
Upvotes: 1