我在作为集群一部分的机器上运行我的 rmi 服务器。IP 可能会更改,因此通过此过程进行连接是不可靠的。
直到现在,在工作中的开发盒上,基于 IP 的连接都很好,但是转移到 UAT 我需要更改它,但我不知道该怎么做。
下面我有服务器和客户端类的代码。在这里你可以看到我使用机器 ip 连接。我如何用机器别名替换它?这是可能的还是我感到困惑?
谢谢
private final String address = "111.111.111.111";
private Registry registry;
private int port = 6789;
private static Logger logger = Logger.getLogger(RmiServer.class);
public RmiServer() throws RemoteException {
try {
registry = LocateRegistry.createRegistry(port);
registry.rebind("rmiServer", this);
logger.info("Server is Ready! Connected on: " + address + ":" + port + " ." +
} catch (RemoteException e) {
logger.error("Unable to start the server. Exiting the application.", e);
System.exit(-1);
}
}
private final String serverAddress = "111.111.111.111";
private String serverPort = "6789";
private ReceiveMessageInterface rmiServer;
private Registry registry;
private Logger logger = Logger.getLogger(RMIClient.class);
public RMIClient(){
try {
registry = LocateRegistry.getRegistry(serverAddress, (new Integer(serverPort)).intValue());
rmiServer = (ReceiveMessageInterface) (registry.lookup("rmiServer"));
logger.info("Client started correctly");
} catch (RemoteException e) {
logger.error("Remote object exception occured when connecting to server. Exiting application", e);
System.exit(-1);
} catch (NotBoundException e) {
logger.error("Not Bound Exception occured when connecting to server. Exiting application", e);
System.exit(-1);
}
}