?? externalaccessagent.java
字號:
package examples.externalCom;
import FIPA.*;
import FIPA.ACL.*;
import FIPA.ACL.Content.*;
import javax.swing.JOptionPane;
import de.ikv.grasshopper.communication.GrasshopperAddress;
import de.ikv.grasshopper.communication.ProxyGenerator;
import de.ikv.grasshopper.type.Identifier;
import de.ikv.grasshopper.agency.AgentCreationFailedException;
/**
* This class represents an agent initiating a conversation.
* The user has to specify the agent at whom this message is directed. If both receiver and sender agent are on the
* same grasshopper agency, the name of the agent is enough for the message to come through to the other side.
* If the agent runs on another agency, the name should include the address of the other agent.
*/
public class ExternalAccessAgent extends FIPAAgent{
public static String Gpdm="";
public static String Gpjg="";
public static String Gpgs="";
public static String Yssj="";
public void init(Object args[]){
if (args.length < 5){
log("Creation arguments needed: <ComReceiverAddress>");
log("Exiting.");
}
String serverObjectAddr = (String)args[0];
Gpdm = (String)args[1];
Gpjg = (String)args[2];
Gpgs = (String)args[3];
Yssj = (String)args[4];
// do nothing here.
}
public String getName(){
return "SenderAgent";
}
public void live(){
this.registerWithLocalDF();
this.action();
}
private ACLMessage createMessage(String receiver){
try{
return new ACLMessage("<mesg reply-with=\"greeting\" type=\"inform\">" +
"<receiver>" +
"<agent>" +
receiver +
"</agent>" +
"</receiver>" +
"<sender>" +
"<agent>" +
this.getAgentName() +
"</agent>" +
"</sender>" +
"<content>" +
"<sl>" +
"<cblock>" +
""+Gpdm+","+Gpjg+","+Gpgs+","+Yssj+"" +
"</cblock>" +
"</sl>" +
"</content>" +
"</mesg>" );
}catch(Exception e){
System.out.println("SenderAgent: Exception " + e.toString());
}
return null;
}
/**
* The onRemove() method of Agent is overwritten so that the agent can
* deregister itself from the DF.
*/
public void onRemove(){
this.deRegisterWithLocalDF();
}
public void action(){
//String receiver = JOptionPane.showInputDialog("Enter receiver: <receiverName>[@address]");
String receiver ="ReceiverAgent";
if (receiver == null || receiver.equals("")){
// do nothing
}else{
System.out.println("Creating message");
ACLMessage message = this.createMessage(receiver);
if (message != null){
System.out.println("SenderAgent: Sending message to " + receiver);
String s = message.toString();
System.out.println(s);
this.send(s);
}
}
try{
remove();}
catch(Exception e){
System.out.println("Remove Fail!");
};
}
public void message(String msg){
System.out.println("#############Sender Agent: received message \n" + msg);
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -