Ebrahim Amini Sharifi
Ebrahim Amini Sharifi

Reputation: 1004

how execute an JADE agent from ordinary(not agent) java class?

I want to send message to an agent from other class that is not an agent. for example Servlet or main static class.

Upvotes: 2

Views: 455

Answers (1)

Ebrahim Amini Sharifi
Ebrahim Amini Sharifi

Reputation: 1004

This is an oridnary class not an agent:

        MainContainerAgentsRetriever retriever = new MainContainerAgentsRetriever();
        JadeGateway.execute(retriever);
        // At this point the retriever behaviour has been fully executed --> the list of 
        // agents running in the Main Container is available: get it and print it
        List agents = retriever.getAgents();

        if (agents != null) {
            System.out.println("Agents living in the Main Container: ");
            for (int i = 0; i < agents.size(); ++i) {
                System.out.println("- " + ((AID) agents.get(i)).getLocalName());

                ACLMessage msg = new ACLMessage();
                msg.addReceiver(((AID) agents.get(i)));
                msg.setContent("salam refigha");
                retriever.send(msg);



            }
        }

Upvotes: 1

Related Questions