Java Reference
In-Depth Information
public void boost(double factor)
{
apogee *= factor;
}
public double getApogee()
{
return apogee;
}
public double getPrice()
{
return price;
}
}
An instance of
RocketImpl
can be active on one machine and can be accessed by a Java
program running on another machine. For this to work, a client needs a proxy for
the
RocketImpl
object. This proxy needs to implement the
Rocket
interface and must
have the additional features required to communicate with a remote object.
A great benefit of RMI is that it
automates
the construction of this proxy. To generate
the proxy, place the
RocketImpl.java
file and the
Rocket.java
interface file below
the directory in which you will run the RMI registry:
c:\rmi> dir com\oozinoz\remote
Rocket.java
RocketImpl.java
To create the
RocketImpl
stub that facilitates remote communication, run the RMI compiler
that comes with the JDK:
c:\rmi> rmic -v1.2 com.oozinoz.remote.RocketImpl
Note that the
rmic
executable takes a class name, not the file name, as an argument. Earlier
versions of the JDK constructed separate files for use on the client and the server machines.
As of version 1.2, the RMI compiler creates a single stub file that both the client and the
server machines need. The
rmic
command forces the compilation of the classes it needs and
creates a
RocketImpl_Stub
class:
c:\rmi> dir com\oozinoz\remote
RocketImpl.java
Rocket.java
RocketImpl.class
Rocket.class
RocketImpl_Stub.class
To make an object active, you must register it with an RMI registry running on the server. The
rmiregistry
executable comes as part of the JDK. When you run the registry, specify the
port that the registry will listen to: