Zadanie 1
This commit is contained in:
@@ -24,10 +24,15 @@ public class ServiceAgent extends Agent
|
||||
ServiceDescription sd2 = new ServiceDescription();
|
||||
sd2.setType("answers");
|
||||
sd2.setName("dictionary");
|
||||
//service no 3
|
||||
ServiceDescription sd3 = new ServiceDescription();
|
||||
sd3.setType("answers");
|
||||
sd3.setName("gcide");
|
||||
|
||||
//add them all
|
||||
dfad.addServices(sd1);
|
||||
dfad.addServices(sd2);
|
||||
dfad.addServices(sd3);
|
||||
|
||||
try
|
||||
{
|
||||
@@ -40,6 +45,7 @@ public class ServiceAgent extends Agent
|
||||
|
||||
addBehaviour(new WordnetCyclicBehaviour(this));
|
||||
addBehaviour(new DictionaryCyclicBehaviour(this));
|
||||
addBehaviour(new GCIDECyclicBehaviour(this));
|
||||
//doDelete();
|
||||
}
|
||||
protected void takeDown()
|
||||
@@ -93,6 +99,46 @@ public class ServiceAgent extends Agent
|
||||
}
|
||||
}
|
||||
|
||||
class GCIDECyclicBehaviour extends CyclicBehaviour
|
||||
{
|
||||
ServiceAgent agent;
|
||||
|
||||
|
||||
public GCIDECyclicBehaviour(ServiceAgent agent)
|
||||
{
|
||||
this.agent = agent;
|
||||
}
|
||||
|
||||
|
||||
public void action()
|
||||
{
|
||||
MessageTemplate template = MessageTemplate.MatchOntology("gcide");
|
||||
ACLMessage message = agent.receive(template);
|
||||
if (message == null)
|
||||
{
|
||||
block();
|
||||
}
|
||||
else
|
||||
{
|
||||
//process the incoming message
|
||||
String content = message.getContent();
|
||||
ACLMessage reply = message.createReply();
|
||||
reply.setPerformative(ACLMessage.INFORM);
|
||||
String response = "";
|
||||
try
|
||||
{
|
||||
response = agent.makeRequest("gcide",content);
|
||||
}
|
||||
catch (NumberFormatException ex)
|
||||
{
|
||||
response = ex.getMessage();
|
||||
}
|
||||
reply.setContent(response);
|
||||
agent.send(reply);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class WordnetCyclicBehaviour extends CyclicBehaviour
|
||||
{
|
||||
ServiceAgent agent;
|
||||
|
||||
Reference in New Issue
Block a user