handeling java RMI 连接拒绝主机异常
handeling java RMI connection refused to host exception
如果服务器未启动,我想向用户显示一条错误消息。
当用户启动程序时。
下面我提到了我的 ServerConnector 单例 class,我用它连接到整个应用程序的服务器。
public class ServerConnector {
private static ServerConnector serverConnector;
private RemoteFactory remoteFactory;
private ServerConnector() throws NotBoundException, MalformedURLException,
RemoteException {
remoteFactory = (RemoteFactory) Naming
.lookup("rmi://localhost:5050/RoomReservation");
}
public static ServerConnector getServerConnector()
throws NotBoundException, MalformedURLException, RemoteException {
if (serverConnector == null) {
serverConnector = new ServerConnector();
}
return serverConnector;
}
public CustomerController getCustomerController() throws RemoteException {
return remoteFactory.getCustomerController();
}
}
有什么方法可以在加载程序的 GUI 之前检查服务器是否已启动?
谢谢。
赶上java.rmi.ConnectException
。这意味着 Registry 尚未启动。
赶上NotBoundException
。这意味着服务器尚未绑定到注册表。
如果服务器未启动,我想向用户显示一条错误消息。 当用户启动程序时。 下面我提到了我的 ServerConnector 单例 class,我用它连接到整个应用程序的服务器。
public class ServerConnector {
private static ServerConnector serverConnector;
private RemoteFactory remoteFactory;
private ServerConnector() throws NotBoundException, MalformedURLException,
RemoteException {
remoteFactory = (RemoteFactory) Naming
.lookup("rmi://localhost:5050/RoomReservation");
}
public static ServerConnector getServerConnector()
throws NotBoundException, MalformedURLException, RemoteException {
if (serverConnector == null) {
serverConnector = new ServerConnector();
}
return serverConnector;
}
public CustomerController getCustomerController() throws RemoteException {
return remoteFactory.getCustomerController();
}
}
有什么方法可以在加载程序的 GUI 之前检查服务器是否已启动?
谢谢。
赶上
java.rmi.ConnectException
。这意味着 Registry 尚未启动。赶上
NotBoundException
。这意味着服务器尚未绑定到注册表。