SlideShare a Scribd company logo
REMOTE METHOD INVOCATION
PROGRAMMAZIONE CONCORRENTE E DISTR.
Università degli Studi di Padova
Dipartimento di Matematica
Corso di Laurea in Informatica, A.A. 2015 – 2016
rcardin@math.unipd.it
Programmazione concorrente e distribuita
SUMMARY
 Introduction
 Remote interfaces
 Dynamic code loading
 Serialization
 Security manager
 Exporting remote objects
 Compiling
 Running
 Distributed garbage collection
2Riccardo Cardin
Programmazione concorrente e distribuita
INTRODUCTION
 RMI allows applications to call object methods
located remotely
 A server program creates some remote objects
 A client program obtains a remote reference and
then invokes methods on them
 Distributed object application
 Sharing resources, processing load across systems
 RMI provides mechanism by which the server and the
client communicate
 Using low level communication (i.e. sockets) is harder and
less performing
 Serialization has a cost and its difficult to share some state
3Riccardo Cardin
Programmazione concorrente e distribuita
INTRODUCTION
 Distributed object applications need to do the
following
 Locate remote objects
 Application can register its remote objects with RMI's simple
naming facility, the RMI registry
 Communicate with remote objects
 Details of communication between remote objects are
handled by RMI
 Load class definitions for objects that are passed
around
 RMI provides mechanisms for loading an object's class
definitions as well as for transmitting an object's data
4Riccardo Cardin
Programmazione concorrente e distribuita
INTRODUCTION
5Riccardo Cardin
1
2
3
4
5
6
Client side Server side
Programmazione concorrente e distribuita
CREATING DISTRIBUTED APPLICATIONS
 Developing a distributed application using RMI
involves these general steps:
 Designing and implementing the components
 Defining the remote interfaces
 Implementing the remote objects
 Implementing the clients
 Compiling sources
 Making classes network accessible
 Typically a web server is used for this purpose
 Starting the application
 Registry, server, client, ...
6Riccardo Cardin
Programmazione concorrente e distribuita
CREATING DISTRIBUTED APPLICATIONS
7Riccardo Cardin
Programmazione concorrente e distribuita
REMOTE INTERFACES
 Distributed application are made up of remote
interfaces and classes
 Objects with methods that can be invoked across Java
virtual machines are called remote objects.
 A remote interfaces has the following characteristics
 Extends the interface java.rmi.Remote
 Each method of the interface
declares java.rmi.RemoteException in its throws clause
 Remote objects are treated like an object reference
 A local representation (remote stub) is sent to other JVMs
 Implementation of the Remote proxy pattern
 Any other object is copied before being sent
8Riccardo Cardin
Programmazione concorrente e distribuita
REMOTE INTERFACES
 Each interface defines a specific protocol
 It’s important to clearly separate methods’ interfaces
from their implementation
 Methods of an interface that extends Remote can be
invoked from another JVM
 Remote methods MUST throw a RemoteException
 A checked exception used to indicate either a communication
failure or a protocol error
 Remote interfaces are defined server side
9Riccardo Cardin
// The interface implements java.rmi.Remote and its unique method
// throws a java.rmi.RemoteException
public interface Compute extends Remote {
<T> T executeTask(Task<T> t) throws RemoteException;
}
Programmazione concorrente e distribuita
REMOTE INTERFACES
 A remote interface must be implemented
 The implementing class can declare more methods,
but these will not be seen by the clients
 Parameters of remote methods follow these rules:
 Remote objects are passed by reference. Changes made
remotely are reflected in the original remote object
 A stub is a proxy to the remote object that communicates
with the original remote object
 Local objects are passed by copy, using serialization
 Changes are not propagated back in any way
10Riccardo Cardin
public class ComputeEngine implements Compute {
// Implement at least remote methods
}
Programmazione concorrente e distribuita
REMOTE INTERFACES
11Riccardo Cardin
Programmazione concorrente e distribuita
DYNAMIC CODE LOADING
 Interfaces that are not marked as remote must
be serializable
 Type that are not marked as remote are passed by
copy, using serialization
 Use java.io.Serializable has a marked interface
 The implementation will be dinamically downloaded
by RMI into the host JVM
 This is possibile beacuse all objects are written in Java
12Riccardo Cardin
// This is not a remote intefaces, but it is used in the protocol
// defined by a remote method. It’s implementation must implement
// also the Serializable interface
public interface Task<T> {
T execute();
}
Programmazione concorrente e distribuita
SERIALIZATION
 Representation of an object as a sequence of
bytes, that includes data as well as type
 The process is JVM independent
 Serialization process uses the stream API
 ObjectInputStream and ObjectOutputStream types
 Deserialization is the opposite process
 The type must implement java.io.Serializable
 All fields in the class must be serializable. If a field is not, it
must be marked as transient
 Transient fields are not serialized and are lost intentionally
 A transient variable cannot be final or static
 Serialization is used by RMI, EJB and so on
13Riccardo Cardin
Programmazione concorrente e distribuita
SECURITY MANAGER
 Defines the outer boundaries of the sandbox for
downloaded (untrusted) code
 It descends from class java.lang.SecurityManager
 Security policies specify actions that are unsafe
 Accept or open a socket from/to a host and port
 Modify a thread (change its priority, ...)
 Interact with file system
 Interact with system properties
 Exit an application
 For every unsafe action there is a corresponding
checkXXX method
 Actions not allowed throw a SecurityException
14Riccardo Cardin
Programmazione concorrente e distribuita
SECURITY MANAGER
 RMI programs must install a security manager
 Otherwise RMI will not download classes
 Only one security manager can be installed
 By default, an application has no security manager installed
 Policies are specified using *.policy files
 Server and client application must specify their policy file
 Default file: java.home/lib/security/java.policy
 Use -Djava.security.policy property specify a file
15Riccardo Cardin
if (System.getSecurityManager() == null) {
System.setSecurityManager(new SecurityManager());
}
grant codeBase "file:/home/ann/src/" {
permission java.security.AllPermission;
};
Programmazione concorrente e distribuita
SECURITY MANAGER
16Riccardo Cardin
Programmazione concorrente e distribuita
EXPORTING REMOTE OBJECTS
 Remote objects need to be exported to the RMI
runtime
 Exporting means create stub objects that expose the
remote methods to clients
 Stub is the client placeholder for the remote object
 The stub implements the remote interface
 It is a remote proxy to the remote object
 2° arg to exportObject is the listening port for incoming
connection
17Riccardo Cardin
Compute engine = new ComputeEngine();
// Listening to port 0 means to listen on every port
Compute stub =
(Compute) UnicastRemoteObject.exportObject(engine, 0);
Programmazione concorrente e distribuita
EXPORTING REMOTE OBJECTS
18Riccardo Cardin
Programmazione concorrente e distribuita
EXPORTING REMOTE OBJECTS
 RMI Registry: a remote map for other remote
objects, indexed by names
 The server register a remote object (stub), the client
retrieve it using the same name
 The java.rmi.Naming type provides methods for
storing and obtaining references to remote objects
 Available methods are bind, unbind and rebind
 The name argument specifies the host and port of the registry
 The object represents the remote object (stub) to expose to
clients
19Riccardo Cardin
// Name is a string that represents an URL without the scheme
// //host:port/name
Naming.bind(name, object)
Programmazione concorrente e distribuita
EXPORTING REMOTE OBJECTS
 RMI Registry
 The creation and lookup of a new Registry can be
done using the type LocateRegistry
 A registry is a remote object binded to a fixed name
 This type offers also an API to interact with the registry
 For security reasons, an application can bind an object with a
registry running on the same host
 Using the lookup method, a client can retrieve a stub
20Riccardo Cardin
// Retrieves the default registry listening on port 1099
Registry registry = LocateRegistry.getRegistry();
// Asks the registry to bind a stub to a name
registry.rebind(name, stub);
// The name was the same used to bind the object
Compute comp = (Compute) registry.lookup(name);
Programmazione concorrente e distribuita
EXPORTING REMOTE OBJECTS
21Riccardo Cardin
A client looks up from the
RMI registry a stub binded
to a name
A server bind a stub to a
specific name in a RMI
registry
The client calls remote
methods, passing
serializable type as
arguments
1
2
3
Programmazione concorrente e distribuita
COMPILING
 Compilation of an RMI program requires a series
of different steps
 Create an archive (JAR) with remote interfaces
 This archive will be shared across server and clients
 The above jar needs to be shared with the registry
 Definitions that can be automatically downloaded
have to be placed in a public folder
 For example, use an HTTP web server for this purpose
 Build server classes
22Riccardo Cardin
javac compute/Compute.java compute/Task.java
jar cvf compute.jar compute/*.class
javac -cp c:homeannpublic_htmlclassescompute.jar
engineComputeEngine.java
Programmazione concorrente e distribuita
COMPILING
 Compilation of an RMI program requires a series
of different steps
 Build client classes
 The Task interface needs to be public accessible
 The client needs also the jar of remote interfaces
 Defining security policies for server and clients
 Create a *.policy file for each actor, specifying which
actions are allowed to be performed by the downloaded code
23Riccardo Cardin
javac -cp /home/jones/public_html/classes/compute.jar
client/ComputePi.java client/Pi.java
cp client/Pi.class /home/jones/public_html/classes/client
grant codeBase "file:/home/ann/src/" {
permission java.security.AllPermission;
};
Programmazione concorrente e distribuita
RUNNING
 Starting the server components
 Start the RMI registry, given with the JDK platform
 Start the server program
 Use java.rmi.server.codebase to specify the location of
remote interfaces archive
 Use java.rmi.server.hostname to specify the host for
stubs exported from the server JVM
 By default RMI uses the the IP address of the host
 Use java.security.policy to specify the policy file
24Riccardo Cardin
start rmiregistry 1099 :: By default the registry run on port 1099
java -cp c:homeannsrc;c:classescompute.jar
-Djava.rmi.server.codebase= file:/c:/classes/compute.jar
-Djava.rmi.server.hostname=mycomputer.example.com
-Djava.security.policy=server.policy engine.ComputeEngine
Programmazione concorrente e distribuita
RUNNING
 Starting the client component
 Start the client program
 Use java.rmi.server.codebase to specify the location of
client’s interfaces implementation
 Use java.security.policy to specify the policy file
 The host name of the server can be supplied as an argument
of the program
25Riccardo Cardin
java -cp c:homejonessrc;c:classescompute.jar
-Djava.rmi.server.codebase=file:/c:/classes/
-Djava.security.policy=client.policy
client.ComputePi mycomputer.example.com 45
Programmazione concorrente e distribuita
RUNNING
26Riccardo Cardin
The registry search the stub
implementation into the web
server
The implementation of client
interfaces are loaded by the
server from the public codebase
Programmazione concorrente e distribuita
RUNNING
27Riccardo Cardin
Programmazione concorrente e distribuita
DISTRIBUTED GARBAGE COLLECTION
 RMI uses a reference-counting algorithm
 Keeps track of all live references within each JVM
 The first reference to a remote object sends a “referenced”
message to the server for that object. Reference count is
incremented
 As live references are found to be unreferenced in local JVM,
the count is decremented. When the last reference has been
discarded, an unreferenced message is sent
 When a remote object is not referenced by any client, the
RMI runtime refers to it using a weak reference
 Due to connection delays, it is possible that
premature collection of remote object will occur
 A reference to this object will thrown a RemoteException
28Riccardo Cardin
Programmazione concorrente e distribuita
EXAMPLES
29Riccardo Cardin
https://github.com/rcardin/pcd-snippets
Programmazione concorrente e distribuita
REFERENCES
 The Java Tutorials: RMI
https://docs.oracle.com/javase/tutorial/rmi/
 The Java Tutorials: Security Manager
https://docs.oracle.com/javase/tutorial/essential/environment/sec
urity.html
 Java security: How to install the security manager and customize
your security policy
http://www.javaworld.com/article/2077067/core-java/java-
security---how-to-install-the-security-manager-and-customize-your-
security-policy.html
 Default Policy Implementation and Policy File Syntax
http://docs.oracle.com/javase/7/docs/technotes/guides/security/P
olicyFiles.html
30Riccardo Cardin
Programmazione concorrente e distribuita
REFERENCES
 Java RMI : What is the role of the stub-skeleton that are generated
by the rmic compiler
http://stackoverflow.com/questions/16886889/java-rmi-what-is-
the-role-of-the-stub-skeleton-that-are-generated-by-the-rmic
 Java – Serialization
http://www.tutorialspoint.com/java/java_serialization.htm
 Garbage Collection of Remote Objects
https://docs.oracle.com/javase/8/docs/platform/rmi/spec/rmi-
arch4.html
31Riccardo Cardin

More Related Content

What's hot

javarmi
javarmijavarmi
javarmi
Arjun Shanka
 
Advanced Reflection in Java
Advanced Reflection in JavaAdvanced Reflection in Java
Advanced Reflection in Java
kim.mens
 
Designing Better API
Designing Better APIDesigning Better API
Designing Better API
Kaniska Mandal
 
J3d hibernate
J3d hibernateJ3d hibernate
J3d hibernate
KRANTHICMR
 
Javainterview
JavainterviewJavainterview
Javainterview
Amarjit03
 
Introduction to-vhdl
Introduction to-vhdlIntroduction to-vhdl
Introduction to-vhdl
Neeraj Gupta
 
Basics of reflection in java
Basics of reflection in javaBasics of reflection in java
Basics of reflection in java
kim.mens
 
Java Faqs useful for freshers and experienced
Java Faqs useful for freshers and experiencedJava Faqs useful for freshers and experienced
Java Faqs useful for freshers and experienced
yearninginjava
 
Managing Binary Compatibility in Scala (Scala Days 2011)
Managing Binary Compatibility in Scala (Scala Days 2011)Managing Binary Compatibility in Scala (Scala Days 2011)
Managing Binary Compatibility in Scala (Scala Days 2011)
mircodotta
 
Introduction to VHDL
Introduction to VHDLIntroduction to VHDL
Unit I Advanced Java Programming Course
Unit I   Advanced Java Programming CourseUnit I   Advanced Java Programming Course
Unit I Advanced Java Programming Course
parveen837153
 
Detecting aspect-specific code smells using Ekeko for AspectJ
Detecting aspect-specific code smells using Ekeko for AspectJDetecting aspect-specific code smells using Ekeko for AspectJ
Detecting aspect-specific code smells using Ekeko for AspectJ
Coen De Roover
 
Ekeko Technology Showdown at SoTeSoLa 2012
Ekeko Technology Showdown at SoTeSoLa 2012Ekeko Technology Showdown at SoTeSoLa 2012
Ekeko Technology Showdown at SoTeSoLa 2012
Coen De Roover
 
Lecture1
Lecture1Lecture1
Lecture1
karim_ibrahim
 
Java tutorial PPT
Java tutorial PPTJava tutorial PPT
Java tutorial PPT
Intelligo Technologies
 
Core java
Core java Core java
Core java
Ravi varma
 
Core Java Tutorials by Mahika Tutorials
Core Java Tutorials by Mahika TutorialsCore Java Tutorials by Mahika Tutorials
Core Java Tutorials by Mahika Tutorials
Mahika Tutorials
 
The SOUL Tool Suite for Querying Programs in Symbiosis with Eclipse
The SOUL Tool Suite for Querying Programs in Symbiosis with EclipseThe SOUL Tool Suite for Querying Programs in Symbiosis with Eclipse
The SOUL Tool Suite for Querying Programs in Symbiosis with Eclipse
Coen De Roover
 
Java faq's
Java faq'sJava faq's
Java faq's
Swathi Pothula
 
Introduction to JAVA
Introduction to JAVAIntroduction to JAVA
Introduction to JAVA
Professional Guru
 

What's hot (20)

javarmi
javarmijavarmi
javarmi
 
Advanced Reflection in Java
Advanced Reflection in JavaAdvanced Reflection in Java
Advanced Reflection in Java
 
Designing Better API
Designing Better APIDesigning Better API
Designing Better API
 
J3d hibernate
J3d hibernateJ3d hibernate
J3d hibernate
 
Javainterview
JavainterviewJavainterview
Javainterview
 
Introduction to-vhdl
Introduction to-vhdlIntroduction to-vhdl
Introduction to-vhdl
 
Basics of reflection in java
Basics of reflection in javaBasics of reflection in java
Basics of reflection in java
 
Java Faqs useful for freshers and experienced
Java Faqs useful for freshers and experiencedJava Faqs useful for freshers and experienced
Java Faqs useful for freshers and experienced
 
Managing Binary Compatibility in Scala (Scala Days 2011)
Managing Binary Compatibility in Scala (Scala Days 2011)Managing Binary Compatibility in Scala (Scala Days 2011)
Managing Binary Compatibility in Scala (Scala Days 2011)
 
Introduction to VHDL
Introduction to VHDLIntroduction to VHDL
Introduction to VHDL
 
Unit I Advanced Java Programming Course
Unit I   Advanced Java Programming CourseUnit I   Advanced Java Programming Course
Unit I Advanced Java Programming Course
 
Detecting aspect-specific code smells using Ekeko for AspectJ
Detecting aspect-specific code smells using Ekeko for AspectJDetecting aspect-specific code smells using Ekeko for AspectJ
Detecting aspect-specific code smells using Ekeko for AspectJ
 
Ekeko Technology Showdown at SoTeSoLa 2012
Ekeko Technology Showdown at SoTeSoLa 2012Ekeko Technology Showdown at SoTeSoLa 2012
Ekeko Technology Showdown at SoTeSoLa 2012
 
Lecture1
Lecture1Lecture1
Lecture1
 
Java tutorial PPT
Java tutorial PPTJava tutorial PPT
Java tutorial PPT
 
Core java
Core java Core java
Core java
 
Core Java Tutorials by Mahika Tutorials
Core Java Tutorials by Mahika TutorialsCore Java Tutorials by Mahika Tutorials
Core Java Tutorials by Mahika Tutorials
 
The SOUL Tool Suite for Querying Programs in Symbiosis with Eclipse
The SOUL Tool Suite for Querying Programs in Symbiosis with EclipseThe SOUL Tool Suite for Querying Programs in Symbiosis with Eclipse
The SOUL Tool Suite for Querying Programs in Symbiosis with Eclipse
 
Java faq's
Java faq'sJava faq's
Java faq's
 
Introduction to JAVA
Introduction to JAVAIntroduction to JAVA
Introduction to JAVA
 

Viewers also liked

Diagrammi delle Classi
Diagrammi delle ClassiDiagrammi delle Classi
Diagrammi delle Classi
Riccardo Cardin
 
Design Pattern Strutturali
Design Pattern StrutturaliDesign Pattern Strutturali
Design Pattern Strutturali
Riccardo Cardin
 
Java - Processing input and output
Java - Processing input and outputJava - Processing input and output
Java - Processing input and output
Riccardo Cardin
 
Design pattern architetturali Model View Controller, MVP e MVVM
Design pattern architetturali   Model View Controller, MVP e MVVMDesign pattern architetturali   Model View Controller, MVP e MVVM
Design pattern architetturali Model View Controller, MVP e MVVM
Riccardo Cardin
 
Java Graphics Programming
Java Graphics ProgrammingJava Graphics Programming
Java Graphics Programming
Riccardo Cardin
 
Errori comuni nei documenti di Analisi dei Requisiti
Errori comuni nei documenti di Analisi dei RequisitiErrori comuni nei documenti di Analisi dei Requisiti
Errori comuni nei documenti di Analisi dei Requisiti
Riccardo Cardin
 
Introduzione ai Design Pattern
Introduzione ai Design PatternIntroduzione ai Design Pattern
Introduzione ai Design Pattern
Riccardo Cardin
 
Java - Collections framework
Java - Collections frameworkJava - Collections framework
Java - Collections framework
Riccardo Cardin
 
Diagrammi di Sequenza
Diagrammi di SequenzaDiagrammi di Sequenza
Diagrammi di Sequenza
Riccardo Cardin
 
Presto updates to 0.178
Presto updates to 0.178Presto updates to 0.178
Presto updates to 0.178
Kai Sasaki
 
Scala For Java Programmers
Scala For Java ProgrammersScala For Java Programmers
Scala For Java Programmers
Enno Runne
 
Software architecture patterns
Software architecture patternsSoftware architecture patterns
Software architecture patterns
Riccardo Cardin
 
SOLID - Principles of Object Oriented Design
SOLID - Principles of Object Oriented DesignSOLID - Principles of Object Oriented Design
SOLID - Principles of Object Oriented Design
Riccardo Cardin
 
Design Pattern Architetturali - Dependency Injection
Design Pattern Architetturali - Dependency InjectionDesign Pattern Architetturali - Dependency Injection
Design Pattern Architetturali - Dependency Injection
Riccardo Cardin
 
Java - Sockets
Java - SocketsJava - Sockets
Java - Sockets
Riccardo Cardin
 
Scala - the good, the bad and the very ugly
Scala - the good, the bad and the very uglyScala - the good, the bad and the very ugly
Scala - the good, the bad and the very ugly
Bozhidar Bozhanov
 

Viewers also liked (16)

Diagrammi delle Classi
Diagrammi delle ClassiDiagrammi delle Classi
Diagrammi delle Classi
 
Design Pattern Strutturali
Design Pattern StrutturaliDesign Pattern Strutturali
Design Pattern Strutturali
 
Java - Processing input and output
Java - Processing input and outputJava - Processing input and output
Java - Processing input and output
 
Design pattern architetturali Model View Controller, MVP e MVVM
Design pattern architetturali   Model View Controller, MVP e MVVMDesign pattern architetturali   Model View Controller, MVP e MVVM
Design pattern architetturali Model View Controller, MVP e MVVM
 
Java Graphics Programming
Java Graphics ProgrammingJava Graphics Programming
Java Graphics Programming
 
Errori comuni nei documenti di Analisi dei Requisiti
Errori comuni nei documenti di Analisi dei RequisitiErrori comuni nei documenti di Analisi dei Requisiti
Errori comuni nei documenti di Analisi dei Requisiti
 
Introduzione ai Design Pattern
Introduzione ai Design PatternIntroduzione ai Design Pattern
Introduzione ai Design Pattern
 
Java - Collections framework
Java - Collections frameworkJava - Collections framework
Java - Collections framework
 
Diagrammi di Sequenza
Diagrammi di SequenzaDiagrammi di Sequenza
Diagrammi di Sequenza
 
Presto updates to 0.178
Presto updates to 0.178Presto updates to 0.178
Presto updates to 0.178
 
Scala For Java Programmers
Scala For Java ProgrammersScala For Java Programmers
Scala For Java Programmers
 
Software architecture patterns
Software architecture patternsSoftware architecture patterns
Software architecture patterns
 
SOLID - Principles of Object Oriented Design
SOLID - Principles of Object Oriented DesignSOLID - Principles of Object Oriented Design
SOLID - Principles of Object Oriented Design
 
Design Pattern Architetturali - Dependency Injection
Design Pattern Architetturali - Dependency InjectionDesign Pattern Architetturali - Dependency Injection
Design Pattern Architetturali - Dependency Injection
 
Java - Sockets
Java - SocketsJava - Sockets
Java - Sockets
 
Scala - the good, the bad and the very ugly
Scala - the good, the bad and the very uglyScala - the good, the bad and the very ugly
Scala - the good, the bad and the very ugly
 

Similar to Java - Remote method invocation

Rmi
RmiRmi
Rmi
RmiRmi
Remote method invocatiom
Remote method invocatiomRemote method invocatiom
Remote method invocatiom
sakthibalabalamuruga
 
Distributed Programming using RMI
 Distributed Programming using RMI Distributed Programming using RMI
Distributed Programming using RMI
backdoor
 
Distributed Programming using RMI
Distributed Programming using RMIDistributed Programming using RMI
Distributed Programming using RMI
backdoor
 
Remote Method Invocation in JAVA
Remote Method Invocation in JAVARemote Method Invocation in JAVA
Remote Method Invocation in JAVA
Jalpesh Vasa
 
Rmi ppt
Rmi pptRmi ppt
Remote Method Invocation
Remote Method InvocationRemote Method Invocation
Remote Method Invocation
Sonali Parab
 
Oracle docs rmi applications
Oracle docs rmi applicationsOracle docs rmi applications
Oracle docs rmi applications
Biswabrata Banerjee
 
Remote Method Invocation
Remote Method InvocationRemote Method Invocation
Remote Method Invocation
ashishspace
 
Java RMI
Java RMIJava RMI
Java RMI
Ankit Desai
 
Java RMI
Java RMIJava RMI
Java RMI
Prajakta Nimje
 
Rmi
RmiRmi
Basic java
Basic java Basic java
Basic java
Raghu nath
 
Remote Method Invocation (Java RMI)
Remote Method Invocation (Java RMI)Remote Method Invocation (Java RMI)
Remote Method Invocation (Java RMI)
Sonali Parab
 
Remote Method Innovation (RMI) In JAVA
Remote Method Innovation (RMI) In JAVARemote Method Innovation (RMI) In JAVA
Remote Method Innovation (RMI) In JAVA
Prankit Mishra
 
Distributed Objects and JAVA
Distributed Objects and JAVADistributed Objects and JAVA
Distributed Objects and JAVA
elliando dias
 
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
 
Remote Method Invocation, Advanced programming
Remote Method Invocation, Advanced programmingRemote Method Invocation, Advanced programming
Remote Method Invocation, Advanced programming
Gera Paulos
 
A Short Java RMI Tutorial
A Short Java RMI TutorialA Short Java RMI Tutorial
A Short Java RMI Tutorial
Guo Albert
 

Similar to Java - Remote method invocation (20)

Rmi
RmiRmi
Rmi
 
Rmi
RmiRmi
Rmi
 
Remote method invocatiom
Remote method invocatiomRemote method invocatiom
Remote method invocatiom
 
Distributed Programming using RMI
 Distributed Programming using RMI Distributed Programming using RMI
Distributed Programming using RMI
 
Distributed Programming using RMI
Distributed Programming using RMIDistributed Programming using RMI
Distributed Programming using RMI
 
Remote Method Invocation in JAVA
Remote Method Invocation in JAVARemote Method Invocation in JAVA
Remote Method Invocation in JAVA
 
Rmi ppt
Rmi pptRmi ppt
Rmi ppt
 
Remote Method Invocation
Remote Method InvocationRemote Method Invocation
Remote Method Invocation
 
Oracle docs rmi applications
Oracle docs rmi applicationsOracle docs rmi applications
Oracle docs rmi applications
 
Remote Method Invocation
Remote Method InvocationRemote Method Invocation
Remote Method Invocation
 
Java RMI
Java RMIJava RMI
Java RMI
 
Java RMI
Java RMIJava RMI
Java RMI
 
Rmi
RmiRmi
Rmi
 
Basic java
Basic java Basic java
Basic java
 
Remote Method Invocation (Java RMI)
Remote Method Invocation (Java RMI)Remote Method Invocation (Java RMI)
Remote Method Invocation (Java RMI)
 
Remote Method Innovation (RMI) In JAVA
Remote Method Innovation (RMI) In JAVARemote Method Innovation (RMI) In JAVA
Remote Method Innovation (RMI) In JAVA
 
Distributed Objects and JAVA
Distributed Objects and JAVADistributed Objects and JAVA
Distributed Objects and JAVA
 
Module 3 remote method invocation-2
Module 3   remote method  invocation-2Module 3   remote method  invocation-2
Module 3 remote method invocation-2
 
Remote Method Invocation, Advanced programming
Remote Method Invocation, Advanced programmingRemote Method Invocation, Advanced programming
Remote Method Invocation, Advanced programming
 
A Short Java RMI Tutorial
A Short Java RMI TutorialA Short Java RMI Tutorial
A Short Java RMI Tutorial
 

More from Riccardo Cardin

Design Pattern Comportamentali
Design Pattern ComportamentaliDesign Pattern Comportamentali
Design Pattern Comportamentali
Riccardo Cardin
 
Design Pattern Creazionali
Design Pattern CreazionaliDesign Pattern Creazionali
Design Pattern Creazionali
Riccardo Cardin
 
Diagrammi di Attività
Diagrammi di AttivitàDiagrammi di Attività
Diagrammi di Attività
Riccardo Cardin
 
Diagrammi Use Case
Diagrammi Use CaseDiagrammi Use Case
Diagrammi Use Case
Riccardo Cardin
 
Introduzione a UML
Introduzione a UMLIntroduzione a UML
Introduzione a UML
Riccardo Cardin
 
Mvc e di spring e angular js
Mvc e di   spring e angular jsMvc e di   spring e angular js
Mvc e di spring e angular js
Riccardo Cardin
 
Reactive programming principles
Reactive programming principlesReactive programming principles
Reactive programming principles
Riccardo Cardin
 

More from Riccardo Cardin (7)

Design Pattern Comportamentali
Design Pattern ComportamentaliDesign Pattern Comportamentali
Design Pattern Comportamentali
 
Design Pattern Creazionali
Design Pattern CreazionaliDesign Pattern Creazionali
Design Pattern Creazionali
 
Diagrammi di Attività
Diagrammi di AttivitàDiagrammi di Attività
Diagrammi di Attività
 
Diagrammi Use Case
Diagrammi Use CaseDiagrammi Use Case
Diagrammi Use Case
 
Introduzione a UML
Introduzione a UMLIntroduzione a UML
Introduzione a UML
 
Mvc e di spring e angular js
Mvc e di   spring e angular jsMvc e di   spring e angular js
Mvc e di spring e angular js
 
Reactive programming principles
Reactive programming principlesReactive programming principles
Reactive programming principles
 

Recently uploaded

Enums On Steroids - let's look at sealed classes !
Enums On Steroids - let's look at sealed classes !Enums On Steroids - let's look at sealed classes !
Enums On Steroids - let's look at sealed classes !
Marcin Chrost
 
Transform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR SolutionsTransform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR Solutions
TheSMSPoint
 
Microservice Teams - How the cloud changes the way we work
Microservice Teams - How the cloud changes the way we workMicroservice Teams - How the cloud changes the way we work
Microservice Teams - How the cloud changes the way we work
Sven Peters
 
Measures in SQL (SIGMOD 2024, Santiago, Chile)
Measures in SQL (SIGMOD 2024, Santiago, Chile)Measures in SQL (SIGMOD 2024, Santiago, Chile)
Measures in SQL (SIGMOD 2024, Santiago, Chile)
Julian Hyde
 
一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理
一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理
一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理
dakas1
 
Malibou Pitch Deck For Its €3M Seed Round
Malibou Pitch Deck For Its €3M Seed RoundMalibou Pitch Deck For Its €3M Seed Round
Malibou Pitch Deck For Its €3M Seed Round
sjcobrien
 
Fundamentals of Programming and Language Processors
Fundamentals of Programming and Language ProcessorsFundamentals of Programming and Language Processors
Fundamentals of Programming and Language Processors
Rakesh Kumar R
 
Mobile app Development Services | Drona Infotech
Mobile app Development Services  | Drona InfotechMobile app Development Services  | Drona Infotech
Mobile app Development Services | Drona Infotech
Drona Infotech
 
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
mz5nrf0n
 
Oracle 23c New Features For DBAs and Developers.pptx
Oracle 23c New Features For DBAs and Developers.pptxOracle 23c New Features For DBAs and Developers.pptx
Oracle 23c New Features For DBAs and Developers.pptx
Remote DBA Services
 
What next after learning python programming basics
What next after learning python programming basicsWhat next after learning python programming basics
What next after learning python programming basics
Rakesh Kumar R
 
ALGIT - Assembly Line for Green IT - Numbers, Data, Facts
ALGIT - Assembly Line for Green IT - Numbers, Data, FactsALGIT - Assembly Line for Green IT - Numbers, Data, Facts
ALGIT - Assembly Line for Green IT - Numbers, Data, Facts
Green Software Development
 
How Can Hiring A Mobile App Development Company Help Your Business Grow?
How Can Hiring A Mobile App Development Company Help Your Business Grow?How Can Hiring A Mobile App Development Company Help Your Business Grow?
How Can Hiring A Mobile App Development Company Help Your Business Grow?
ToXSL Technologies
 
All you need to know about Spring Boot and GraalVM
All you need to know about Spring Boot and GraalVMAll you need to know about Spring Boot and GraalVM
All you need to know about Spring Boot and GraalVM
Alina Yurenko
 
Hand Rolled Applicative User Validation Code Kata
Hand Rolled Applicative User ValidationCode KataHand Rolled Applicative User ValidationCode Kata
Hand Rolled Applicative User Validation Code Kata
Philip Schwarz
 
Requirement Traceability in Xen Functional Safety
Requirement Traceability in Xen Functional SafetyRequirement Traceability in Xen Functional Safety
Requirement Traceability in Xen Functional Safety
Ayan Halder
 
Top 9 Trends in Cybersecurity for 2024.pptx
Top 9 Trends in Cybersecurity for 2024.pptxTop 9 Trends in Cybersecurity for 2024.pptx
Top 9 Trends in Cybersecurity for 2024.pptx
devvsandy
 
E-commerce Development Services- Hornet Dynamics
E-commerce Development Services- Hornet DynamicsE-commerce Development Services- Hornet Dynamics
E-commerce Development Services- Hornet Dynamics
Hornet Dynamics
 
Top Benefits of Using Salesforce Healthcare CRM for Patient Management.pdf
Top Benefits of Using Salesforce Healthcare CRM for Patient Management.pdfTop Benefits of Using Salesforce Healthcare CRM for Patient Management.pdf
Top Benefits of Using Salesforce Healthcare CRM for Patient Management.pdf
VALiNTRY360
 
Using Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional SafetyUsing Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional Safety
Ayan Halder
 

Recently uploaded (20)

Enums On Steroids - let's look at sealed classes !
Enums On Steroids - let's look at sealed classes !Enums On Steroids - let's look at sealed classes !
Enums On Steroids - let's look at sealed classes !
 
Transform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR SolutionsTransform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR Solutions
 
Microservice Teams - How the cloud changes the way we work
Microservice Teams - How the cloud changes the way we workMicroservice Teams - How the cloud changes the way we work
Microservice Teams - How the cloud changes the way we work
 
Measures in SQL (SIGMOD 2024, Santiago, Chile)
Measures in SQL (SIGMOD 2024, Santiago, Chile)Measures in SQL (SIGMOD 2024, Santiago, Chile)
Measures in SQL (SIGMOD 2024, Santiago, Chile)
 
一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理
一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理
一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理
 
Malibou Pitch Deck For Its €3M Seed Round
Malibou Pitch Deck For Its €3M Seed RoundMalibou Pitch Deck For Its €3M Seed Round
Malibou Pitch Deck For Its €3M Seed Round
 
Fundamentals of Programming and Language Processors
Fundamentals of Programming and Language ProcessorsFundamentals of Programming and Language Processors
Fundamentals of Programming and Language Processors
 
Mobile app Development Services | Drona Infotech
Mobile app Development Services  | Drona InfotechMobile app Development Services  | Drona Infotech
Mobile app Development Services | Drona Infotech
 
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
 
Oracle 23c New Features For DBAs and Developers.pptx
Oracle 23c New Features For DBAs and Developers.pptxOracle 23c New Features For DBAs and Developers.pptx
Oracle 23c New Features For DBAs and Developers.pptx
 
What next after learning python programming basics
What next after learning python programming basicsWhat next after learning python programming basics
What next after learning python programming basics
 
ALGIT - Assembly Line for Green IT - Numbers, Data, Facts
ALGIT - Assembly Line for Green IT - Numbers, Data, FactsALGIT - Assembly Line for Green IT - Numbers, Data, Facts
ALGIT - Assembly Line for Green IT - Numbers, Data, Facts
 
How Can Hiring A Mobile App Development Company Help Your Business Grow?
How Can Hiring A Mobile App Development Company Help Your Business Grow?How Can Hiring A Mobile App Development Company Help Your Business Grow?
How Can Hiring A Mobile App Development Company Help Your Business Grow?
 
All you need to know about Spring Boot and GraalVM
All you need to know about Spring Boot and GraalVMAll you need to know about Spring Boot and GraalVM
All you need to know about Spring Boot and GraalVM
 
Hand Rolled Applicative User Validation Code Kata
Hand Rolled Applicative User ValidationCode KataHand Rolled Applicative User ValidationCode Kata
Hand Rolled Applicative User Validation Code Kata
 
Requirement Traceability in Xen Functional Safety
Requirement Traceability in Xen Functional SafetyRequirement Traceability in Xen Functional Safety
Requirement Traceability in Xen Functional Safety
 
Top 9 Trends in Cybersecurity for 2024.pptx
Top 9 Trends in Cybersecurity for 2024.pptxTop 9 Trends in Cybersecurity for 2024.pptx
Top 9 Trends in Cybersecurity for 2024.pptx
 
E-commerce Development Services- Hornet Dynamics
E-commerce Development Services- Hornet DynamicsE-commerce Development Services- Hornet Dynamics
E-commerce Development Services- Hornet Dynamics
 
Top Benefits of Using Salesforce Healthcare CRM for Patient Management.pdf
Top Benefits of Using Salesforce Healthcare CRM for Patient Management.pdfTop Benefits of Using Salesforce Healthcare CRM for Patient Management.pdf
Top Benefits of Using Salesforce Healthcare CRM for Patient Management.pdf
 
Using Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional SafetyUsing Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional Safety
 

Java - Remote method invocation

  • 1. REMOTE METHOD INVOCATION PROGRAMMAZIONE CONCORRENTE E DISTR. Università degli Studi di Padova Dipartimento di Matematica Corso di Laurea in Informatica, A.A. 2015 – 2016 rcardin@math.unipd.it
  • 2. Programmazione concorrente e distribuita SUMMARY  Introduction  Remote interfaces  Dynamic code loading  Serialization  Security manager  Exporting remote objects  Compiling  Running  Distributed garbage collection 2Riccardo Cardin
  • 3. Programmazione concorrente e distribuita INTRODUCTION  RMI allows applications to call object methods located remotely  A server program creates some remote objects  A client program obtains a remote reference and then invokes methods on them  Distributed object application  Sharing resources, processing load across systems  RMI provides mechanism by which the server and the client communicate  Using low level communication (i.e. sockets) is harder and less performing  Serialization has a cost and its difficult to share some state 3Riccardo Cardin
  • 4. Programmazione concorrente e distribuita INTRODUCTION  Distributed object applications need to do the following  Locate remote objects  Application can register its remote objects with RMI's simple naming facility, the RMI registry  Communicate with remote objects  Details of communication between remote objects are handled by RMI  Load class definitions for objects that are passed around  RMI provides mechanisms for loading an object's class definitions as well as for transmitting an object's data 4Riccardo Cardin
  • 5. Programmazione concorrente e distribuita INTRODUCTION 5Riccardo Cardin 1 2 3 4 5 6 Client side Server side
  • 6. Programmazione concorrente e distribuita CREATING DISTRIBUTED APPLICATIONS  Developing a distributed application using RMI involves these general steps:  Designing and implementing the components  Defining the remote interfaces  Implementing the remote objects  Implementing the clients  Compiling sources  Making classes network accessible  Typically a web server is used for this purpose  Starting the application  Registry, server, client, ... 6Riccardo Cardin
  • 7. Programmazione concorrente e distribuita CREATING DISTRIBUTED APPLICATIONS 7Riccardo Cardin
  • 8. Programmazione concorrente e distribuita REMOTE INTERFACES  Distributed application are made up of remote interfaces and classes  Objects with methods that can be invoked across Java virtual machines are called remote objects.  A remote interfaces has the following characteristics  Extends the interface java.rmi.Remote  Each method of the interface declares java.rmi.RemoteException in its throws clause  Remote objects are treated like an object reference  A local representation (remote stub) is sent to other JVMs  Implementation of the Remote proxy pattern  Any other object is copied before being sent 8Riccardo Cardin
  • 9. Programmazione concorrente e distribuita REMOTE INTERFACES  Each interface defines a specific protocol  It’s important to clearly separate methods’ interfaces from their implementation  Methods of an interface that extends Remote can be invoked from another JVM  Remote methods MUST throw a RemoteException  A checked exception used to indicate either a communication failure or a protocol error  Remote interfaces are defined server side 9Riccardo Cardin // The interface implements java.rmi.Remote and its unique method // throws a java.rmi.RemoteException public interface Compute extends Remote { <T> T executeTask(Task<T> t) throws RemoteException; }
  • 10. Programmazione concorrente e distribuita REMOTE INTERFACES  A remote interface must be implemented  The implementing class can declare more methods, but these will not be seen by the clients  Parameters of remote methods follow these rules:  Remote objects are passed by reference. Changes made remotely are reflected in the original remote object  A stub is a proxy to the remote object that communicates with the original remote object  Local objects are passed by copy, using serialization  Changes are not propagated back in any way 10Riccardo Cardin public class ComputeEngine implements Compute { // Implement at least remote methods }
  • 11. Programmazione concorrente e distribuita REMOTE INTERFACES 11Riccardo Cardin
  • 12. Programmazione concorrente e distribuita DYNAMIC CODE LOADING  Interfaces that are not marked as remote must be serializable  Type that are not marked as remote are passed by copy, using serialization  Use java.io.Serializable has a marked interface  The implementation will be dinamically downloaded by RMI into the host JVM  This is possibile beacuse all objects are written in Java 12Riccardo Cardin // This is not a remote intefaces, but it is used in the protocol // defined by a remote method. It’s implementation must implement // also the Serializable interface public interface Task<T> { T execute(); }
  • 13. Programmazione concorrente e distribuita SERIALIZATION  Representation of an object as a sequence of bytes, that includes data as well as type  The process is JVM independent  Serialization process uses the stream API  ObjectInputStream and ObjectOutputStream types  Deserialization is the opposite process  The type must implement java.io.Serializable  All fields in the class must be serializable. If a field is not, it must be marked as transient  Transient fields are not serialized and are lost intentionally  A transient variable cannot be final or static  Serialization is used by RMI, EJB and so on 13Riccardo Cardin
  • 14. Programmazione concorrente e distribuita SECURITY MANAGER  Defines the outer boundaries of the sandbox for downloaded (untrusted) code  It descends from class java.lang.SecurityManager  Security policies specify actions that are unsafe  Accept or open a socket from/to a host and port  Modify a thread (change its priority, ...)  Interact with file system  Interact with system properties  Exit an application  For every unsafe action there is a corresponding checkXXX method  Actions not allowed throw a SecurityException 14Riccardo Cardin
  • 15. Programmazione concorrente e distribuita SECURITY MANAGER  RMI programs must install a security manager  Otherwise RMI will not download classes  Only one security manager can be installed  By default, an application has no security manager installed  Policies are specified using *.policy files  Server and client application must specify their policy file  Default file: java.home/lib/security/java.policy  Use -Djava.security.policy property specify a file 15Riccardo Cardin if (System.getSecurityManager() == null) { System.setSecurityManager(new SecurityManager()); } grant codeBase "file:/home/ann/src/" { permission java.security.AllPermission; };
  • 16. Programmazione concorrente e distribuita SECURITY MANAGER 16Riccardo Cardin
  • 17. Programmazione concorrente e distribuita EXPORTING REMOTE OBJECTS  Remote objects need to be exported to the RMI runtime  Exporting means create stub objects that expose the remote methods to clients  Stub is the client placeholder for the remote object  The stub implements the remote interface  It is a remote proxy to the remote object  2° arg to exportObject is the listening port for incoming connection 17Riccardo Cardin Compute engine = new ComputeEngine(); // Listening to port 0 means to listen on every port Compute stub = (Compute) UnicastRemoteObject.exportObject(engine, 0);
  • 18. Programmazione concorrente e distribuita EXPORTING REMOTE OBJECTS 18Riccardo Cardin
  • 19. Programmazione concorrente e distribuita EXPORTING REMOTE OBJECTS  RMI Registry: a remote map for other remote objects, indexed by names  The server register a remote object (stub), the client retrieve it using the same name  The java.rmi.Naming type provides methods for storing and obtaining references to remote objects  Available methods are bind, unbind and rebind  The name argument specifies the host and port of the registry  The object represents the remote object (stub) to expose to clients 19Riccardo Cardin // Name is a string that represents an URL without the scheme // //host:port/name Naming.bind(name, object)
  • 20. Programmazione concorrente e distribuita EXPORTING REMOTE OBJECTS  RMI Registry  The creation and lookup of a new Registry can be done using the type LocateRegistry  A registry is a remote object binded to a fixed name  This type offers also an API to interact with the registry  For security reasons, an application can bind an object with a registry running on the same host  Using the lookup method, a client can retrieve a stub 20Riccardo Cardin // Retrieves the default registry listening on port 1099 Registry registry = LocateRegistry.getRegistry(); // Asks the registry to bind a stub to a name registry.rebind(name, stub); // The name was the same used to bind the object Compute comp = (Compute) registry.lookup(name);
  • 21. Programmazione concorrente e distribuita EXPORTING REMOTE OBJECTS 21Riccardo Cardin A client looks up from the RMI registry a stub binded to a name A server bind a stub to a specific name in a RMI registry The client calls remote methods, passing serializable type as arguments 1 2 3
  • 22. Programmazione concorrente e distribuita COMPILING  Compilation of an RMI program requires a series of different steps  Create an archive (JAR) with remote interfaces  This archive will be shared across server and clients  The above jar needs to be shared with the registry  Definitions that can be automatically downloaded have to be placed in a public folder  For example, use an HTTP web server for this purpose  Build server classes 22Riccardo Cardin javac compute/Compute.java compute/Task.java jar cvf compute.jar compute/*.class javac -cp c:homeannpublic_htmlclassescompute.jar engineComputeEngine.java
  • 23. Programmazione concorrente e distribuita COMPILING  Compilation of an RMI program requires a series of different steps  Build client classes  The Task interface needs to be public accessible  The client needs also the jar of remote interfaces  Defining security policies for server and clients  Create a *.policy file for each actor, specifying which actions are allowed to be performed by the downloaded code 23Riccardo Cardin javac -cp /home/jones/public_html/classes/compute.jar client/ComputePi.java client/Pi.java cp client/Pi.class /home/jones/public_html/classes/client grant codeBase "file:/home/ann/src/" { permission java.security.AllPermission; };
  • 24. Programmazione concorrente e distribuita RUNNING  Starting the server components  Start the RMI registry, given with the JDK platform  Start the server program  Use java.rmi.server.codebase to specify the location of remote interfaces archive  Use java.rmi.server.hostname to specify the host for stubs exported from the server JVM  By default RMI uses the the IP address of the host  Use java.security.policy to specify the policy file 24Riccardo Cardin start rmiregistry 1099 :: By default the registry run on port 1099 java -cp c:homeannsrc;c:classescompute.jar -Djava.rmi.server.codebase= file:/c:/classes/compute.jar -Djava.rmi.server.hostname=mycomputer.example.com -Djava.security.policy=server.policy engine.ComputeEngine
  • 25. Programmazione concorrente e distribuita RUNNING  Starting the client component  Start the client program  Use java.rmi.server.codebase to specify the location of client’s interfaces implementation  Use java.security.policy to specify the policy file  The host name of the server can be supplied as an argument of the program 25Riccardo Cardin java -cp c:homejonessrc;c:classescompute.jar -Djava.rmi.server.codebase=file:/c:/classes/ -Djava.security.policy=client.policy client.ComputePi mycomputer.example.com 45
  • 26. Programmazione concorrente e distribuita RUNNING 26Riccardo Cardin The registry search the stub implementation into the web server The implementation of client interfaces are loaded by the server from the public codebase
  • 27. Programmazione concorrente e distribuita RUNNING 27Riccardo Cardin
  • 28. Programmazione concorrente e distribuita DISTRIBUTED GARBAGE COLLECTION  RMI uses a reference-counting algorithm  Keeps track of all live references within each JVM  The first reference to a remote object sends a “referenced” message to the server for that object. Reference count is incremented  As live references are found to be unreferenced in local JVM, the count is decremented. When the last reference has been discarded, an unreferenced message is sent  When a remote object is not referenced by any client, the RMI runtime refers to it using a weak reference  Due to connection delays, it is possible that premature collection of remote object will occur  A reference to this object will thrown a RemoteException 28Riccardo Cardin
  • 29. Programmazione concorrente e distribuita EXAMPLES 29Riccardo Cardin https://github.com/rcardin/pcd-snippets
  • 30. Programmazione concorrente e distribuita REFERENCES  The Java Tutorials: RMI https://docs.oracle.com/javase/tutorial/rmi/  The Java Tutorials: Security Manager https://docs.oracle.com/javase/tutorial/essential/environment/sec urity.html  Java security: How to install the security manager and customize your security policy http://www.javaworld.com/article/2077067/core-java/java- security---how-to-install-the-security-manager-and-customize-your- security-policy.html  Default Policy Implementation and Policy File Syntax http://docs.oracle.com/javase/7/docs/technotes/guides/security/P olicyFiles.html 30Riccardo Cardin
  • 31. Programmazione concorrente e distribuita REFERENCES  Java RMI : What is the role of the stub-skeleton that are generated by the rmic compiler http://stackoverflow.com/questions/16886889/java-rmi-what-is- the-role-of-the-stub-skeleton-that-are-generated-by-the-rmic  Java – Serialization http://www.tutorialspoint.com/java/java_serialization.htm  Garbage Collection of Remote Objects https://docs.oracle.com/javase/8/docs/platform/rmi/spec/rmi- arch4.html 31Riccardo Cardin