Information Technology Reference
In-Depth Information
• Other classes used directly in an RMI application, such as parameters and
return values.
The actual location of classes that may be needed to be loaded at runtime
are defined by the system property java.rmi.server.codebase , a URL pointing
to the location of the class files. Classes loaded by RMI are subject to security
restrictions put in place by the java.lang.SecurityManager class installed for
the virtual machine downloading the class. For classes downloaded into applets or
applications as a result of remote calls, RMI requires a security manager to protect
the application and host from potential harm [122].
Java automatically deletes objects that are no longer referenced. RMI extends
this to remote objects by using a reference counting mechanism similar to that used
by Modula-3 network objects [14]. RMI implements remote garbage collection by
keeping track of all live remote references in all virtual machines. When a remote
object is first referenced, a count is incremented and a referenced message is sent to
the remote object's RMI runtime. When a live reference is unreferenced, the count
is decremented. When the count reaches 0 an unreferenced message is sent to the
remote object's RMI runtime, which is then free to garbage-collect the object.
Clients hold references to remote objects for a certain period of time, called a
lease. It is the responsibility of the client to automatically renew the lease before it
expires. If the lease expires, the server assumes the client is no longer referencing
the remote object and is free to garbage-collect it [122]. Using this mechanism it is
still possible, however, for a client to call a remote object that has been garbage-
collected. For example, if the network is down for a short period of time and the
client's RMI runtime could not renew the lease, the client could, upon the network
connection being restored, call a remote object that has been garbage-collected.
In this instance a java.rmi.RemoteException exception is thrown.
RMI uses a simple naming service to bootstrap RMI applications. Servers
register remote objects they are exporting with a name server called a registry.
When a client wishes to obtain a reference to a remote object, a lookup is performed
on a registry and a reference to the remote object is returned if the lookup succeeds.
Registry services can be used by either using the traditional RPC mechanism
of a centralised registry or by each application maintaining its own registry.
Because RMI services generally return remote objects, the registry only needs
to be contacted when making initial contact with a remote application because
once one of the remote objects on a server has been obtained, additional objects
can be obtained via method calls on the first object [28].
2.5.1
RMI Example
In order to implement our simple date application, we are firstly required to define
the remote interface, illustrated in Figure 2.12, which is required to extend from
the java.rmi.Remote interface and each remote method is required to declare
that it throws the java.rmi.RemoteException exception.
Search WWH ::




Custom Search