Java Reference
In-Depth Information
c:\rmi> rmiregistry 5000
With the registry running on the server machine, you can create and register a RocketImpl
object:
package com.oozinoz.remote;
import java.rmi.*;
public class RegisterRocket
{
public static void main(String[] args)
{
try
{
// challenge!
Naming.rebind(
"rmi://localhost:5000/Biggie", biggie);
System.out.println("Registered biggie");
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
If you copy this code to the same directory that the other files reside in, you can compile and
run it. The program displays a confirmation that the rocket is registered:
c:\rmi> javac com\oozinoz\remote\RegisterRocket.java
c:\rmi> java com.oozinoz.remote.RegisterRocket
Registered biggie
You need to replace the //challenge! line in the RegisterRocket class with code that
creates a biggie object that models a rocket. The remaining code in the main() method
registers this object. A description of the mechanics of the Naming class is outside the scope
of this discussion.
However, you should have enough information to create the biggie object that this code
registers.
CHALLENGE 11.3
Replace the //challenge! line with a declaration and instantiation of
the biggie object. Define biggie to model a rocket with a price of $29.95 and
an apogee of 820 meters.
Running the RegisterRocket program makes a RocketImpl object, specifically
biggie , available on a server. A client that runs on another machine can access biggie if
the client has access to the Rocket interface and the RocketImpl_Stub class. If you are
Search WWH ::




Custom Search