2. DEFINITION
RMI stands for Remote Method Invocation. It is a
mechanism that allows an object residing in one
system (JVM) to access/invoke an object running on
another JVM.
RMI is used to build distributed applications; it
provides remote communication between Java
programs. It is provided in the package java.rmi
4. STUB:
The stub object on the client
machine builds an information block and
send.
Information to the server.
The block consists an identifier of the re
mote object to be used.
Method name which is to be invoked
Parameters to the remote JVM.
5. UNDERSTANDING STUB &SKELETON
RMI uses stub and skeleton object for communication
with the remote object.
A remote object is an object whose method can be
invoked from another JVM. Let's understand the stub
and skeleton objects
8. CLIENT &SERVER
In CIient server computing, the clients requests a
resource and the server provides that resource.
A server may serve multiple client is in contact with
only one server.
Both client and server usually communicate via a
computer network. but sometimes they may reside in
the same system.
9. STUB AND SKELETON IN RMI
The STUB is the class that implements the remote
interface.
It server as a client-side placeholder for the remote
object.
The stub communicates with the server-side
SKELETON.
The SKLETON is the STUB’s counterpart on Server-
side.
11. TRANSPORT LAYER
Transport Layer provides transparent transfer of data
between end users, providing reliable data transfer
services to the upper layers.
The transport layer controls the reliability of a given
link through flow control, segmentation and
Desegmentation, and error control.
13. six steps to write the RMI program
in java:
Creation of remote interface .
Provide the implementation of the remote interface.
Compile the implementation class and create the stub
and skeleton objects using the rmi tool.
Start the registry service by rmi registry tool .
Write and start the remote application .
Write and start the client application.
14. Step 1: Defining the remote interface:
The first thing to do is to create an interface which will
provide the description of the methods that can be
invoked by remote clients.
This interface should extend the Remote interface and
the method prototype within the interface should
throw the Remote Exception.
// Creating a Search interface
import java.rmi.*;
public interface Search extends Remote
{
// Declaring the method prototype
public String query(String search) throws RemoteException; }
15. Step 2: Implementing the remote interface
The next step is to implement the remote interface. To
implement the remote interface, the class should
extend to UnicastRemoteObject class of java.rmi
package. Also, a default constructor needs to be
created to throw the from its parent constructor in
class.
16. Step 3: Creating Stub and Skeleton objects from the
implementation class using rmic
The rmic tool is used to invoke the rmi compiler that
creates the Stub and Skeleton objects. Its prototype is
rmic classname.
For above program the following command need to be
executed at the command prompt
rmic SearchQuery.
17. STEP 4: Start the rmiregistry
Start the registry service by issuing the following
command at the command prompt start rmiregistry
STEP 5: Create and execute the server application
program
The next step is to create the server application
program and execute it on a separate command
prompt.
18. //program for client application
import java.rmi.*;
public class ClientRequest
{
public static void main(String args[])
{
String answer,value="Reflection in Java";
try
{
// lookup method to find reference of remote object
Search access =
(Search)Naming.lookup("rmi://localhost:1900"+
"/geeksforgeeks");
answer = access.query(value);
System.out.println("Article on " + value +
" " + answer+" at GeeksforGeeks");
}
catch(Exception ae) { system.out.println(ae);}}}