Dynamic Class Loading
RMI
system uses object serialization to transmit data from one machine to
another machine. When an object is passed from one program to another
program, either as a parameter or return value of a remote method, then
the receiving program must resolve that object. When parameters and
return values are unmarshalled on the receiving end, they become live
objects. The classes for parameters and return values are required for
all types of objects. If you pass standard Java objects (e.g., String,
Vector etc.), the classes will be loaded locally because these
classes are available in every JVM. If you declare a remote method with
a certain return type that is not known to the client (like custom classes
and interfaces), then these classes must also be resolved at the time
of unmarshaling. One way to make these classes available is to copy
these files from one machine to another. However, if the server adds
new classes for return types, then the client must be updated. In a
small local area network (LAN), it is possible to update client application,
every time the server is updated, but if it were a Wide Area Network
(WAN), then it would be a problem to keep updating the client every
time the server is updated. For that reason, RMI provides the facility
of dynamic class loading. The RMI system uses an existing web server
to dynamically load classes (see Figure 6.1). Whenever a program
loads classes from another network location, there is a security issue.
For dynamic loading of classes, a security manager must be installed
in the client code. You may install a security manager in the
server code, if the server is itself a client.
Figure 6.1

This chapter shows two examples of dynamic class loading.
The source code needed for the first example is stored in the
examples\dynamic directory. The "dynamic"
directory contains the following files:
- TDInterface.java
- TDServerImpl.java
- TDApplet.java
- TDClient.html
- Compile.bat
- Rmicompile.bat
- RunServer.bat
- RunApplet.bat
To run this example you need the following applications:
Netscape
Navigator or appletviewer
Java
Web Server
|