I was going through the RMI documents and was wondering if it is possible to automate RMI? For example i have 4 classes 1 interface, 1 implementation class, 1 server class and 1 client class. Now in order to access an object remotely one has to
compile all classes
javac class.java
run client
java client
which will display the output.But can I create, export and bind the server object to rmi registry automatically when its class object is created? So that the server is ready as long as the object is alive and tha client can start accessing the methods?
I have only 1 class that is a server and it is not accessed by any other classes except for the client, so there are no security issues also involved in this.
My prime moto is to execute all the 4 steps listed above in the code itself and make the server class methods accesible to client.No manual execution of javac
, start rmiregistry
, start server and java client.
Also is it possible for the client to access the server without any commands like start rmiregistry
and start server
being run from the server side if the server uses LocateRegistry.getRegistry() instead of LocateRegisgtry.creareRegistry(1099) ??
If you're content with having the lifespan of the registry be the same as the lifespan of the server process, the LocateRegistry
class has createRegistry(...)
methods which allow you to build an in-process registry easily. All the rmiregistry
program does is put a tiny little wrapper around a call to LocateRegistry.createRegistry(1099);
.