1. RMI Architecture
Prof. Ashish Bhatia,ast.bhatia@gmail.com,ashish@asbspace.in,
Web: asbspace.in, M:9879009551
September 10, 2012
2. OutLine
Basic of RMI
RMI Architecture
RMI Architecture
3 Common Terms
Stub
Skeleton
Remote Reference Layer
RMI Registry
Creating RMI Base Application
Creating the interface
Creating the interface
Implementing the interface
Creating the Server Program
Creating the Client Program
Running the Program
3. Basic of RMI
Stands for Remote Method Procedure Call.
4. Basic of RMI
Stands for Remote Method Procedure Call.
Enables to communicate two different objects in different Java
Virtual Machine.
5. Basic of RMI
Stands for Remote Method Procedure Call.
Enables to communicate two different objects in different Java
Virtual Machine.
Distributed Application Development and Remote Calling
6. Basic of RMI
Stands for Remote Method Procedure Call.
Enables to communicate two different objects in different Java
Virtual Machine.
Distributed Application Development and Remote Calling
CORBA - Common Object Request Broker Architectire,
DCOM - Distributed Component Object Model.
8. RMI Architecture
Mechanism by which client can programmer make a regular
method call , without worrying about sending data across the
network or parsing the response.
The solution is to install the proxy object on the client.
Proxy is an object located at client VM that appears to be
client program.
Client call proxy, making a regular method call.
Client proxy contacts server using a network protocol [TCP]
Same happen at server side.
Proxy on server so that server don’t realize the network call.
9. RMI Architecture
Proxies at both the end communicated with each other and it
shows / pretends that calls were regular calls not the remote
call.
How do Remote Call Works ?
Java RMI
CORBA [ IIOP ]
Web Service [ SOAP ]
11. 3 Common Terms
Marshalling :is a process in which parameters passed by
client are converted to a format that can be transferred across
a network.
12. 3 Common Terms
Marshalling :is a process in which parameters passed by
client are converted to a format that can be transferred across
a network.
UnMarshalling : is a process in which marshaled parameters
passed by the client-side RRL through the server-side RRL are
converted to a format that the skeleton understands.
13. 3 Common Terms
Marshalling :is a process in which parameters passed by
client are converted to a format that can be transferred across
a network.
UnMarshalling : is a process in which marshaled parameters
passed by the client-side RRL through the server-side RRL are
converted to a format that the skeleton understands.
Serilization : is a general purpose mechanism for taking an
object and encoding it as a stream of bytes. The underlying
design rationale is fairly simple.
14. Stub : Client Side Proxy
Client invoke a method on a remote object -¿ Call to Proxy
Object called STUB
STUB knows how to contact to the server.
It packages the parameters used in remote methods in to a
block of bytes
Process of Encoding is called Marshalling
An identifier of the remote object to be used
A description of the method to be called. The parameters.
Objects are encoded using Serilaization
15. Skeleton : Server Side Proxy
It locates remote object to be called
It calls the desired method, passing the supplied parameters.
It captures the return value or exception of the call.
It sends a package consisting of the marshaled return data
back to the stub on the client.
16. Remote Reference Layer
Encapsulates the invocation semantic of the RMI connection.
Provides java.rmi.server.RemoteRef object which handle
remote service implmentation object.
invoke() method is used by stub instance to forward method
call.
RRL extracts information about the remote server / remote
client.
17. RMI Registry
It is a naming services used by RMI server program to bind
the Java Object with names.
Client retrieves object using the name from the RMI registry.
By default it runs on the port 1099 to accept the queries.
On a host machine, a server program creates a remote service
by first creating a local object that implements that service.
RMI creates a listening service that waits for clients to
connect and request the service.
On the client side, the RMI Registry is accessed through the
static class Naming. It provides the method lookup() that a
client uses to query a registry.
18. Creating RMI Base Application
1. Create the interface.
2. Define a class that implements an interface.
3. Create the server process.
4. Create the client process.
19. Creating the interface
import java.rmi.*;
public interface Hello extends Remote
{
public String sayDemo() throws RemoteException;
}
20. Creating the interface
import java.rmi.*;
public interface Hello extends Remote
{
public String sayDemo() throws RemoteException;
}
21. Implementing the interface
import java.rmi.*;
import java.rmi.server.*;
public class HelloImpl extends UnicastRemoteObject
implements Hello
{
public String sayDemo() throws RemoteException
{
return("Hello World");
}
}
22. Creating the Server Program
import java.rmi.*;
import java.rmi.server.*;
public class HelloServer
{
public static void main(String args)
{
HelloImpl temp = new HelloImpl();
String rmiobjectname = "rmi://localhost/Hello";
Context namingContext=new InitialContext();
namingContext.bind(rmiobjectname,temp);
System.out.println("Binding Complete ...");
}
}
23. Creating the Client Program
import java.rmi.*;
import java.rmi.server.*;
public class HelloClient
{
public static void main(String args)
{
try
{
Context namingContext = new InitialContext();
Hello greeting =
(Hello)namingContext.lookup("rmi://localhost/Hello");
System.out.println("Recvd Message ..." +
greeting.getGreeting());
}
catch(ConnectException e)
{
System.out.println("Error");
24. Running the Program
Compile all java files.
Run rmic HelloImpl to generate Stub Files
Create two folders Server anc Client
Copy all class files except HelloClient.class and stub.class file
in server folder
Copy HelloClient.class, Hello.class and stub.class in client
folder.
Run rmiregistry through commandprompt.
Run HelloServer followed by HelloClient.