0

I'm quite new to Jade and multi agent systems. I'm trying to build a system with several agents who will have to communicate by sending ACLMessages. I've read documentation about the structure of how to build an Agent Class.

Here is my code:

public class ServerCommunicationAgent extends Agent {
    public static String serverAddress = "http://LO-LESTER-077:8080";
    private static final long serialVersionUID = 1L;

    protected void setup() {
        System.out.println(getLocalName() + ": correctly started");
        boolean state = true;

        // A Class that has a socket with my server
        CommunicationService.getInstance().ServerCommunicationAgent(state); 

        // Sends a tick every millisecond
        addBehaviour(new TickerBehaviour(this, 10000) {
            private static final long serialVersionUID = 1L;
            @Override
            protected void onTick() {
                ACLMessage message = new ACLMessage(ACLMessage.INFORM);
                message.setContent("OK");
                message.setLanguage("English");
                message.setOntology("Test Dialogue");
                message.setConversationId("TestID");
                message.addReceiver(new AID("SecurityAgent", AID.ISLOCALNAME));
                send(message);
            }    
        }); 
    }

    // This method is called from CommunicationService when i have a response
    public void LaunchServiceAgent(final String Agent, final String Location){
        System.out.println(": Agent received service request: " + Agent + " in " + Location + " and has to call " + Agent + Location);

        addBehaviour(new Behaviour(this) {
            private static final long serialVersionUID = 1L;

            @Override
            public void action() {
                ACLMessage messages = new ACLMessage(ACLMessage.INFORM);
                messages.setContent("Hello world");
                messages.setLanguage("English");
                messages.setOntology("Test Dialogue");
                messages.setConversationId("TestID");
                messages.addReceiver(new AID(Agent + Location, AID.ISLOCALNAME));
                send(messages);
            }

            @Override
            public boolean done() {
                return false;
            }
       });
}

So as i explained in my code, when the agent starts, it sends a message to my server. It receives a message through LaunchServiceAgent method. I correctly receive my message but i'm unable to send it to another agent using an ACLMessage. I think my code is correct because my TickBehaviour works fine.

So my question is, how do i correctly send a message to another Agent from my method?

Thanks for any response :)

Mike Causer
  • 8,196
  • 2
  • 43
  • 63
Nicola
  • 1
  • 1

2 Answers2

0

You must set a template when you send the message and match it to the conversation id. The agent receiving the message must check if the template is matched.

0

Your LauchServiceAgent(...) method is never returning, because you always return 'false' in the done() method. This could be causing your troubles, as your method never ends, it get stuck.

One option to fix that is to use a OneShotBehaviour(), which automatically executes once and auto-finishes. Another option is to set a variable to 'true' right after successfully sending your message [after 'send(message);'] and making done() return this variable.

Advice: use the predefined types of behaviours whenever possible to avoid some headaches [OneShotBehaviour, SimpleBehaviour, etc].

shirowww
  • 533
  • 4
  • 18