I am using RMI as follows (I am using jdk1.5.0_07)
//Create the registry Registry registry = LocateRegistry.createRegistry(1099);
//Obtains the stub for the registry on the local machine registry = LocateRegistry.getRegistry();
//Exports the remote object Data db = new Data("server"); RmiInterface dataStub = (RmiInterface) UnicastRemoteObject.exportObject (db, 0);
//Bind the remote object's stub in the registry registry.bind("Server", dataStub);
The client has to connect first to the server before being able to query the database, the connection to the server is done like that:
//Obtains a stub for the registry on the server's host Registry registry = LocateRegistry.getRegistry(serverName, 1099);
//Looks up the remote object's stub by name in the registry dataRmi = (RmiInterface) registry.lookup("Server");
-On the other hand, it was mentioned in the Assignment that:
-You must not require the use of an HTTP server. -You must not require the installation of a security manager. -You must provide all classes pre-installed so that no dynamic class downloading occurs. -You must use RMI over JRMP (do not use IIOP)
-does the way I used RMI fit with all the Assignment specs?
I believe it is unnecessary only if your remote implementation class is extended from UnicastRemoteObject. It this case, the exporting is done by UnicastRemoteObject's constructor. If your class does not extended from UnicastRemoteObject, you then need to manually export it.