Professional Documents
Culture Documents
RMI
RMI
Steps in RMI-based
RMI-based Distributed System Application
1. Design the interface for the service.
4.
2. Implement the methods specified in
5. 3. 3. 2. the interface.
XYZ XYZ
Client
Stub Stub Implementation 3. Generate the stub and the skeleton.
uses 1. 4. Register the service by name and
implements
XYZ location.
interface
5. Use the service in an application.
Client Host Server Host
1
Case Study : Temperature
Parameter Marshalling Service
Transfer of parameters (or marshalling) Lets create a distributed system using
is done by the RMI. RMI model for networking (remote
Complex objects are streamed using access).
Serialization. Basically this program will download the
RMI model of networking for distributed weather (temperature) information
system involves only Java. from the site:
No need to learn IDL or any other http://iwin.nws.noaa.gov/iwin/us/traveler.html
language.
Temperature Client/Server
Distributed Application Defining Remote Interface
import java.rmi.*;
rmic
4
// the interface extends Remote interface
compiles
// any class implementing Remote can be
5. 3. generates 3. 2. accessed remotely security permitting
TempClient TempImpl_Stub uses TempImpl_Stub
public interface TemperatureServer extends
TempServerImpl
Remote
1.
uses
implements { // specify methods that can be called
TempServer
remotely
Client Host Server Host
// each method “throws RemoteException”
}
1/24/02 B.Ramamurthy 9 1/24/02 B.Ramamurthy 10
2
TemperatureServerImpl
TemperatureServerImpl (contd.)
This class’s constructor calls a private method It implements the service method
which in turn: getWeatherInfo which simply returns
1. Connects to the url specified the weather data gathered.
2. Streams into a buffer the page referenced. The main method instantiates an object
3. Parses the buffer to get the required data. for the service, and registers it with
4. Creates an array of weather information. rmiregistry.
3
Temperature Client Temperature Client (contd.)
import java.rmi.*; The main method in this client can get
// import other packages the IP address of the remote host as a
constructor calls a private method command line argument.
getRemoteTemp which takes care of Command line argument is an array of
lookup of remote object and access. String of items in the command line
In this application it also displays the after the name of the application.
information.