CLICK HERE TO DOWNLOAD PPT ON Remote Method Invocation
Remote Method Invocation Presentation Transcript
1.Remote Method Invocation
2.Java RMI
3.In the Good Old Days
4.Today’s World
5.Why not just use sockets?
Sockets programming is tedious
Error prone for implementing complex protocols
Best left to “the experts”
Sockets programming is tedious
Error prone for implementing complex protocols
Best left to “the experts”
6.Java RMI Allows
Provide user with a “thin client “
allows good performance on low end workstations
Run server on high end hardware
maximize $ investment over many clients
server remote from client
Distributed network object
Provide user with a “thin client “
allows good performance on low end workstations
Run server on high end hardware
maximize $ investment over many clients
server remote from client
Distributed network object
7.What RMI Is And Isn’t
Java only solution to the problem of distributed object computing
Unlike CORBA it is not language independent
Isn’t meant to replace CORBA
Good for java only solutions, not easy to integrate with legacy code
Java only solution to the problem of distributed object computing
Unlike CORBA it is not language independent
Isn’t meant to replace CORBA
Good for java only solutions, not easy to integrate with legacy code
8.What RMI Is And Isn’t (Cont.)
Underlying wire protocol (object serialization) is not an open standard; the good news is that since JDK 1.2 it will optionally use the IIOP Protocol (RMI Over IIOP)
Since it is a Java only solution objects are at the mercy of the java interpreter and JITs for run time performance
Underlying wire protocol (object serialization) is not an open standard; the good news is that since JDK 1.2 it will optionally use the IIOP Protocol (RMI Over IIOP)
Since it is a Java only solution objects are at the mercy of the java interpreter and JITs for run time performance
9.REAL Architecture
10.Architecture Showing Implementation
11.The General Idea
12.The Parts
Client - user interface
Server - data source
Stubs
marshals argument data (serialization)
unmarshals results data (deserialization)
Skeletons (not required w/Java 2)
unmarshals argument data
marshals results data
Client - user interface
Server - data source
Stubs
marshals argument data (serialization)
unmarshals results data (deserialization)
Skeletons (not required w/Java 2)
unmarshals argument data
marshals results data
13.The Parts(cont.)
Remote Reference Layer
provides a RemoteRef object that represents the link to the remote service implementation object.
encodes and decodes the on-wire protocol
implements the remote object protocols
Transport layer
The Transport Layer makes the connection between JVMs. All connections are stream-based network connections that use TCP/IP.
Handles the underlying socket handling required for communications
sets up and maintains connections
communications related error handling
Remote Reference Layer
provides a RemoteRef object that represents the link to the remote service implementation object.
encodes and decodes the on-wire protocol
implements the remote object protocols
Transport layer
The Transport Layer makes the connection between JVMs. All connections are stream-based network connections that use TCP/IP.
Handles the underlying socket handling required for communications
sets up and maintains connections
communications related error handling
14.The Steps
Create the Interface to the server
Create the Server
Create the Client
Compile the Interface (javac)
Compile the Server (javac)
Compile the Client (javac)
Generate Stubs and Skeletons (rmic)
Create the Interface to the server
Create the Server
Create the Client
Compile the Interface (javac)
Compile the Server (javac)
Compile the Client (javac)
Generate Stubs and Skeletons (rmic)
15.To run
Start the RMI registry
rmiregistry is on the server directory
Start the RMI Server
Start the RMI Client
Run The Program
Start the RMI registry
rmiregistry is on the server directory
Start the RMI Server
Start the RMI Client
Run The Program
16.RMI Registry
The RMI Registry is a naming service provided with the JDK as a teaching tool or for a small number of Remote Objects
Uses port 1099 as its default port
Can be considered to be a reference implementation
runs out of steam above a 100 objects
runs on same machine as the remote object
The RMI Registry is a naming service provided with the JDK as a teaching tool or for a small number of Remote Objects
Uses port 1099 as its default port
Can be considered to be a reference implementation
runs out of steam above a 100 objects
runs on same machine as the remote object
17.RMI Registry (More)
Use another naming service
J2EE uses JNDI and Directory Services to provide a more robust naming service
Silverstream uses JNDI with its own ServiceProvider and repository for RMI
Use another naming service
J2EE uses JNDI and Directory Services to provide a more robust naming service
Silverstream uses JNDI with its own ServiceProvider and repository for RMI
18.A SMALL DEMO SHOWING HOW METHODS ARE INVOKED
19.To create an RMI application, the first step is the defining of a remote interface between the client and server objects.
/* MyIntf.java */
import java.rmi.*; //package for rmi
public interface MyIntf extends Remote
{
public int sum(double a,double b) throws RemoteException;
}
20.Step 2: Develop the remote object and its interface
The server is a simple unicast remote server.
Create server by extending java.rmi.server.UnicastRemoteObject.
The server uses the RMISecurityManager to protect its resources while engaging in remote communication.
/* MySrvr.java */
import java.rmi.*;
import java.rmi.server.*;
public class MySrvr extends UnicastRemoteObject implementsMyIntf
{
MySrvr() throws RemoteException //default constructor
{}
21.Step 2: Develop the remote object and its interface
Implement the remote methods
/* MySrvr.java */
public int sum(double a,double b) throws RemoteException
{
return a + b;
}
}
The server must bind its name to the registry, the client will look up the server name.
Use java.rmi.Naming class to bind the server name to registry. In this example the name call “MySrvr”.
In the main method of your server object, the RMI security manager is created and installed.
/* MyIntf.java */
import java.rmi.*; //package for rmi
public interface MyIntf extends Remote
{
public int sum(double a,double b) throws RemoteException;
}
20.Step 2: Develop the remote object and its interface
The server is a simple unicast remote server.
Create server by extending java.rmi.server.UnicastRemoteObject.
The server uses the RMISecurityManager to protect its resources while engaging in remote communication.
/* MySrvr.java */
import java.rmi.*;
import java.rmi.server.*;
public class MySrvr extends UnicastRemoteObject implementsMyIntf
{
MySrvr() throws RemoteException //default constructor
{}
21.Step 2: Develop the remote object and its interface
Implement the remote methods
/* MySrvr.java */
public int sum(double a,double b) throws RemoteException
{
return a + b;
}
}
The server must bind its name to the registry, the client will look up the server name.
Use java.rmi.Naming class to bind the server name to registry. In this example the name call “MySrvr”.
In the main method of your server object, the RMI security manager is created and installed.
22.Step 2: Develop the remote object and its interface
/* MySrvr.java */
public static void main(String args[]) throws RemoteException
{
//create a local instance of the object
MySrvr obj = new MySrvr();
//put the local instance in the registry
Naming.rebind(“MyObject" ,obj);
System.out.println("Server is ready and running");
//Server Is Ready and Running
}
23.Step 3: Develop the client program
In order for the client object to invoke methods on the server, it must first look up the name of server in the registry. You use the java.rmi.Naming class to lookup the server name.
The server name is specified as URL in the from (rmi://host:port/name )
The name specified in the URL must exactly match the name that the server has bound to the registry. In this example, the name is “MyObject”
The remote method invocation is programmed using the remote interface name (m) as prefix and the remote method name (sum) as suffix.
/* MySrvr.java */
public static void main(String args[]) throws RemoteException
{
//create a local instance of the object
MySrvr obj = new MySrvr();
//put the local instance in the registry
Naming.rebind(“MyObject" ,obj);
System.out.println("Server is ready and running");
//Server Is Ready and Running
}
23.Step 3: Develop the client program
In order for the client object to invoke methods on the server, it must first look up the name of server in the registry. You use the java.rmi.Naming class to lookup the server name.
The server name is specified as URL in the from (rmi://host:port/name )
The name specified in the URL must exactly match the name that the server has bound to the registry. In this example, the name is “MyObject”
The remote method invocation is programmed using the remote interface name (m) as prefix and the remote method name (sum) as suffix.
24.Step 3: Develop the client program
import java.rmi.*;
import java.rmi.server.*;
public class MyClient
{
public static void main(String[] args) throws RemoteException
{
//get the remote object from the registry
String url = “rmi//192.168.0.2/MyObject"; //passing ip adress //of server registry
MyIntf m = (MyIntf)Naming.lookup(url); //looks up in registry
System.out.println("Got remote object");
System.out.println(" Sum Is " + m.sum(7,5));//prints //the output on cmd
}
}
25.Step 4 & 5: Compile the Java source files & Generate the client stubs and server skeletons
Assume the program compile and executing at command prompt in ~/rmi folder where there is one folder rmi server which contains both (MySrvr.java) and MyIntf.java files then u must compile these files
Once the interface is completed, you need to generate stubs and skeleton code. The RMI system provides an RMI compiler (rmic) that takes your generated interface class and procedures stub code on its self.
26.Step 6: Start the RMI registry
The RMI applications need install to Registry. And the Registry must start manual by call rmiregisty.
The rmiregistry us uses port 1099 by default. You can also bind rmiregistry to a different port by indicating the new port number as : rmiregistry <new port>
Remark: On Windows, you have to type in from the command line:
> start rmiregistry
import java.rmi.*;
import java.rmi.server.*;
public class MyClient
{
public static void main(String[] args) throws RemoteException
{
//get the remote object from the registry
String url = “rmi//192.168.0.2/MyObject"; //passing ip adress //of server registry
MyIntf m = (MyIntf)Naming.lookup(url); //looks up in registry
System.out.println("Got remote object");
System.out.println(" Sum Is " + m.sum(7,5));//prints //the output on cmd
}
}
25.Step 4 & 5: Compile the Java source files & Generate the client stubs and server skeletons
Assume the program compile and executing at command prompt in ~/rmi folder where there is one folder rmi server which contains both (MySrvr.java) and MyIntf.java files then u must compile these files
Once the interface is completed, you need to generate stubs and skeleton code. The RMI system provides an RMI compiler (rmic) that takes your generated interface class and procedures stub code on its self.
26.Step 6: Start the RMI registry
The RMI applications need install to Registry. And the Registry must start manual by call rmiregisty.
The rmiregistry us uses port 1099 by default. You can also bind rmiregistry to a different port by indicating the new port number as : rmiregistry <new port>
Remark: On Windows, you have to type in from the command line:
> start rmiregistry
27.RUN THE SERVER
Step 7: Transferring Files To The Client
Copy the files on the client side through networking into the client diectory that is rmiClient as shown in next slide
The client contains MyClient.java File which lookups in remote registry and executes or call the method on remote object
Step 7: Transferring Files To The Client
Copy the files on the client side through networking into the client diectory that is rmiClient as shown in next slide
The client contains MyClient.java File which lookups in remote registry and executes or call the method on remote object
28.Steps 7 & 8: Start the remote server objects & Run the client
Once the Registry is started, the server can be started and will be able to store itself in the Registry.
Now run the Client on Client Machine to view the output
Once the Registry is started, the server can be started and will be able to store itself in the Registry.
Now run the Client on Client Machine to view the output
0 comments