SlideShare une entreprise Scribd logo
1  sur  24
Remote Method Invocation
www.sunilos.com
www.raystec.com
www.SunilOS.com 2
Single Server App
Server
Payment
<<Service>>
Shop
<<JSP>>
Inventory
<<Service>>
www.SunilOS.com 3
Distributed Application
Client
Shop
<<JSP>>
Server 1
Payment
<<Service>>
Server - 2
Inventory
<<Service>>
www.SunilOS.com 4
Communication Protocol
Client
Shop
<<JSP>>
Server 1
Payment
<<Service>>
Server - 2
Inventory
<<Service>>
RMI
SOAP
(XML)
CORBA
www.SunilOS.com5
Java Remote Object Invocation (RMI)
 Java RMI allows the programmer to execute a method of
remote class using the same semantics as local method
call.
Local Machine (Client)
AddServer remoteObject;
int s;
…
s=remoteObject.sum(1,2);
System.out.println(s);
Remote Machine
(Server)
public int sum(int
a,int b) {
return a + b;
}
1,2
3
www.SunilOS.com 6
The General RMI Architecture
 The server must first bind its
name to the registry.
 The client looks up the
server name in the registry
to establish remote
references.
 The Stub serializes the
parameters to skeleton, the
skeleton invokes the remote
method and serializes the
result back to the stub.
www.SunilOS.com 7
The Stub and Skeleton
 A client invokes a remote method, the call is first forwarded to
stub.
 The stub is responsible for sending the remote call over to the
server-side skeleton.
 The stub opens a socket to the remote server, marshals the
object parameters and forwards the data stream to the skeleton.
 A skeleton contains a method that receives the remote calls,
unmarshals the parameters, and invokes the actual remote object
implementation.
Stub
RMI Client RMI Server
skeleton
return
call
www.SunilOS.com 8
Steps for Developing an RMI System
1. Define the remote interface.
2. Develop the remote object by implementing the remote
interface.
3. Develop the client program.
4. Compile the Java source files.
5. Generate the client stubs and server skeletons.
6. Start the RMI registry.
7. Start the remote server objects.
8. Run the client.
www.SunilOS.com 9
Class Hierarchy
Remote
<<interface>>
AddServerIntf
<<interface>>
+ sum(int a,int b):int
AddServerImpl
+ sum(int a,int b):int
+add(int a):int
extends
implements
UnicastRemoteObject
extends
RMIRegistry
<<index>>
Client
www.SunilOS.com 10
Step 1: Defining the Remote Interface
import java.rmi.*;
public interface AddServerIntf extends Remote
{
public int sum(int a,int b) throws
RemoteException;
}
www.SunilOS.com 11
Step 2: Defining the Remote Server
 The server is a simple unicast remote server. Server is created by
extending java.rmi.server.UnicastRemoteObject.
 The server uses the RMISecurityManager to protect its resources
while engaging in remote communication.
import java.rmi.*; import java.rmi.server.*;
import java.rmi.registry.*;
public class AddServerImpl extends UnicastRemoteObject implements
AddServerIntf {
AddServerImpl() throws RemoteException{
super();
}
….
www.SunilOS.com 12
Step 2: Defining the Remote Server ( Cont.)
// Remote method implementation
public int sum(int a,int 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 of server is “ADD-SERVER”.
In the main method of your server object, the RMI security manager is
created and installed.
www.SunilOS.com 13
Step 2: Defining the Remote Server
 Main method to start Server
public static void main(String args[]) throws Exception{
//set the security manager
System.setSecurityManager(new RMISecurityManager());
//create a local instance of the server object
AddServerImpl serverObj= new AddServerImpl();
//Bind server instance with RMI Registry
Naming.rebind("ADD-SERVER" , serverObj);
System.out.println("Server is started.....");
}
www.SunilOS.com 14
Step 3: Developing the Client program
 Client will look up the name of server in the registry using
java.rmi.Naming class.
 The server name is specified as URL:
o rmi://host:port/name
 Default RMI port is 1099.
 The name specified in the URL must exactly match the name that
the server has bound to the registry. In this example, the name of
server is “ADD-SERVER”.
 The remote method invocation is programmed using the remote
interface name (remoteObject) as prefix and the remote method
name (sum) as suffix.
www.SunilOS.com 15
Step 3: Developing the client program (Cont.)
public class SampleClient{
public static void main(String[] args){
// set the security manager for the client
System.setSecurityManager(new RMISecurityManager());
//get the remote object from the registry
try {
String url = “rmi://localhost:1099/ADD-SERVER”;
AddServerIntf remoteObject =(AddServerIntf)Naming.lookup(url);
System.out.println(" SUM = " + remoteObject.sum(1,2) );
}catch (RemoteException exc) {
System.out.println("Error in lookup: " + exc.toString()); }
catch (java.net.MalformedURLException exc) {
System.out.println("Malformed URL: " + exc.toString()); }
catch (java.rmi.NotBoundException exc) {
System.out.println("NotBound: " + exc.toString());
}
}
www.SunilOS.com 16
Step 4 : Compiling Classes
Assume the program is in c:rmi
o c:rmi> set CLASSPATH=”c:/rmi”
o c:rmi> javac AddServerIntf.java
o c:rmi> javac AddServerImpl.java
o c:rmi> javac SampleClient.java
www.SunilOS.com 17
Step 5: Generating stubs and skeletons
 The RMI system provides an RMI compiler (rmic) that
takes your RMI interface and class and generates stub
and skeleton.
 Assuming that classes are stored in c:/rmi folder and
run following commands from command prompt:
o c:rmi> set CLASSPATH=”c:/rmi”
o c:rmi> javac AddServerIntf.java
o c:rmi> javac AddServerImpl.java
o c:rmi> rmic AddServerImpl
www.SunilOS.com 18
Step 6: Starting the RMI registry
 The RMI Server objects are bound with the RMI Registry
and registry is started by calling command:
o rmiregistry
 By default port #1099 is used by RMI Registry. You can
also bind registry to a different port number by indicating
the port number next to command as:
o rmiregistry <new port>
 c:rmi>rmiregistry 1099
www.SunilOS.com 19
Steps 7: Starting Server and Client
 First Registry is started then Server will be started and bound to
Registry by a unique name.
 A security policy will be set when server is started. Granted
permissions are declared in a policy file. It is a text file. Policy file is
applied by –D command option:
o –Djava.security.policy=policy.all
 Open a command prompt and start server by:
o c:rmi> java –Djava.security.policy=policy.all AddServerImpl
 Open another command prompt and run client:
o c:rmi> java –Djava.security.policy=policy.all SampleClient
www.SunilOS.com 20
Java Policy File
The Java application must first obtain information
regarding its privileges. It can obtain the security
policy through a policy file.
In our example, we will allow Java code to have
all permissions. Policy file contents will be:
grant {
permission java.security.AllPermission;
};
Specific Permissions
grant {
permission java.io.filePermission “/tmp/*”, “read”, “write”;
permission java.net.SocketPermission “www.sunrays..co.in :
999”,”connect”;
permission java.net.SocketPermission “*:1024-65535”,”connect,request”;
permission java.net.SocketPermission “*:80”,”connect”;
};
Allows classes to read/write any file under the “/tmp” directory and its
subdirectories.
Allows classes to establish a network connection with the host
“www.SunilOS.com” at port 999.
Allows classes to connect to or accept connections on unprivileged
ports greater than 1024, on any host.
Allows all classes to connect to the HTTP port 80 on any host.
www.SunilOS.com 21
www.SunilOS.com 22
Run it!
 Open Command Prompt 1
 >rmiregistry
 Open Command Prompt 2
 >java -Djava.security.policy=policy.all AddServer
 Open Command Prompt 3
 >java -Djava.security.policy=policy.all AddClient
Disclaimer
This is an educational presentation to enhance the
skill of computer science students.
This presentation is available for free to computer
science students.
Some internet images from different URLs are
used in this presentation to simplify technical
examples and correlate examples with the real
world.
We are grateful to owners of these URLs and
pictures.
www.SunilOS.com 23
Thank You!
www.SunilOS.com 24
www.SunilOS.com

Contenu connexe

Tendances

Java IO Package and Streams
Java IO Package and StreamsJava IO Package and Streams
Java IO Package and Streamsbabak danyal
 
Datatypes in python
Datatypes in pythonDatatypes in python
Datatypes in pythoneShikshak
 
standard template library(STL) in C++
standard template library(STL) in C++standard template library(STL) in C++
standard template library(STL) in C++•sreejith •sree
 
Thread priority in java
Thread priority in javaThread priority in java
Thread priority in javaRakesh Mittal
 
Object oriented analysis
Object oriented analysisObject oriented analysis
Object oriented analysisMahesh Bhalerao
 
Remote Method Invocation in JAVA
Remote Method Invocation in JAVARemote Method Invocation in JAVA
Remote Method Invocation in JAVAJalpesh Vasa
 
Software applications and challenges
Software applications and challenges Software applications and challenges
Software applications and challenges Madhar Khan Pathan
 
Interface specification
Interface specificationInterface specification
Interface specificationmaliksiddique1
 
16. Concurrency Control in DBMS
16. Concurrency Control in DBMS16. Concurrency Control in DBMS
16. Concurrency Control in DBMSkoolkampus
 
input/ output in java
input/ output  in javainput/ output  in java
input/ output in javasharma230399
 
oops concept in java | object oriented programming in java
oops concept in java | object oriented programming in javaoops concept in java | object oriented programming in java
oops concept in java | object oriented programming in javaCPD INDIA
 
Event Handling in java
Event Handling in javaEvent Handling in java
Event Handling in javaGoogle
 
Network programming in Java
Network programming in JavaNetwork programming in Java
Network programming in JavaTushar B Kute
 

Tendances (20)

Java I/O
Java I/OJava I/O
Java I/O
 
Java IO Package and Streams
Java IO Package and StreamsJava IO Package and Streams
Java IO Package and Streams
 
Datatypes in python
Datatypes in pythonDatatypes in python
Datatypes in python
 
standard template library(STL) in C++
standard template library(STL) in C++standard template library(STL) in C++
standard template library(STL) in C++
 
Threads in JAVA
Threads in JAVAThreads in JAVA
Threads in JAVA
 
Thread priority in java
Thread priority in javaThread priority in java
Thread priority in java
 
Object oriented analysis
Object oriented analysisObject oriented analysis
Object oriented analysis
 
Triggers and active database
Triggers and active databaseTriggers and active database
Triggers and active database
 
Java operators
Java operatorsJava operators
Java operators
 
Remote Method Invocation in JAVA
Remote Method Invocation in JAVARemote Method Invocation in JAVA
Remote Method Invocation in JAVA
 
Software applications and challenges
Software applications and challenges Software applications and challenges
Software applications and challenges
 
Interface
InterfaceInterface
Interface
 
Interface specification
Interface specificationInterface specification
Interface specification
 
16. Concurrency Control in DBMS
16. Concurrency Control in DBMS16. Concurrency Control in DBMS
16. Concurrency Control in DBMS
 
input/ output in java
input/ output  in javainput/ output  in java
input/ output in java
 
Applets in java
Applets in javaApplets in java
Applets in java
 
Java rmi
Java rmiJava rmi
Java rmi
 
oops concept in java | object oriented programming in java
oops concept in java | object oriented programming in javaoops concept in java | object oriented programming in java
oops concept in java | object oriented programming in java
 
Event Handling in java
Event Handling in javaEvent Handling in java
Event Handling in java
 
Network programming in Java
Network programming in JavaNetwork programming in Java
Network programming in Java
 

Similaire à RMI Architecture and Java Remote Method Invocation

Similaire à RMI Architecture and Java Remote Method Invocation (20)

Distributed Objects and JAVA
Distributed Objects and JAVADistributed Objects and JAVA
Distributed Objects and JAVA
 
Rmi
RmiRmi
Rmi
 
Rmi
RmiRmi
Rmi
 
Java rmi example program with code
Java rmi example program with codeJava rmi example program with code
Java rmi example program with code
 
Java remote method invocation
Java remote method invocationJava remote method invocation
Java remote method invocation
 
Rmi
RmiRmi
Rmi
 
Remote method invocatiom
Remote method invocatiomRemote method invocatiom
Remote method invocatiom
 
Java rmi
Java rmiJava rmi
Java rmi
 
Rmi ppt
Rmi pptRmi ppt
Rmi ppt
 
Remote Method Invocation
Remote Method InvocationRemote Method Invocation
Remote Method Invocation
 
ADB Lab Manual.docx
ADB Lab Manual.docxADB Lab Manual.docx
ADB Lab Manual.docx
 
17rmi
17rmi17rmi
17rmi
 
Android workshop
Android workshopAndroid workshop
Android workshop
 
Call Back
Call BackCall Back
Call Back
 
Module 1 Introduction
Module 1   IntroductionModule 1   Introduction
Module 1 Introduction
 
Call Back
Call BackCall Back
Call Back
 
Call Back
Call BackCall Back
Call Back
 
Call Back
Call BackCall Back
Call Back
 
Rmi3
Rmi3Rmi3
Rmi3
 
RMI (Remote Method Invocation)
RMI (Remote Method Invocation)RMI (Remote Method Invocation)
RMI (Remote Method Invocation)
 

Plus de Sunil OS

Threads V4
Threads  V4Threads  V4
Threads V4Sunil OS
 
Java IO Streams V4
Java IO Streams V4Java IO Streams V4
Java IO Streams V4Sunil OS
 
Java Basics V3
Java Basics V3Java Basics V3
Java Basics V3Sunil OS
 
Threads v3
Threads v3Threads v3
Threads v3Sunil OS
 
Exception Handling v3
Exception Handling v3Exception Handling v3
Exception Handling v3Sunil OS
 
Collection v3
Collection v3Collection v3
Collection v3Sunil OS
 
Java 8 - CJ
Java 8 - CJJava 8 - CJ
Java 8 - CJSunil OS
 
Machine learning ( Part 3 )
Machine learning ( Part 3 )Machine learning ( Part 3 )
Machine learning ( Part 3 )Sunil OS
 
Machine learning ( Part 2 )
Machine learning ( Part 2 )Machine learning ( Part 2 )
Machine learning ( Part 2 )Sunil OS
 
Machine learning ( Part 1 )
Machine learning ( Part 1 )Machine learning ( Part 1 )
Machine learning ( Part 1 )Sunil OS
 
Python Pandas
Python PandasPython Pandas
Python PandasSunil OS
 
Python part2 v1
Python part2 v1Python part2 v1
Python part2 v1Sunil OS
 
Angular 8
Angular 8 Angular 8
Angular 8 Sunil OS
 
Python Part 1
Python Part 1Python Part 1
Python Part 1Sunil OS
 
C# Variables and Operators
C# Variables and OperatorsC# Variables and Operators
C# Variables and OperatorsSunil OS
 

Plus de Sunil OS (20)

Threads V4
Threads  V4Threads  V4
Threads V4
 
Java IO Streams V4
Java IO Streams V4Java IO Streams V4
Java IO Streams V4
 
OOP V3.1
OOP V3.1OOP V3.1
OOP V3.1
 
Java Basics V3
Java Basics V3Java Basics V3
Java Basics V3
 
DJango
DJangoDJango
DJango
 
PDBC
PDBCPDBC
PDBC
 
OOP v3
OOP v3OOP v3
OOP v3
 
Threads v3
Threads v3Threads v3
Threads v3
 
Exception Handling v3
Exception Handling v3Exception Handling v3
Exception Handling v3
 
Collection v3
Collection v3Collection v3
Collection v3
 
Java 8 - CJ
Java 8 - CJJava 8 - CJ
Java 8 - CJ
 
Machine learning ( Part 3 )
Machine learning ( Part 3 )Machine learning ( Part 3 )
Machine learning ( Part 3 )
 
Machine learning ( Part 2 )
Machine learning ( Part 2 )Machine learning ( Part 2 )
Machine learning ( Part 2 )
 
Machine learning ( Part 1 )
Machine learning ( Part 1 )Machine learning ( Part 1 )
Machine learning ( Part 1 )
 
Python Pandas
Python PandasPython Pandas
Python Pandas
 
Python part2 v1
Python part2 v1Python part2 v1
Python part2 v1
 
Angular 8
Angular 8 Angular 8
Angular 8
 
Python Part 1
Python Part 1Python Part 1
Python Part 1
 
C# Variables and Operators
C# Variables and OperatorsC# Variables and Operators
C# Variables and Operators
 
C# Basics
C# BasicsC# Basics
C# Basics
 

Dernier

Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...fonyou31
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajanpragatimahajan3
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...Sapna Thakur
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Disha Kariya
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room servicediscovermytutordmt
 

Dernier (20)

Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajan
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room service
 

RMI Architecture and Java Remote Method Invocation

  • 2. www.SunilOS.com 2 Single Server App Server Payment <<Service>> Shop <<JSP>> Inventory <<Service>>
  • 3. www.SunilOS.com 3 Distributed Application Client Shop <<JSP>> Server 1 Payment <<Service>> Server - 2 Inventory <<Service>>
  • 4. www.SunilOS.com 4 Communication Protocol Client Shop <<JSP>> Server 1 Payment <<Service>> Server - 2 Inventory <<Service>> RMI SOAP (XML) CORBA
  • 5. www.SunilOS.com5 Java Remote Object Invocation (RMI)  Java RMI allows the programmer to execute a method of remote class using the same semantics as local method call. Local Machine (Client) AddServer remoteObject; int s; … s=remoteObject.sum(1,2); System.out.println(s); Remote Machine (Server) public int sum(int a,int b) { return a + b; } 1,2 3
  • 6. www.SunilOS.com 6 The General RMI Architecture  The server must first bind its name to the registry.  The client looks up the server name in the registry to establish remote references.  The Stub serializes the parameters to skeleton, the skeleton invokes the remote method and serializes the result back to the stub.
  • 7. www.SunilOS.com 7 The Stub and Skeleton  A client invokes a remote method, the call is first forwarded to stub.  The stub is responsible for sending the remote call over to the server-side skeleton.  The stub opens a socket to the remote server, marshals the object parameters and forwards the data stream to the skeleton.  A skeleton contains a method that receives the remote calls, unmarshals the parameters, and invokes the actual remote object implementation. Stub RMI Client RMI Server skeleton return call
  • 8. www.SunilOS.com 8 Steps for Developing an RMI System 1. Define the remote interface. 2. Develop the remote object by implementing the remote interface. 3. Develop the client program. 4. Compile the Java source files. 5. Generate the client stubs and server skeletons. 6. Start the RMI registry. 7. Start the remote server objects. 8. Run the client.
  • 9. www.SunilOS.com 9 Class Hierarchy Remote <<interface>> AddServerIntf <<interface>> + sum(int a,int b):int AddServerImpl + sum(int a,int b):int +add(int a):int extends implements UnicastRemoteObject extends RMIRegistry <<index>> Client
  • 10. www.SunilOS.com 10 Step 1: Defining the Remote Interface import java.rmi.*; public interface AddServerIntf extends Remote { public int sum(int a,int b) throws RemoteException; }
  • 11. www.SunilOS.com 11 Step 2: Defining the Remote Server  The server is a simple unicast remote server. Server is created by extending java.rmi.server.UnicastRemoteObject.  The server uses the RMISecurityManager to protect its resources while engaging in remote communication. import java.rmi.*; import java.rmi.server.*; import java.rmi.registry.*; public class AddServerImpl extends UnicastRemoteObject implements AddServerIntf { AddServerImpl() throws RemoteException{ super(); } ….
  • 12. www.SunilOS.com 12 Step 2: Defining the Remote Server ( Cont.) // Remote method implementation public int sum(int a,int 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 of server is “ADD-SERVER”. In the main method of your server object, the RMI security manager is created and installed.
  • 13. www.SunilOS.com 13 Step 2: Defining the Remote Server  Main method to start Server public static void main(String args[]) throws Exception{ //set the security manager System.setSecurityManager(new RMISecurityManager()); //create a local instance of the server object AddServerImpl serverObj= new AddServerImpl(); //Bind server instance with RMI Registry Naming.rebind("ADD-SERVER" , serverObj); System.out.println("Server is started....."); }
  • 14. www.SunilOS.com 14 Step 3: Developing the Client program  Client will look up the name of server in the registry using java.rmi.Naming class.  The server name is specified as URL: o rmi://host:port/name  Default RMI port is 1099.  The name specified in the URL must exactly match the name that the server has bound to the registry. In this example, the name of server is “ADD-SERVER”.  The remote method invocation is programmed using the remote interface name (remoteObject) as prefix and the remote method name (sum) as suffix.
  • 15. www.SunilOS.com 15 Step 3: Developing the client program (Cont.) public class SampleClient{ public static void main(String[] args){ // set the security manager for the client System.setSecurityManager(new RMISecurityManager()); //get the remote object from the registry try { String url = “rmi://localhost:1099/ADD-SERVER”; AddServerIntf remoteObject =(AddServerIntf)Naming.lookup(url); System.out.println(" SUM = " + remoteObject.sum(1,2) ); }catch (RemoteException exc) { System.out.println("Error in lookup: " + exc.toString()); } catch (java.net.MalformedURLException exc) { System.out.println("Malformed URL: " + exc.toString()); } catch (java.rmi.NotBoundException exc) { System.out.println("NotBound: " + exc.toString()); } }
  • 16. www.SunilOS.com 16 Step 4 : Compiling Classes Assume the program is in c:rmi o c:rmi> set CLASSPATH=”c:/rmi” o c:rmi> javac AddServerIntf.java o c:rmi> javac AddServerImpl.java o c:rmi> javac SampleClient.java
  • 17. www.SunilOS.com 17 Step 5: Generating stubs and skeletons  The RMI system provides an RMI compiler (rmic) that takes your RMI interface and class and generates stub and skeleton.  Assuming that classes are stored in c:/rmi folder and run following commands from command prompt: o c:rmi> set CLASSPATH=”c:/rmi” o c:rmi> javac AddServerIntf.java o c:rmi> javac AddServerImpl.java o c:rmi> rmic AddServerImpl
  • 18. www.SunilOS.com 18 Step 6: Starting the RMI registry  The RMI Server objects are bound with the RMI Registry and registry is started by calling command: o rmiregistry  By default port #1099 is used by RMI Registry. You can also bind registry to a different port number by indicating the port number next to command as: o rmiregistry <new port>  c:rmi>rmiregistry 1099
  • 19. www.SunilOS.com 19 Steps 7: Starting Server and Client  First Registry is started then Server will be started and bound to Registry by a unique name.  A security policy will be set when server is started. Granted permissions are declared in a policy file. It is a text file. Policy file is applied by –D command option: o –Djava.security.policy=policy.all  Open a command prompt and start server by: o c:rmi> java –Djava.security.policy=policy.all AddServerImpl  Open another command prompt and run client: o c:rmi> java –Djava.security.policy=policy.all SampleClient
  • 20. www.SunilOS.com 20 Java Policy File The Java application must first obtain information regarding its privileges. It can obtain the security policy through a policy file. In our example, we will allow Java code to have all permissions. Policy file contents will be: grant { permission java.security.AllPermission; };
  • 21. Specific Permissions grant { permission java.io.filePermission “/tmp/*”, “read”, “write”; permission java.net.SocketPermission “www.sunrays..co.in : 999”,”connect”; permission java.net.SocketPermission “*:1024-65535”,”connect,request”; permission java.net.SocketPermission “*:80”,”connect”; }; Allows classes to read/write any file under the “/tmp” directory and its subdirectories. Allows classes to establish a network connection with the host “www.SunilOS.com” at port 999. Allows classes to connect to or accept connections on unprivileged ports greater than 1024, on any host. Allows all classes to connect to the HTTP port 80 on any host. www.SunilOS.com 21
  • 22. www.SunilOS.com 22 Run it!  Open Command Prompt 1  >rmiregistry  Open Command Prompt 2  >java -Djava.security.policy=policy.all AddServer  Open Command Prompt 3  >java -Djava.security.policy=policy.all AddClient
  • 23. Disclaimer This is an educational presentation to enhance the skill of computer science students. This presentation is available for free to computer science students. Some internet images from different URLs are used in this presentation to simplify technical examples and correlate examples with the real world. We are grateful to owners of these URLs and pictures. www.SunilOS.com 23