/* File Name: CrossXServer */ package explorer.server; import java.rmi.*; import java.rmi.registry.*; import java.io.*; import java.util.*; /** * CrossXServer maintains the RMI Registry that binds the remote object in * a particular port and waits for clients to look up the remote object * */ public class CrossXServer { static int serverport; static String userDbFile; private static ResourceBundle resources; /** * Initialises the Server resources such as port ,DBfile */ static { try { resources = ResourceBundle.getBundle("resources.server", Locale.getDefault()); serverport=Integer.parseInt(resources.getString("explorer.server.port")); userDbFile=resources.getString("explorer.server.userdb"); userDbFile=System.getProperty("user.dir") + "/" + userDbFile; User.createNewDatabase(); } catch (MissingResourceException mre) { System.err.println("resources/server.properties not found"); System.exit(1); } } public CrossXServer() { } /** * Used to start the server * Binds the remote object for the clients to look up */ public void startServer() { System.out.println("=== Server starting at port " + serverport + "==="); try { ClientRegisterImpl regiterImpl=new ClientRegisterImpl(); try { LocateRegistry.createRegistry(serverport); System.out.println("Binding..."); Naming.rebind("//:" + serverport + "/ClientRegister", regiterImpl); } catch (UnknownHostException e) { System.out.println("Binding failed! (UnknownHostException)"); throw e; } catch (RemoteException e){ System.out.println("Binding failed! (RemoteException)"); throw e; } catch (java.net.MalformedURLException e) { System.out.println("Binding failed! (MalformedURLException)"); throw e; } System.out.println("=== Server ready ==="); } catch (Throwable e) { System.out.println("Server startup failed!"); e.printStackTrace(); System.exit(0); } } public static void main(String[] args) { CrossXServer XServer=new CrossXServer(); XServer.startServer(); } }