The
UnicastRemoteObject Class
This class is the base class for most of the user defined remote objects.
It defines a non-replicated remote object whose references are valid
only while the server process is alive. It provides support for point-to-point
active object references using TCP streams. This class can be used to
create and export remote objects. The remote object can be exported
implicitly by extending the UnicastRemoteObject
, or it can be done explicitly with a call to the exportObject()
method of the same class. If UnicastRemoteObject
is not extended, the implementation class must provide correct implementation
of the hashCode(), equals(),
and toString(), so that
they behave appropriately for remote objects.
Methods
- public static RemoteStub
exportObject(Remote obj) - Exports the specified remote
object to make it available to receive incoming calls, using an anonymous
port.
- public static Remote exportObject(Remote
obj, int port) - Exports the specified remote object to make
it available to receive incoming calls, using the particular supplied
port.
- public static Remote exportObject(Remote
obj, int port, RMIClientSocketFactory csf, RMIServerSocketFactory
ssf) - Export the remote object to make it available to receive
incoming calls, using a transport specified by the given socket factory.
- public static boolean unexportObject(java.rmi.Remote
obj, boolean force) - This method makes the remote object unavailable
for incoming calls. If the force parameter is true, the object is
forcibly unexported even if there are pending calls to the remote
object.
The
Naming Class
The java.rmi.Naming class
provides several methods that can be used to interact with the remote
object registry. The methods can be used to register and query for
remote objects. An object is requested by its name, so all names in
a particular registry must be unique.
Methods
- public static void bind(String
url, Remote obj) - Binding means associating a name
for a remote object that can be used to look up that remote object.
This method binds the specified "name" to a remote
object. It throws an AlreadyBoundException
if the name is already bound to an object.
- public static String[] list(String
url) - Returns an array of the Strings bound in the registry.
Each String object contains a name that is bound to a remote object.
The names are URL-formatted strings.
- public static Remote lookup(String
url) - Returns a stub for the remote object associated with
the specified name. This method takes a string containing the URL
to a remote object reference on the server.
- public static void rebind(String
url, Remote obj) - Rebinds the specified name to a new remote
object. Any old binding for the name is replaced.
- public static void unbind(String
url) - Removes an object reference from the registry. It throws
a NotBoundException if there was no binding.
To develop and run a distributed application using RMI we have to
follow steps given below:
- Define the interfaces
- Implementing these interfaces
- Compile the application with the java compiler
- Compile the server implementation with the rmic compiler.
- Run the RMI registry
- Run the server
- Run the client
|