import jade.core.AID;
import jade.domain.AMSService;
import jade.domain.FIPAAgentManagement.*;
public class Sender2 extends Agent {
protected void setup()
{
AMSAgentDescription [] agents = null;
AID Rams= new AID("ams@gjpc:1099/JADE");//获取gjpc机器上的ams
Rams.addAddresses("http://gjpc:7778/acc");
try {
SearchConstraints c = new SearchConstraints();
c.setMaxResults (new Long(-1));
//agents = AMSService.search( this, new AMSAgentDescription (), c );
//下面查找rams里面的agents
agents = AMSService.search( this, Rams, new AMSAgentDescription (), c );
}
catch (Exception e) {
System.out.println( "Problem searching AMS: " + e );
e.printStackTrace();
}
ACLMessage msg = new ACLMessage(ACLMessage.INFORM);
msg.setContent( "this is from guojie 's Ping" );//本地机器名为guojie
//逐个向他们发送消息
for (int i=0; i<agents.length;i++){
if ( agents[i].getName().equals(getAID()) ){
continue;
}
System.out.println(agents[i].getName().toString());
agents[i].getName().addAddresses("http://gjpc:7778/acc");
//这一句必须要有
msg.addReceiver( agents[i].getName() );
}
System.out.println("wait fro a minute...");
send(msg);
}
} |