0

I have one agent with its services that implements a CyclicBehaviour were and I wanna see those services or use its methods, how can I do it?

for example

Agent:

public class agent1 extends Agent {

int[] numbers= {11, 20, 40};
public void setup() {
    DFAgentDescription dfd = new DFAgentDescription();
    dfd.setName(getAID());
    ServiceDescription sd = new ServiceDescription();
    sd.setName("number");
    sd.setType(numbers[0]);
    sd.addOntologies("ontology");
    ..........
    sd.addNumbers(new SLCodec().getName());
    dfd.addServices(sd);

    try {
        DFService.register(this, dfd);
    }
    catch(FIPAException e) {
        System.err.println("Agente"+ getLocalName()+": "+ e.getMessage());
    }
};

public String getNumber()
{
    return idiomas;
}

}

Behaviour:

public class CyclicTraduce extends CyclicBehaviour {
 @Override
public void action() {
    // TODO Auto-generated method stub

    //I want to use getNumber method of agent here
}
}

1 Answers1

0

If the behaviour is used by agent1 then just use casting (without registering services)

((agent1) myAgent).getNumber()

otherwise you have to look for the registered services:

DFAgentDescription template = new DFAgentDescription();
ServiceDescription sd = new ServiceDescription();
sd.setType("type to be searched");
template.addServices(sd);

DFAgentDescription[] result = DFService.search(myAgent,template);
result[0].getName() // aid to send to in order to invoke the method

and send a message for agent1 that will invoke getNumber and reply with a result.

nikelyn
  • 518
  • 3
  • 13