agentservice.java

来自「javaP2P技术内幕课程111213141516源代码」· Java 代码 · 共 47 行

JAVA
47
字号

import java.rmi.Naming;
import java.rmi.RemoteException;
import java.rmi.RMISecurityManager;
import java.rmi.server.UnicastRemoteObject;

public class AgentService extends UnicastRemoteObject
                           implements Agent
{
    public AgentService() throws RemoteException {
        super();
    }


    public static void main(String[] args) {
        if(args.length < 1) {
            System.out.println("usage [hostname]");
            System.exit(1);
        }

        String hostname = args[0];

        if (System.getSecurityManager() == null) {
            System.setSecurityManager(new RMISecurityManager());
        }

        String name = "//" + hostname + "/Agent";

        try {
            Agent agent = new AgentService();
            Naming.rebind(name, agent);
            System.out.println("AgentService bound");
        } catch (Exception e) {
            System.err.println("AgentService exception: " + 
          e.getMessage());
            e.printStackTrace();
        }
    }

    // implementation of the Agent interface
    public String talk() {
        return "P2P is very cool";
    }

}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?