⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 externalaccessagent.java

📁 利用新的分布式对象技术-移动agent实现的掌上电脑证券监管系统
💻 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 + -