Download Slide 1 - MyTech5

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
RMI
RMI is the java API that facilitate distributed
computing by allowing remote method calls. A
remote method call represents a method invocation
between different JVM .
RMI Client
Remote Method Call
Remote
Object or
RMI server
• RMI provides basic infrastructure required for
distributed computing.
• Commonly used terms or terminology of RMI .
• 1) Remote object / RMI server :- A remote object
/RMI server is a distributed object that exposes
remote method which can be invoke on the remote
object in a distributed manner from different JVM.
• 2) RMI client: is an object that invokes a remote
method using RMI.
Domain name Server
Domain Name
IP Address
Client
Web
Server
Web
Application
• 3) Stub :- A stub represents a proxy of remote
object that hides the internal details of remote
method invocation from the RMI client .
• 4) Skeleton:- A skeleton is the proxy of RMI client
that hides the internal details of RMI from the
remote object .
• In order to invoke remote method using RMI
following sequence of operation are required.
Directory Server
Name
Remote
Object
Stub
JVM
2.5
1.2
2.4
2.0
2.1
2.6
2.2
JVM
Skeleton
2.3
2.7
Proxy for server
Proxy for client
• 1.0 Remote object is created
• 1.1 Stub & skeleton for the remote object is
created.
• 1.2 Remote stub is registered with a logical name in
directory server
• 2.0 search remote stub .
• 2.1 Remote stub is obtained
• 2.2 invokes remote method
• 2.3 establises connection with its skeleton &
marshals method call to the skeleton
• 2.4 unmarshalls method call and invokes method on
actual object
• 2.5 method completes and result is returned to
skeleton
• 2.6 skeleton marshals result of method call to the
stub .
• 2.7 stub unmarshals result and provide it to client.
•
• STEPS TO CREATE RMI BASED APPLICATION:• 1) Define a remote interface , each remote object
exposes remote interface to its clients .this interface
extends java.rmi.remote interface and provides
remote method. Each remote method in the
remote interface through java
java.rmi.RemoteException.
• 2) Define a class that implements remote interface
& provides Exporting logic
.java.rmi.server.UnicastRemoteObject class provides
exporting logic logic(Statements to create stub &
skeleton for a remote object )
• This class must be extended by the implementation
class.
• 3) compile implementation class & generate its stub
& skeleton class.
• rmic:(rmi compiler ) tools provided with jdk is used
to generate stub & skeleton class for a rmi object.
• Syntax: rmic className of RemoteObject
• Ex . Rmic Myadder
• MyAdder_Stub.class & MyAdder_skeleton.class
• 4) start a directory service to facilitate registration &
lookup of remote stub .
• An implementation of directory service is provided
with jdk that provides the facility of registration &
lookup of remote stub.
• syntax to start rmiregistry: 1) on default port(1099)
• Rmiregistry
Enter
• 2) on a specific port :- rmiregistry port number
Enter
• 5) Create remote object and register its stub with
the directory server.
•
• Java.rmi.Naming : class provides static method to
register or lookup a remote object with RMI registry.
• bind():- register a remote stub with the given name in
the RMI registry .
• Public static void bind(String name, Remote
Object)throws RemoteException,
AlreadyBindException .
• rebind(): public static void rebind(String name,remote
object)throws RemoteException ;
• Lookup():- is used for search remote stub.
• Public static Remote lookup(String lookup
String)throws RemoteException;
• Formate of lookup String:- protocal/host
Address/port/registered name
• Note: protocal/host address is optional if rmiregistry
is running on default port on localhost.
• 5) Define a class to represent client: in client class
obtain the reference of remote stub from the
directory server and invoke remote method on it.
• If rmi registry is running on a different port then
default method of registering remote stub is
changed.i.e at the time of registration address of
the host as well as port number of the rmi registry
is used.
• For this purpose registry & LocateRegistryClass
provided in java.rmi.registry package.
• LocateRegistry class is a factory that provides
method to obtain registry object. A registry object is
used to bound ,unbound or lookup a stub in the
rmi registry.
• You can see easily using
• >javap java.rmi.registry.LocateRegistry >a.txt.
• > a.txt
• getRegistry() method of LocateRegistry class is used
to create a registry object.
• 1)Public static registry getRegistry(String hostName)
remote exception.
• 2) Public static Registry getRegistry(int port)throws
remote exception.
• Public static registry getRegistry(String host
name,int port)throws remote exception;
• A registry class provides bind & rebind method to
register an object to the directory server.