Вопрос

I'm currently using Topic based communication using JADE. I'm able to register a JADE agent using jade.core.messaging.TopicManagementFEService thereby connecting to the main-container in the same platform.

The details are below:

  1. Main-Container: a simple LAMP/WAMP Server that hosts the Main-Container.
  2. Client: An Android Emulator(testing purpose) to connect to the main-container.

Currently,

  1. Server starts the main-container
  2. Android emulator connects to the Main-container successfully (Agent created along with Topic Mgmt Service enabled)
  3. Server is sending messages based on a specific topic.

But my Android Client is not able to receive this message although the topic registered is the same on both ends!

You can see the code below:

Server Side:

TopicManagementHelper topicHelper = (TopicManagementHelper) getHelper(TopicManagementHelper.SERVICE_NAME);
final AID sensorTopic = topicHelper.createTopic("JADE");
topicHelper.register(sensorTopic);

addBehaviour(new TickerBehaviour(this, TIMER_VALUE_IN_MILLISECONDS) {

private static final long serialVersionUID = -2567778187494378326L;

    public void onTick() {

        ACLMessage msg = new ACLMessage(ACLMessage.INFORM);
        msg.addReceiver(eventTopic);
        msg.setContent(eventValue);
        myAgent.send(msg);
    }
});

Android Side:

// Registering on Android Side as well
TopicManagementHelper topicHelper = (TopicManagementHelper) getHelper(TopicManagementHelper.SERVICE_NAME);
topic = topicHelper.createTopic("JADE"); // See, same topic!
topicHelper.register(topic);

behaviour = new myBehaviour(this, TIMER_VALUE_IN_MILLISECONDS, topic);
addBehaviour(behaviour);

private class myBehaviour extends TickerBehaviour {

 private static final long serialVersionUID = 4782913834042415090L;
 AID topic;
 Agent agent;
 MessageTemplate tpl;

   public myBehaviour(Agent a, long period, AID topic) {
    super(a, period);

    this.agent = a;
    this.topic = topic;
   }

   public void onTick() {
    tpl = MessageTemplate.MatchTopic(topic);
    ACLMessage msg = receive(tpl);
    if (msg != null) {
       logger.log(Level.INFO, "Agent "+ agent.getLocalName() + 
                           ": Message about topic "+ topic.getLocalName() +" received. \n" +
                                    "Content is " + msg.getContent());
       data = msg.getContent();

    } else {
       logger.log(Level.INFO, "In here..."); // Always executes only this code!
       block();
    }
  }
}

Where am I going wrong here? It always executes the else part in the Android side which is obvious to say that message received is NULL!

Это было полезно?

Решение

Never mind. The logic was wrong. The Android-Agent was not identifying itself to the Central-Agent.

I set the Ontology so that the Central Agent is able to identify such message and sends the message accordingly. Now, it is receiving messages!

Self-help works sometimes! ;-)

Другие советы

Receiving topic messages doesn't work correctly with Android up to version 4.3.0 in JADE. Android can send out topic messages but can't receive them. I found this out through my own issues. I've posted more info about it in my own question on stack overflow.

Take a look. JADE Leap Android App unable to receive topic messages

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top