SlideShare a Scribd company logo
ADVANCE JAVA
ADVANCE JAVA
Author Profile
 Ankit Desai
 Ph.D. Scholar, IET, Ahmedabad University
 Education: M. Tech. (C.E.), B. E. (I. T.)
 Experience: 8 years (Academic and Research)
 Research Interest: IoT, Big Data Analytics, Machine
Learning, Data Mining, Algorithms.
Classified e-Material 2
ADVANCE JAVA
Classified e-Material 3
Introduction
to
Java Remote Method (RMI)
Invocation
ADVANCE JAVA
Classified e-Material 4
Overview of the Session
 Introduce the architecture of Java RMI
 Demonstrate how to build a simple distributed
system using Java RMI
 Investigate the advanced features of Java RMI
ADVANCE JAVA
Classified e-Material 5
The Goal of RMI
 To extend the Java Object model to support
programming with distributed Objects
 The intention is to make distributed programming
as easy as standard Java programming
 Focus on application logic not distribution
ADVANCE JAVA
Classified e-Material 6
A Simple Overview
 Java RMI allows one Java object to call methods on
another Java object in a different JVM
Local
Object
Remote
Object
Client JVM
Server JVM
Method parameters
Result or exception
ADVANCE JAVA
Classified e-Material 7
Distributed Programming
 Java RMI is interface based
 A remote object (or distributed service) is specified
by its interface
 “interfaces define behaviour and classes define
implementations”
 Termed Remote Interfaces
Interface Implementation
Client Program Server Program
RMI
System
ADVANCE JAVA
Classified e-Material 8
Distributed Programming (cont.)
 Before you invoke a method on a remote object you
need a reference to this object
 Look for an object with a specific interface type
 There are many ways to find this information
 Discovery Protocols
 Naming Service e.g. RMI Registry
ADVANCE JAVA
Classified e-Material 9
The RMI Registry
 The RMI Registry is a naming service
 Separately Running service
 Initiated using Java’s “rmiregistry” tool
 Server programs register remote objects
 Give the object a name it can be found using
 Client programs lookup object references that match
this service name
 Registry names have a URL format
 rmi://<hostname>:<port>/<ServiceName>
 E.g. rmi://localhost:1099/CalculatorService
 E.g. rmi://194.80.36.30:1099/ChatService
ADVANCE JAVA
Classified e-Material 10
The RMI Registry Interface
 void rebind (String name, Remote obj)
 This method is used by the server to register the
identifier of a remote object by name.
 void bind (String name, Remote obj)
 This method can alternatively be used by a server to
register a remote object by name, but if the name is
already bound to a remote object reference an
exception is thrown.
 void unbind (String name, Remote obj)
 This method removes a binding.
 Remote lookup(String name)
 This method is used by the clients to lookup a remote
object by name. A remote object reference is
returned.
ADVANCE JAVA
Classified e-Material 11
Lookup in Java RMI
RMIRegistry
Server
naming.rebind(“rmi://localhost:1099/TestS
ervice”, RemoteObjectReference)
Client
naming.lookup(“rmi://localhost:1099/
TestService”)
Interface Remote Object
Client Program Server Program
Local Machine
ADVANCE JAVA
Classified e-Material 12
The RMI Architecture
Client Program
Interface
Server Program
Implementation
Client Program Server Program
Remote Reference Layer Remote Reference Layer
Transport Layer
ADVANCE JAVA
Classified e-Material 13
Stubs and Skeleton Layer
 Stubs and skeletons
are generated from
the remote interface
 Using the “rmic” Java
tool
 Stub communicates
with a skeleton rather
than the remote object
 This a Proxy approach
 Marshalls the
parameters and results
to be sent across the
wire
 After java 1.1 skeletons
were made obsolete and
RMI now uses reflection
to direct a request to an
object
Interface
Client
Stub
Server
Skel
ADVANCE JAVA
Classified e-Material 14
Parameter Passing
 Parameter Passing in Java RMI is different from
standard Java
 Reminder: In Java, primitives are passed by value,
Objects are passed by reference
 In Java RMI
 Objects and primitives are passed by value
 Remote objects are passed by reference
 You must be aware of the differences!
 Otherwise you'll generate logical bugs that are
difficult to identify
ADVANCE JAVA
Classified e-Material 15
Parameter Passing (2)
 RMI-Pass by Value
 All ordinary objects and primitives are serialised and
a copy is passed
 Any changes to the copy do not affect the original
 It is your job to ensure your Objects can be
serialised!
 RMI-Pass by Reference
 Remote Object is the parameter, a stub (reference) is
sent
 the stub is used to modify the object, the original
object is modified
ADVANCE JAVA
Classified e-Material 16
A Chat Server Example
ChatServer
ChatServer
ChatServer
ChatServerImpl
Login(..)
Chat(..)
Chas: Hello
Dave: ASL?
Client A
Client B
Server
ADVANCE JAVA
Classified e-Material 17
Building a Java RMI system
An RMI system must be composed of the
following parts:
1. An interface definition of the remote services;
2. The implementations of the remote services;
3. Stub and skeleton files;
4. A server to host the remote services;
5. An RMI Naming service
6. A client program that uses the remote
services.
ADVANCE JAVA
Classified e-Material 18
Step 1 - Define the Remote Interface
 Declare the methods you'd like to call remotely
 This interface must extend java.rmi.Remote
 Each method must declare java.rmi.RemoteException
in its throws clause
 You can have multiple remote interfaces
 Remember about parameter passing
 Remote objects must be passed as remote interface
types
 Local objects must be serializable
ADVANCE JAVA
Classified e-Material 19
Example ChatServer Interface
public interface ChatServer extends
java.rmi.Remote {
public void login(String name, String password)
throws java.rmi.RemoteException;
public void logout(String name)
throws java.rmi.RemoteException;
public void chat(String name, String message)
throws java.rmi.RemoteException;
}
ADVANCE JAVA
Classified e-Material 20
Step 2 - Implement the remote service
 Your class must implement the Remote interface
 Extend this class with UnicastRemoteObject
 Must provide a constructor that throws a
RemoteException.
 Call super() in the constructor
 This activates code in UnicastRemoteObject that
performs the RMI linking and remote object
initialization.
ADVANCE JAVA
Classified e-Material 21
Example Remote Object (ChatServiceImpl)
public class ChatServerImpl
extends java.rmi.server.UnicastRemoteObject implements
ChatServer {
public ChatServerImpl() throws java.rmi.RemoteException
{
Super();
}
public void login(String name, String pass) throws
java.rmi.RemoteException{
// Method Implementation
}
public void logout(String name) throws
java.rmi.RemoteException{
// Method Implementation
}
public void chat(String name, String msg) throws
java.rmi.RemoteException{
// Method Implementation
}
}
ADVANCE JAVA
Classified e-Material 22
Step 3 – Generate Stubs & Skeletons
 Generate the Remote Interface stub
 This stub contains information that allows it to
connect to a remote object, which contains the
implementation of the methods
 RMI provides a tool called rmic to generate stubs
 Use rmic on the remote object
 e.g. rmic ChatServerImpl
 The files: *impl_Stub.class and *impl_Skel.class will
be created
ChatServer RMIC
ChatServerImpl_Stub.class
ChatServerImpl_Skel.class
ADVANCE JAVA
Classified e-Material 23
Step 4 – Create the Server
 The server is a Java application
 Creates one or more instances of remote objects
 Binds at least one of the remote objects to a name in
the RMI registry
 Uses the Naming.rebind() operation
ADVANCE JAVA
Classified e-Material 24
Example Chat Server
public class ChattingServer {
public ChattingServer() {
try {
ChatServer c = new
ChatServerImpl();
Naming.rebind("rmi://localhost
/ChatService", c);
}
catch (Exception e) {
System.out.println("Server Error: " +
e);
}
}
public static void main(String args[]) {
//Create the new Calculator
server
new ChattingServer();
}
}
Create the
remote
object
RMIRegistry
Register the
object
ADVANCE JAVA
Classified e-Material 25
Step 5 – Create the Client
 Get a remote reference by calling Naming.lookup()
 Remember - Lookup by service name
 Receives a stub object for the requested remote
object
 Loads code for the stub either locally or remotely
 Invoke methods directly on the reference
 Much like on standard Java objects
Stub class NetworkFile System OR
ADVANCE JAVA
Classified e-Material 26
Example Chat Client
public class calculatorclient {
public static void main(String[] args) {
try {
// Get a reference to the remote object through the rmiregistry
ChatServer c = (ChatServer)
Naming.lookup("rmi://localhost/ChatService");
// Now use the reference c to call remote methods
c.login(“Chas”,”*****”);
c.chat(“Chas”, “Hello”);
// Catch the exceptions that may occur - rubbish URL, Remote exception
} catch (RemoteException re) {
System.out.println("RemoteException“+re);
}
}
}
Interface
ADVANCE JAVA
Classified e-Material 27
Java RMI Advanced Features
 Serialisation
 Callbacks
 Remote Activation
ADVANCE JAVA
Classified e-Material 28
Serialisation
 To pass user created objects as parameters in RMI
they must be serialisable
 This is easy in Java – simply make the class
implement the Serializable interface
 If you want to optimise the serialisation you can
overide the methods of serializable with your own
implementation e.g. ObjectInput(Output)Stream
 Transforming an Object in a stream of bytes
 Can be sent across the network
ADVANCE JAVA
Classified e-Material 29
Callbacks
 In many applications the server may want to
callback the client
 All messages in the chat system are displayed on a
central server
 You could change the server to callback every client
with each new chat message allowing the message
to be displayed on each client
 Callbacks are just a reverse RMI
 You create a remote object on the client and pass this
reference to the server, who can invoke it directly
ADVANCE JAVA
Classified e-Material 30
Using Callbacks in Chat
ChatServer
ChatServer
ChatServer
ChatServerImpl
Login(.., Callback
Ref)
Chat(..)
Chas: Hello
Dave: ASL?
Client A Client B
Server
Chas: Hello
Dave: ASL?
Callback
Impl Callback
Impl
Callback
Callback
Display(Name.
Msg)
ADVANCE JAVA
Classified e-Material 31
Remote Activation
 Server hosting remote objects continuously execute
 This wastes system resources
 Ideally, a Remote Object would be dormant until it
was invoked
 Java RMI Remote Activation provides this process
 Rather than a server program, you register each
object with the rmid daemon
 Unfortunately this is complex to program!
 See on-line tutorials on web site to find out how to do
it
 Ask the demonstrators
Ad

More Related Content

What's hot (20)

Java RMI Presentation
Java RMI PresentationJava RMI Presentation
Java RMI Presentation
Masud Rahman
 
Threads in JAVA
Threads in JAVAThreads in JAVA
Threads in JAVA
Haldia Institute of Technology
 
Rmi ppt
Rmi pptRmi ppt
Rmi ppt
BVC Engineering College
 
07 java collection
07 java collection07 java collection
07 java collection
Abhishek Khune
 
Java Collection framework
Java Collection frameworkJava Collection framework
Java Collection framework
ankitgarg_er
 
Java RMI
Java RMIJava RMI
Java RMI
Prajakta Nimje
 
JDBC: java DataBase connectivity
JDBC: java DataBase connectivityJDBC: java DataBase connectivity
JDBC: java DataBase connectivity
Tanmoy Barman
 
9. Input Output in java
9. Input Output in java9. Input Output in java
9. Input Output in java
Nilesh Dalvi
 
Java rmi
Java rmiJava rmi
Java rmi
kamal kotecha
 
Advance Java Topics (J2EE)
Advance Java Topics (J2EE)Advance Java Topics (J2EE)
Advance Java Topics (J2EE)
slire
 
Server Side Programming
Server Side ProgrammingServer Side Programming
Server Side Programming
Milan Thapa
 
Java Serialization
Java SerializationJava Serialization
Java Serialization
imypraz
 
Java threads
Java threadsJava threads
Java threads
Prabhakaran V M
 
Spring Core
Spring CoreSpring Core
Spring Core
Pushan Bhattacharya
 
Java awt (abstract window toolkit)
Java awt (abstract window toolkit)Java awt (abstract window toolkit)
Java awt (abstract window toolkit)
Elizabeth alexander
 
Class and Objects in Java
Class and Objects in JavaClass and Objects in Java
Class and Objects in Java
Spotle.ai
 
Collections framework in java
Collections framework in javaCollections framework in java
Collections framework in java
yugandhar vadlamudi
 
Broadcast Receiver
Broadcast ReceiverBroadcast Receiver
Broadcast Receiver
nationalmobileapps
 
Rmi presentation
Rmi presentationRmi presentation
Rmi presentation
Azad public school
 
Java Collections
Java  Collections Java  Collections
Java Collections
Kongu Engineering College, Perundurai, Erode
 

Viewers also liked (20)

Remote Method Invocation (Java RMI)
Remote Method Invocation (Java RMI)Remote Method Invocation (Java RMI)
Remote Method Invocation (Java RMI)
Sonali Parab
 
RMI
RMIRMI
RMI
Aravind Nair
 
Java rmi
Java rmiJava rmi
Java rmi
Tanmoy Barman
 
Java rmi example program with code
Java rmi example program with codeJava rmi example program with code
Java rmi example program with code
kamal kotecha
 
Introduction To Rmi
Introduction To RmiIntroduction To Rmi
Introduction To Rmi
SwarupKulkarni
 
Basic java
Basic java Basic java
Basic java
Raghu nath
 
Ravi Tuppad
Ravi TuppadRavi Tuppad
Ravi Tuppad
Raviraj Tuppad
 
Java rmi
Java rmiJava rmi
Java rmi
Fazlur Rahman
 
Rmi architecture
Rmi architectureRmi architecture
Rmi architecture
Maulik Desai
 
Distributed Programming using RMI
Distributed Programming using RMIDistributed Programming using RMI
Distributed Programming using RMI
backdoor
 
Rmi
RmiRmi
Rmi
Jafar Nesargi
 
Naming And Binding (Distributed computing)
Naming And Binding (Distributed computing)Naming And Binding (Distributed computing)
Naming And Binding (Distributed computing)
Sri Prasanna
 
remote method invocation
remote method invocationremote method invocation
remote method invocation
Arun Nair
 
Networking
NetworkingNetworking
Networking
Ravi Kant Sahu
 
Rmi ppt-2003
Rmi ppt-2003Rmi ppt-2003
Rmi ppt-2003
kalaranjani1990
 
Java networking programs - theory
Java networking programs - theoryJava networking programs - theory
Java networking programs - theory
Mukesh Tekwani
 
javarmi
javarmijavarmi
javarmi
Arjun Shanka
 
Rmi
RmiRmi
Rmi
leminhvuong
 
Jdbc 1
Jdbc 1Jdbc 1
Jdbc 1
Mukesh Tekwani
 
Distributed Objects: CORBA/Java RMI
Distributed Objects: CORBA/Java RMIDistributed Objects: CORBA/Java RMI
Distributed Objects: CORBA/Java RMI
elliando dias
 
Ad

Similar to Java RMI (20)

Remote Method Invocation
Remote Method InvocationRemote Method Invocation
Remote Method Invocation
Sonali Parab
 
Remote method invocatiom
Remote method invocatiomRemote method invocatiom
Remote method invocatiom
sakthibalabalamuruga
 
Rmi
RmiRmi
Rmi
vantinhkhuc
 
Remote Method Invocation
Remote Method InvocationRemote Method Invocation
Remote Method Invocation
ashishspace
 
Distributed Objects and JAVA
Distributed Objects and JAVADistributed Objects and JAVA
Distributed Objects and JAVA
elliando dias
 
DS
DSDS
DS
Verma Mukesh
 
Rmi
RmiRmi
Rmi
phanleson
 
Distributed Programming using RMI
 Distributed Programming using RMI Distributed Programming using RMI
Distributed Programming using RMI
backdoor
 
Rmi3
Rmi3Rmi3
Rmi3
John Thiagarajan
 
17rmi
17rmi17rmi
17rmi
Adil Jafri
 
Remote method invocation
Remote method invocationRemote method invocation
Remote method invocation
Veni7
 
RMI (Remote Method Invocation)
RMI (Remote Method Invocation)RMI (Remote Method Invocation)
RMI (Remote Method Invocation)
Thesis Scientist Private Limited
 
ADB Lab Manual.docx
ADB Lab Manual.docxADB Lab Manual.docx
ADB Lab Manual.docx
SaiKumarPrajapathi
 
Sql and plsql syntax and commands aaaaaa
Sql and plsql syntax and commands aaaaaaSql and plsql syntax and commands aaaaaa
Sql and plsql syntax and commands aaaaaa
thirugnanasambandham4
 
Artificial intelligence - chapter 2 problems, problem spaces, and search
Artificial intelligence - chapter 2 problems, problem spaces, and searchArtificial intelligence - chapter 2 problems, problem spaces, and search
Artificial intelligence - chapter 2 problems, problem spaces, and search
thirugnanasambandham4
 
Module 3 remote method invocation-2
Module 3   remote method  invocation-2Module 3   remote method  invocation-2
Module 3 remote method invocation-2
Ankit Dubey
 
A Short Java RMI Tutorial
A Short Java RMI TutorialA Short Java RMI Tutorial
A Short Java RMI Tutorial
Guo Albert
 
Rmi
RmiRmi
Rmi
Mallikarjuna G D
 
Remote method invocation
Remote method invocationRemote method invocation
Remote method invocation
Dew Shishir
 
Remote Method Invocation
Remote Method InvocationRemote Method Invocation
Remote Method Invocation
Paul Pajo
 
Remote Method Invocation
Remote Method InvocationRemote Method Invocation
Remote Method Invocation
Sonali Parab
 
Remote Method Invocation
Remote Method InvocationRemote Method Invocation
Remote Method Invocation
ashishspace
 
Distributed Objects and JAVA
Distributed Objects and JAVADistributed Objects and JAVA
Distributed Objects and JAVA
elliando dias
 
Distributed Programming using RMI
 Distributed Programming using RMI Distributed Programming using RMI
Distributed Programming using RMI
backdoor
 
Remote method invocation
Remote method invocationRemote method invocation
Remote method invocation
Veni7
 
Sql and plsql syntax and commands aaaaaa
Sql and plsql syntax and commands aaaaaaSql and plsql syntax and commands aaaaaa
Sql and plsql syntax and commands aaaaaa
thirugnanasambandham4
 
Artificial intelligence - chapter 2 problems, problem spaces, and search
Artificial intelligence - chapter 2 problems, problem spaces, and searchArtificial intelligence - chapter 2 problems, problem spaces, and search
Artificial intelligence - chapter 2 problems, problem spaces, and search
thirugnanasambandham4
 
Module 3 remote method invocation-2
Module 3   remote method  invocation-2Module 3   remote method  invocation-2
Module 3 remote method invocation-2
Ankit Dubey
 
A Short Java RMI Tutorial
A Short Java RMI TutorialA Short Java RMI Tutorial
A Short Java RMI Tutorial
Guo Albert
 
Remote method invocation
Remote method invocationRemote method invocation
Remote method invocation
Dew Shishir
 
Remote Method Invocation
Remote Method InvocationRemote Method Invocation
Remote Method Invocation
Paul Pajo
 
Ad

More from Ankit Desai (20)

java Jdbc
java Jdbc java Jdbc
java Jdbc
Ankit Desai
 
java code and document security
java code and document securityjava code and document security
java code and document security
Ankit Desai
 
Java Beans
Java BeansJava Beans
Java Beans
Ankit Desai
 
java drag and drop and data transfer
java drag and drop and data transferjava drag and drop and data transfer
java drag and drop and data transfer
Ankit Desai
 
java swing programming
java swing programming java swing programming
java swing programming
Ankit Desai
 
Java Networking
Java NetworkingJava Networking
Java Networking
Ankit Desai
 
JDBC
JDBCJDBC
JDBC
Ankit Desai
 
Presentation14 audio play
Presentation14 audio playPresentation14 audio play
Presentation14 audio play
Ankit Desai
 
Presentation15 parse xml
Presentation15 parse xmlPresentation15 parse xml
Presentation15 parse xml
Ankit Desai
 
Presentation11 sq lite
Presentation11 sq litePresentation11 sq lite
Presentation11 sq lite
Ankit Desai
 
Hadoop installation
Hadoop installationHadoop installation
Hadoop installation
Ankit Desai
 
Presentation10 view navigation
Presentation10 view navigationPresentation10 view navigation
Presentation10 view navigation
Ankit Desai
 
Presentation7 segment control
Presentation7 segment controlPresentation7 segment control
Presentation7 segment control
Ankit Desai
 
Presentation6 ui image_view
Presentation6 ui image_viewPresentation6 ui image_view
Presentation6 ui image_view
Ankit Desai
 
Presentation5 picker view
Presentation5 picker viewPresentation5 picker view
Presentation5 picker view
Ankit Desai
 
Presentation4 date picker
Presentation4 date pickerPresentation4 date picker
Presentation4 date picker
Ankit Desai
 
Presentation3 actionsheet alertview
Presentation3 actionsheet alertviewPresentation3 actionsheet alertview
Presentation3 actionsheet alertview
Ankit Desai
 
Presentation1 password
Presentation1 passwordPresentation1 password
Presentation1 password
Ankit Desai
 
Presentation2 gesture control
Presentation2 gesture controlPresentation2 gesture control
Presentation2 gesture control
Ankit Desai
 
Presentation8 silder switch_progress
Presentation8 silder switch_progressPresentation8 silder switch_progress
Presentation8 silder switch_progress
Ankit Desai
 
java code and document security
java code and document securityjava code and document security
java code and document security
Ankit Desai
 
java drag and drop and data transfer
java drag and drop and data transferjava drag and drop and data transfer
java drag and drop and data transfer
Ankit Desai
 
java swing programming
java swing programming java swing programming
java swing programming
Ankit Desai
 
Presentation14 audio play
Presentation14 audio playPresentation14 audio play
Presentation14 audio play
Ankit Desai
 
Presentation15 parse xml
Presentation15 parse xmlPresentation15 parse xml
Presentation15 parse xml
Ankit Desai
 
Presentation11 sq lite
Presentation11 sq litePresentation11 sq lite
Presentation11 sq lite
Ankit Desai
 
Hadoop installation
Hadoop installationHadoop installation
Hadoop installation
Ankit Desai
 
Presentation10 view navigation
Presentation10 view navigationPresentation10 view navigation
Presentation10 view navigation
Ankit Desai
 
Presentation7 segment control
Presentation7 segment controlPresentation7 segment control
Presentation7 segment control
Ankit Desai
 
Presentation6 ui image_view
Presentation6 ui image_viewPresentation6 ui image_view
Presentation6 ui image_view
Ankit Desai
 
Presentation5 picker view
Presentation5 picker viewPresentation5 picker view
Presentation5 picker view
Ankit Desai
 
Presentation4 date picker
Presentation4 date pickerPresentation4 date picker
Presentation4 date picker
Ankit Desai
 
Presentation3 actionsheet alertview
Presentation3 actionsheet alertviewPresentation3 actionsheet alertview
Presentation3 actionsheet alertview
Ankit Desai
 
Presentation1 password
Presentation1 passwordPresentation1 password
Presentation1 password
Ankit Desai
 
Presentation2 gesture control
Presentation2 gesture controlPresentation2 gesture control
Presentation2 gesture control
Ankit Desai
 
Presentation8 silder switch_progress
Presentation8 silder switch_progressPresentation8 silder switch_progress
Presentation8 silder switch_progress
Ankit Desai
 

Recently uploaded (20)

Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025
Splunk
 
Cybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure ADCybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure AD
VICTOR MAESTRE RAMIREZ
 
Heap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and DeletionHeap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and Deletion
Jaydeep Kale
 
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptxDevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
Justin Reock
 
Big Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur MorganBig Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur Morgan
Arthur Morgan
 
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes
 
Role of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered ManufacturingRole of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered Manufacturing
Andrew Leo
 
HCL Nomad Web – Best Practices and Managing Multiuser Environments
HCL Nomad Web – Best Practices and Managing Multiuser EnvironmentsHCL Nomad Web – Best Practices and Managing Multiuser Environments
HCL Nomad Web – Best Practices and Managing Multiuser Environments
panagenda
 
Cyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of securityCyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of security
riccardosl1
 
tecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdftecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdf
fjgm517
 
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-UmgebungenHCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
panagenda
 
What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...
Vishnu Singh Chundawat
 
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptxSpecial Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
shyamraj55
 
AI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global TrendsAI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global Trends
InData Labs
 
Mobile App Development Company in Saudi Arabia
Mobile App Development Company in Saudi ArabiaMobile App Development Company in Saudi Arabia
Mobile App Development Company in Saudi Arabia
Steve Jonas
 
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep DiveDesigning Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
ScyllaDB
 
Procurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptxProcurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptx
Jon Hansen
 
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Impelsys Inc.
 
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven InsightsAndrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell
 
Build Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For DevsBuild Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For Devs
Brian McKeiver
 
Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025
Splunk
 
Cybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure ADCybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure AD
VICTOR MAESTRE RAMIREZ
 
Heap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and DeletionHeap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and Deletion
Jaydeep Kale
 
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptxDevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
Justin Reock
 
Big Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur MorganBig Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur Morgan
Arthur Morgan
 
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes
 
Role of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered ManufacturingRole of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered Manufacturing
Andrew Leo
 
HCL Nomad Web – Best Practices and Managing Multiuser Environments
HCL Nomad Web – Best Practices and Managing Multiuser EnvironmentsHCL Nomad Web – Best Practices and Managing Multiuser Environments
HCL Nomad Web – Best Practices and Managing Multiuser Environments
panagenda
 
Cyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of securityCyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of security
riccardosl1
 
tecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdftecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdf
fjgm517
 
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-UmgebungenHCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
panagenda
 
What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...
Vishnu Singh Chundawat
 
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptxSpecial Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
shyamraj55
 
AI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global TrendsAI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global Trends
InData Labs
 
Mobile App Development Company in Saudi Arabia
Mobile App Development Company in Saudi ArabiaMobile App Development Company in Saudi Arabia
Mobile App Development Company in Saudi Arabia
Steve Jonas
 
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep DiveDesigning Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
ScyllaDB
 
Procurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptxProcurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptx
Jon Hansen
 
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Impelsys Inc.
 
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven InsightsAndrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell
 
Build Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For DevsBuild Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For Devs
Brian McKeiver
 

Java RMI

  • 2. ADVANCE JAVA Author Profile  Ankit Desai  Ph.D. Scholar, IET, Ahmedabad University  Education: M. Tech. (C.E.), B. E. (I. T.)  Experience: 8 years (Academic and Research)  Research Interest: IoT, Big Data Analytics, Machine Learning, Data Mining, Algorithms. Classified e-Material 2
  • 3. ADVANCE JAVA Classified e-Material 3 Introduction to Java Remote Method (RMI) Invocation
  • 4. ADVANCE JAVA Classified e-Material 4 Overview of the Session  Introduce the architecture of Java RMI  Demonstrate how to build a simple distributed system using Java RMI  Investigate the advanced features of Java RMI
  • 5. ADVANCE JAVA Classified e-Material 5 The Goal of RMI  To extend the Java Object model to support programming with distributed Objects  The intention is to make distributed programming as easy as standard Java programming  Focus on application logic not distribution
  • 6. ADVANCE JAVA Classified e-Material 6 A Simple Overview  Java RMI allows one Java object to call methods on another Java object in a different JVM Local Object Remote Object Client JVM Server JVM Method parameters Result or exception
  • 7. ADVANCE JAVA Classified e-Material 7 Distributed Programming  Java RMI is interface based  A remote object (or distributed service) is specified by its interface  “interfaces define behaviour and classes define implementations”  Termed Remote Interfaces Interface Implementation Client Program Server Program RMI System
  • 8. ADVANCE JAVA Classified e-Material 8 Distributed Programming (cont.)  Before you invoke a method on a remote object you need a reference to this object  Look for an object with a specific interface type  There are many ways to find this information  Discovery Protocols  Naming Service e.g. RMI Registry
  • 9. ADVANCE JAVA Classified e-Material 9 The RMI Registry  The RMI Registry is a naming service  Separately Running service  Initiated using Java’s “rmiregistry” tool  Server programs register remote objects  Give the object a name it can be found using  Client programs lookup object references that match this service name  Registry names have a URL format  rmi://<hostname>:<port>/<ServiceName>  E.g. rmi://localhost:1099/CalculatorService  E.g. rmi://194.80.36.30:1099/ChatService
  • 10. ADVANCE JAVA Classified e-Material 10 The RMI Registry Interface  void rebind (String name, Remote obj)  This method is used by the server to register the identifier of a remote object by name.  void bind (String name, Remote obj)  This method can alternatively be used by a server to register a remote object by name, but if the name is already bound to a remote object reference an exception is thrown.  void unbind (String name, Remote obj)  This method removes a binding.  Remote lookup(String name)  This method is used by the clients to lookup a remote object by name. A remote object reference is returned.
  • 11. ADVANCE JAVA Classified e-Material 11 Lookup in Java RMI RMIRegistry Server naming.rebind(“rmi://localhost:1099/TestS ervice”, RemoteObjectReference) Client naming.lookup(“rmi://localhost:1099/ TestService”) Interface Remote Object Client Program Server Program Local Machine
  • 12. ADVANCE JAVA Classified e-Material 12 The RMI Architecture Client Program Interface Server Program Implementation Client Program Server Program Remote Reference Layer Remote Reference Layer Transport Layer
  • 13. ADVANCE JAVA Classified e-Material 13 Stubs and Skeleton Layer  Stubs and skeletons are generated from the remote interface  Using the “rmic” Java tool  Stub communicates with a skeleton rather than the remote object  This a Proxy approach  Marshalls the parameters and results to be sent across the wire  After java 1.1 skeletons were made obsolete and RMI now uses reflection to direct a request to an object Interface Client Stub Server Skel
  • 14. ADVANCE JAVA Classified e-Material 14 Parameter Passing  Parameter Passing in Java RMI is different from standard Java  Reminder: In Java, primitives are passed by value, Objects are passed by reference  In Java RMI  Objects and primitives are passed by value  Remote objects are passed by reference  You must be aware of the differences!  Otherwise you'll generate logical bugs that are difficult to identify
  • 15. ADVANCE JAVA Classified e-Material 15 Parameter Passing (2)  RMI-Pass by Value  All ordinary objects and primitives are serialised and a copy is passed  Any changes to the copy do not affect the original  It is your job to ensure your Objects can be serialised!  RMI-Pass by Reference  Remote Object is the parameter, a stub (reference) is sent  the stub is used to modify the object, the original object is modified
  • 16. ADVANCE JAVA Classified e-Material 16 A Chat Server Example ChatServer ChatServer ChatServer ChatServerImpl Login(..) Chat(..) Chas: Hello Dave: ASL? Client A Client B Server
  • 17. ADVANCE JAVA Classified e-Material 17 Building a Java RMI system An RMI system must be composed of the following parts: 1. An interface definition of the remote services; 2. The implementations of the remote services; 3. Stub and skeleton files; 4. A server to host the remote services; 5. An RMI Naming service 6. A client program that uses the remote services.
  • 18. ADVANCE JAVA Classified e-Material 18 Step 1 - Define the Remote Interface  Declare the methods you'd like to call remotely  This interface must extend java.rmi.Remote  Each method must declare java.rmi.RemoteException in its throws clause  You can have multiple remote interfaces  Remember about parameter passing  Remote objects must be passed as remote interface types  Local objects must be serializable
  • 19. ADVANCE JAVA Classified e-Material 19 Example ChatServer Interface public interface ChatServer extends java.rmi.Remote { public void login(String name, String password) throws java.rmi.RemoteException; public void logout(String name) throws java.rmi.RemoteException; public void chat(String name, String message) throws java.rmi.RemoteException; }
  • 20. ADVANCE JAVA Classified e-Material 20 Step 2 - Implement the remote service  Your class must implement the Remote interface  Extend this class with UnicastRemoteObject  Must provide a constructor that throws a RemoteException.  Call super() in the constructor  This activates code in UnicastRemoteObject that performs the RMI linking and remote object initialization.
  • 21. ADVANCE JAVA Classified e-Material 21 Example Remote Object (ChatServiceImpl) public class ChatServerImpl extends java.rmi.server.UnicastRemoteObject implements ChatServer { public ChatServerImpl() throws java.rmi.RemoteException { Super(); } public void login(String name, String pass) throws java.rmi.RemoteException{ // Method Implementation } public void logout(String name) throws java.rmi.RemoteException{ // Method Implementation } public void chat(String name, String msg) throws java.rmi.RemoteException{ // Method Implementation } }
  • 22. ADVANCE JAVA Classified e-Material 22 Step 3 – Generate Stubs & Skeletons  Generate the Remote Interface stub  This stub contains information that allows it to connect to a remote object, which contains the implementation of the methods  RMI provides a tool called rmic to generate stubs  Use rmic on the remote object  e.g. rmic ChatServerImpl  The files: *impl_Stub.class and *impl_Skel.class will be created ChatServer RMIC ChatServerImpl_Stub.class ChatServerImpl_Skel.class
  • 23. ADVANCE JAVA Classified e-Material 23 Step 4 – Create the Server  The server is a Java application  Creates one or more instances of remote objects  Binds at least one of the remote objects to a name in the RMI registry  Uses the Naming.rebind() operation
  • 24. ADVANCE JAVA Classified e-Material 24 Example Chat Server public class ChattingServer { public ChattingServer() { try { ChatServer c = new ChatServerImpl(); Naming.rebind("rmi://localhost /ChatService", c); } catch (Exception e) { System.out.println("Server Error: " + e); } } public static void main(String args[]) { //Create the new Calculator server new ChattingServer(); } } Create the remote object RMIRegistry Register the object
  • 25. ADVANCE JAVA Classified e-Material 25 Step 5 – Create the Client  Get a remote reference by calling Naming.lookup()  Remember - Lookup by service name  Receives a stub object for the requested remote object  Loads code for the stub either locally or remotely  Invoke methods directly on the reference  Much like on standard Java objects Stub class NetworkFile System OR
  • 26. ADVANCE JAVA Classified e-Material 26 Example Chat Client public class calculatorclient { public static void main(String[] args) { try { // Get a reference to the remote object through the rmiregistry ChatServer c = (ChatServer) Naming.lookup("rmi://localhost/ChatService"); // Now use the reference c to call remote methods c.login(“Chas”,”*****”); c.chat(“Chas”, “Hello”); // Catch the exceptions that may occur - rubbish URL, Remote exception } catch (RemoteException re) { System.out.println("RemoteException“+re); } } } Interface
  • 27. ADVANCE JAVA Classified e-Material 27 Java RMI Advanced Features  Serialisation  Callbacks  Remote Activation
  • 28. ADVANCE JAVA Classified e-Material 28 Serialisation  To pass user created objects as parameters in RMI they must be serialisable  This is easy in Java – simply make the class implement the Serializable interface  If you want to optimise the serialisation you can overide the methods of serializable with your own implementation e.g. ObjectInput(Output)Stream  Transforming an Object in a stream of bytes  Can be sent across the network
  • 29. ADVANCE JAVA Classified e-Material 29 Callbacks  In many applications the server may want to callback the client  All messages in the chat system are displayed on a central server  You could change the server to callback every client with each new chat message allowing the message to be displayed on each client  Callbacks are just a reverse RMI  You create a remote object on the client and pass this reference to the server, who can invoke it directly
  • 30. ADVANCE JAVA Classified e-Material 30 Using Callbacks in Chat ChatServer ChatServer ChatServer ChatServerImpl Login(.., Callback Ref) Chat(..) Chas: Hello Dave: ASL? Client A Client B Server Chas: Hello Dave: ASL? Callback Impl Callback Impl Callback Callback Display(Name. Msg)
  • 31. ADVANCE JAVA Classified e-Material 31 Remote Activation  Server hosting remote objects continuously execute  This wastes system resources  Ideally, a Remote Object would be dormant until it was invoked  Java RMI Remote Activation provides this process  Rather than a server program, you register each object with the rmid daemon  Unfortunately this is complex to program!  See on-line tutorials on web site to find out how to do it  Ask the demonstrators