RMI stands for Remote Method Invocation to create distributed application in java. In this object access to invoke method (goes to the machine to execute method and returns the result to the other machines). In RMI client invokes the method and stub is a proxy for the remote object then we have RRL then transport layer. In the server side we have skeleton then we have RRL then transport layer.
There is the connection between the client and server with the help of transport layer of client side and server side. The client makes a call to the server. Call comes to the stub passes the request to RRL. RRL stands for Remote Reference Layer.
RRL here identifies the type of server i.e. whether unicast or multicast. RMI unicast the server here you cannot replicate the objects. Stub once get a method call invoke method on remote reference to pass to server side.
RRL to skeleton invoke the method gets executed result to skeleton then it goes to RRL then to the transport layer to client side result to stub then stub produces result to the client.when client passes the object to the stub they must be in parameter and are of primitive type & object type. Object type basically serliazed the object. Primitive type is stub marshelling it means putting together parameters.
Steps to create the remote interface
1.First step is to define a remote interface
import java.rmi.*;
public interface AddServerInterface extends Remote
{
public int sum(int a,int b);
}
2. Second step is the implementation of remote interface
import java.rmi.*;
import java.rmi.registry.*;
public class AddServer{
public static void main(String args[]){
try{
AddServerInterface addService=new Adder();
Naming.rebind("AddService",addService);
//addService object is hosted with name AddService.
}catch(Exception e){System.out.println(e);}
}
}
3. Third step is to create client application
import java.rmi.*;
public class Client{
public static void main(String args[]){
try{
AddServerInterface st=(AddServerInterface)Naming.lookup("rmi://"+args[0]+"/AddService");
System.out.println(st.sum(25,8));
}catch(Exception e){System.out.println(e);}
}
}
Then all you have to do run this RMI application.To run the RMI application first thing you have to do is to save the file in the directory we have to name it as rmi then you have to compile all the java files then start RMI registry then run the server file then at last run the client file in the another command prompt.
0 Comment(s)