The registration of the remote object must be done by the server in order for the client to look it up, is called the RMI Registry. In RMI, the client must contact an RMI registry, so that the server side application will be able to contact the client’s registry which points the client in the direction of the service. The client registers the service with the registry so that it is transparent to even for the server.
The class rebind () method of java.rmi.Naming class is used to specify the port number . For example if the registry is running on a port number 3271 of an application named HelloRMIRegistry the following is the usage of the URL to reference the remote object:
Naming.rebind ("//myhost:3271/ HelloRMIRegistry ", obj);
The URL stored on the web page needs to specify the non-default port number.
When the server’s remote objects created by the server can include the URL from which the stub class can dynamically be downloaded to the client. The following example depicts this:
java -Djava.rmi.server.codebase=http://myhost/~username/codebase/ examples.ExampleRMIURL
where ExampleRMIURL is the name of the application.
If an object implements the java.rmi.Remote interface, an object is to be bound to registry context. Each registry context implements the Referenceable interface.
The object factory is implemented by the RegistryContextFactory which converts the registry references into the corresponding registry contexts or remote objects. To construct the registry constructs, the URL of the registry must be determined. In this way the remote objects will be bounded with registry contexts.
The methods of remote objects are to be invoked by implementing the java.rmi.Remote interface.
bind(): binds the specified name to the remote object. The name parameter of this method should be in an URL format.
unbind(): Destroys the binding for a specific name of a remote method in the registry
rebind(): Binds again the specified name to the remote object. The current binding will be replaced by rebinding.
list(): Returns the names of the names that were bound to the registry in an array form. These names are in the form of URL-formatted string.
lookup(): A stub, a reference will be returned for the remote object which is related with a specified name.