Reputation: 3
I want to show a an error message to user if the server is not started. when user is starting the program. below I mention my ServerConnector singleton class which I used to connect to server allover the application.
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();
}
}
is there any way to check the server is started before loading a GUI of the program?
Thank you.
Upvotes: 0
Views: 67
Reputation: 310840
Catch java.rmi.ConnectException
. That means the Registry hasn't been started.
Catch NotBoundException
. That means the server hasn't been bound to the Registry.
Upvotes: 1