SlideShare a Scribd company logo
1 of 28
Remote Method Invocation
Prof. Dr. Ralf Lämmel
Universität Koblenz-Landau
Software Languages Team
https://github.com/101companies/101repo/tree/master/languages/AspectJ/javaRmiSamples
Non-101samples available here:
http://101companies.org/wiki/
Contribution:javaRmi
(C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable)
Elevator speech
What if the objects of interests are no longer located on the same
computer, i.e., the objects are distributed instead? How to
communicate between different computers in an OOP-friendly
manner? Basically, we want to continue to hold references to
objects (perhaps remote objects), and send them messages (i.e.,
perform method calls) as before.
We will be looking into Java RMI as a
technology of choice. Alternative options
include Corba, WebServices, and SOA.
(C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable)
Non-distributed programming
Caller and callee are on the same machine.
MyMachine MyMachine
Object1
(Client)
Object2
(Server)
Method Invocation
- Arguments are evaluated.
- Caller location is pushed onto stack.
- Callee method is executed.
- Result is returned.
- Caller location resumes.
(C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable)
Distributed programming
Caller and callee are on different machines.
Host mymac.foo.edu Host myserver.bar.edu
Object1
(Client) Remote
Method Invocation
Client holds on a server proxy.
Args + result go over the network.
In demo code, client and server may be on the same machine, perhaps even on the
same JVM, but the invocation is handled (conceptually) over the network.
Object2
(Server)
(C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable)
See package “helloworld” of javaRmiSamples (see 1st slide).
Start the server as described in “Makefile”.
Start the client by running the “Client” class.
Observe how 42 was remotely incremented.
DEMO
A first look at the
“hello world” of RMI
(C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable)
A more interesting scenario: a banking
application to access account data remotely
at a teller (ATM).
Host koblenz1.db.de Host server.db.de
Teller Bank
Customer
Account
(C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable)
Communication between different Java runtimes on the same
machine or different machines, eventually involves the network
layer of the OS.
JRE JRE
Host OS
Network layer
JRE JRE
Host OS
Network layer
network cable
(C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable)
Stubs and skeletons
• Client invokes a remote method on “stub” object.
• The stub sends the call to the server-side “skeleton”.
• That is, the stub:
– opens a socket to the remote server,
– marshals the method parameters,
– forwards the data stream to the skeleton,
– awaits and unmarshals result data stream from skeleton.
• The skeleton contains a method that:
– receives the remote calls,
– unmarshals the method parameters,
– invokes the actual remote (by now, local) implementation, and
– marshals the result and delivers it back to the stub.
(C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable)
Remote-method invocation
Host mymac.foo.edu Host myserver.bar.edu
Object1
(Client) Object2
(Server)
Remote
Object
Stub:
serves as
Remote
Reference
odd(3) 01101 odd(3)
true10010true
Same interface as
remote object
Serialized method
name, parameters and
return value
Remote
Object
Skeleton
(C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable)
Parameters and return values
Remote objects – by reference
Serializable objects – by copy
Others – cannot be passed (exception)
(C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable)
How to refer to / look up
remote objects?
Remote
Object
C
Remote
Object
A
Remote
Object
B
Naming
“X”
“Y”
“Z”
Host myserver.bar.edu
We need a naming service!
A server-side directory that
associates remote objects
with names (URLs)
(C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable)
Naming service cont’d
Host mymac.foo.edu Host myserver.bar.edu
ObjectY
Naming
“X”
“Y”
“Z”
lookup(“Y”)
Remote reference
to server
(C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable)
Designing a client/server app
(Summary)
Server
Bind 1+ “service” objects via registry
Client
Looks up and interacts with service objects
For example (see “helloworld” demo):
Service: increment operation
(C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable)
Designing a client/server app
(Detailed steps)
1. Design an interface for service (remote object).
2. Implement the service.
3. (Generate stub and skeleton classes.)
4. Implement a server to contact for binding.
5. Implement a client to invoke service.
6. Start the server.
7. Run the client.
Done
automatically.
(C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable)
Step 1:
Design an interface for service (remote object).
import java.rmi.Remote;
import java.rmi.RemoteException;
public interface Service extends Remote {
public long inc(long x)
throws RemoteException;
}
This is a regular interface except for the
special base interface and the special
throws declaration.
(C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable)
Step 2:
Implement the service.
import java.rmi.server.UnicastRemoteObject;
import java.rmi.RemoteException;
public class ServiceImpl
extends UnicastRemoteObject
implements Service {
// Needed for serialization
private static final long serialVersionUID = 6102178242852627613L;
// Needed because of exception
public ServiceImpl() throws RemoteException {
super();
}
public long inc(long x) throws RemoteException {
return ++x;
}
}
(C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable)
Step 4:
Implement a server to contact for binding.
import java.rmi.Naming;
public class Server {
public Server() {
try {
Service s = new ServiceImpl();
Naming.rebind("rmi://localhost/Service", s);
} catch (Exception e) {
System.out.println("Trouble: " + e);
}
}
public static void main(String args[]) {
new Server();
}
}
Remote
object
Register with
naming service
(C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable)
Name format for binding
rmi://<host_name>
[:<name_service_port>]
/<service_name>
Thus, URLs of a specific form are used for
addressing remote objects.
(C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable)
Availability of registry
• Binding requires that the registry is locally running.
• Registry can be started programmatically as follows:
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
LocateRegistry.createRegistry(Registry.REGISTRY_PORT);
• Default TCP/IP port: 1099
(C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable)
Usage of “localhost”
• localhost may fail to work in binding.
• This depends on the network configuration.
• Alternatively, one can use the following idiom:
InetAddress addr = InetAddress.getLocalHost();
String hostname = addr.getHostName();
Naming.rebind("rmi://"+hostname+"/Service", s);
(C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable)
Step 5:
Implement a client to invoke service.
import java.rmi.Naming;
public class Client {
public static void main(String[] args) {
try {
Service s = (Service) Naming.lookup("rmi://localhost/Service");
System.out.println(s.inc(41));
} catch (Exception e) {
...
}
}
}
(C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable)
Step 6:
Start the server.
JavaRmi> java helloworld.Server
Server must be
killed, e.g., with
CTRL-C
One may want to run
the server (and the
client) with a security
policy.
If you are using Eclipse,
you cannot (easily) run
both server and client
simultaneously from
within Eclipse. One of the
two would be started
from the command line.
(C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable)
Step 7:
Run the client.
JavaRmi> java helloworld.Client
42
(C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable)
Components
of an RMI-based application
• Services of remote objects (interfaces)
• Implementation of services (classes)
• Proxies for client-side (classes, generated)
• A server that binds services (class)
• A client that looks up services (class)
• The RMI registry (component of RMI layer)
• Security policies for client and server (optional)
(C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable)
Security of RMI
• Useful constrains:
– Service provision (“May an app provide services?”)
– Naming lookups (“May an IP address look up services?”)
– Remote invocations (“May an IP address invoke ...?”)
• Use a non-default security manager:
System.setSecurityManager(new SecurityManager());
• Assign a security policy to an application:
java -Djava.security.policy=mySecurity.policy Server
(C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable)
– A non-C/S-based version as a reference: package “banking.local”.
– The C/S-based version: package “banking.remote”.
– Think of a refactoring to derive the latter from the former.
DEMO
An RMI-based banking app
(C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable)
DEMO
http://101companies.org/wiki/
Contribution:javaRmi
This implementation is interesting in so far that it readies all
data objects for RMI. Further, the operation “total” is provided
as a service, but “cut” is not. Thus, the client must implement
“cut”, which essentially means that all company, department,
and employee objects end up as proxies on the client.
(C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable)
Summary
• RMI easily blends with OOP.
– A simple form of distributed programming is enabled this way.
– Client/Server applications are enabled this way.
• RMI – semantics and concepts:
– Use local proxy objects for access to remote objects.
– Un-/marshal arguments and results for messages on the wire.
– Bind objects to names (URLs) that can be used for lookup.
• RMI – programming idioms:
– Remote objects are looked up from server-side registry.
– Remote objects may also be returned by RMI calls.
– Remote objects may be created by factory methods.
• Omissions:
– Multiplicity of clients
– Other distribution technologies: Corba, WebServices, SOA, HTTP, ...

More Related Content

Viewers also liked

Remote Method Invocation
Remote Method InvocationRemote Method Invocation
Remote Method Invocationelliando dias
 
Remote method invocation
Remote method invocationRemote method invocation
Remote method invocationDew Shishir
 
Inter-Process communication using pipe in FPGA based adaptive communication
Inter-Process communication using pipe in FPGA based adaptive communicationInter-Process communication using pipe in FPGA based adaptive communication
Inter-Process communication using pipe in FPGA based adaptive communicationMayur Shah
 
Introduction to C++ Remote Procedure Call (RPC)
Introduction to C++ Remote Procedure Call (RPC)Introduction to C++ Remote Procedure Call (RPC)
Introduction to C++ Remote Procedure Call (RPC)Abdelrahman Al-Ogail
 
RPC: Remote procedure call
RPC: Remote procedure callRPC: Remote procedure call
RPC: Remote procedure callSunita Sahu
 
Introduction to Remote Method Invocation (RMI)
Introduction to Remote Method Invocation (RMI)Introduction to Remote Method Invocation (RMI)
Introduction to Remote Method Invocation (RMI)eLink Business Innovations
 
Chapter 4 a interprocess communication
Chapter 4 a interprocess communicationChapter 4 a interprocess communication
Chapter 4 a interprocess communicationAbDul ThaYyal
 
Java RMI Presentation
Java RMI PresentationJava RMI Presentation
Java RMI PresentationMasud Rahman
 
remote procedure calls
  remote procedure calls  remote procedure calls
remote procedure callsAshish Kumar
 
Java rmi example program with code
Java rmi example program with codeJava rmi example program with code
Java rmi example program with codekamal kotecha
 
Piping Training course-How to be an Expert in Pipe & Fittings for Oil & Gas c...
Piping Training course-How to be an Expert in Pipe & Fittings for Oil & Gas c...Piping Training course-How to be an Expert in Pipe & Fittings for Oil & Gas c...
Piping Training course-How to be an Expert in Pipe & Fittings for Oil & Gas c...Varun Patel
 
Java - Remote method invocation
Java - Remote method invocationJava - Remote method invocation
Java - Remote method invocationRiccardo Cardin
 

Viewers also liked (17)

Remote Method Invocation
Remote Method InvocationRemote Method Invocation
Remote Method Invocation
 
Remote method invocation
Remote method invocationRemote method invocation
Remote method invocation
 
Inter-Process communication using pipe in FPGA based adaptive communication
Inter-Process communication using pipe in FPGA based adaptive communicationInter-Process communication using pipe in FPGA based adaptive communication
Inter-Process communication using pipe in FPGA based adaptive communication
 
Introduction to C++ Remote Procedure Call (RPC)
Introduction to C++ Remote Procedure Call (RPC)Introduction to C++ Remote Procedure Call (RPC)
Introduction to C++ Remote Procedure Call (RPC)
 
Java rmi
Java rmiJava rmi
Java rmi
 
RPC: Remote procedure call
RPC: Remote procedure callRPC: Remote procedure call
RPC: Remote procedure call
 
RMI
RMIRMI
RMI
 
Introduction to Remote Method Invocation (RMI)
Introduction to Remote Method Invocation (RMI)Introduction to Remote Method Invocation (RMI)
Introduction to Remote Method Invocation (RMI)
 
Java rmi
Java rmiJava rmi
Java rmi
 
Socket System Calls
Socket System CallsSocket System Calls
Socket System Calls
 
Chapter 4 a interprocess communication
Chapter 4 a interprocess communicationChapter 4 a interprocess communication
Chapter 4 a interprocess communication
 
Java RMI Presentation
Java RMI PresentationJava RMI Presentation
Java RMI Presentation
 
Network Sockets
Network SocketsNetwork Sockets
Network Sockets
 
remote procedure calls
  remote procedure calls  remote procedure calls
remote procedure calls
 
Java rmi example program with code
Java rmi example program with codeJava rmi example program with code
Java rmi example program with code
 
Piping Training course-How to be an Expert in Pipe & Fittings for Oil & Gas c...
Piping Training course-How to be an Expert in Pipe & Fittings for Oil & Gas c...Piping Training course-How to be an Expert in Pipe & Fittings for Oil & Gas c...
Piping Training course-How to be an Expert in Pipe & Fittings for Oil & Gas c...
 
Java - Remote method invocation
Java - Remote method invocationJava - Remote method invocation
Java - Remote method invocation
 

Similar to Remote method invocation (as part of the the PTT lecture)

Running Accurate, Scalable, and Reproducible Simulations of Distributed Syste...
Running Accurate, Scalable, and Reproducible Simulations of Distributed Syste...Running Accurate, Scalable, and Reproducible Simulations of Distributed Syste...
Running Accurate, Scalable, and Reproducible Simulations of Distributed Syste...Rafael Ferreira da Silva
 
Selected design patterns (as part of the the PTT lecture)
Selected design patterns (as part of the the PTT lecture)Selected design patterns (as part of the the PTT lecture)
Selected design patterns (as part of the the PTT lecture)Ralf Laemmel
 
Javarmi 130925082348-phpapp01
Javarmi 130925082348-phpapp01Javarmi 130925082348-phpapp01
Javarmi 130925082348-phpapp01heenamithadiya
 
Metaprograms and metadata (as part of the the PTT lecture)
Metaprograms and metadata (as part of the the PTT lecture)Metaprograms and metadata (as part of the the PTT lecture)
Metaprograms and metadata (as part of the the PTT lecture)Ralf Laemmel
 
Remote Method Invocation in JAVA
Remote Method Invocation in JAVARemote Method Invocation in JAVA
Remote Method Invocation in JAVAJalpesh Vasa
 
Report on mini project(Student database handling using RMI)
Report on mini project(Student database handling using RMI)Report on mini project(Student database handling using RMI)
Report on mini project(Student database handling using RMI)shraddha mane
 
Distributed Programming using RMI
 Distributed Programming using RMI Distributed Programming using RMI
Distributed Programming using RMIbackdoor
 
Distributed Programming using RMI
Distributed Programming using RMIDistributed Programming using RMI
Distributed Programming using RMIbackdoor
 
Remote Method Invocation
Remote Method InvocationRemote Method Invocation
Remote Method InvocationSonali Parab
 
Remote Method Invocation
Remote Method InvocationRemote Method Invocation
Remote Method Invocationashishspace
 
Node.js Patterns for Discerning Developers
Node.js Patterns for Discerning DevelopersNode.js Patterns for Discerning Developers
Node.js Patterns for Discerning Developerscacois
 
Communication middleware
Communication middlewareCommunication middleware
Communication middlewarePeter R. Egli
 
Building Machine Learning Applications with Sparkling Water
Building Machine Learning Applications with Sparkling WaterBuilding Machine Learning Applications with Sparkling Water
Building Machine Learning Applications with Sparkling WaterSri Ambati
 
Rpc, Rmi And Webservices 2
Rpc, Rmi And Webservices 2Rpc, Rmi And Webservices 2
Rpc, Rmi And Webservices 2groupe0D
 
Comparison between-rpc-rmi-and-webservices-son-1228374226080667-8
Comparison between-rpc-rmi-and-webservices-son-1228374226080667-8Comparison between-rpc-rmi-and-webservices-son-1228374226080667-8
Comparison between-rpc-rmi-and-webservices-son-1228374226080667-8helpsoft01
 
#4 (Remote Method Invocation)
#4 (Remote Method Invocation)#4 (Remote Method Invocation)
#4 (Remote Method Invocation)Ghadeer AlHasan
 

Similar to Remote method invocation (as part of the the PTT lecture) (20)

Running Accurate, Scalable, and Reproducible Simulations of Distributed Syste...
Running Accurate, Scalable, and Reproducible Simulations of Distributed Syste...Running Accurate, Scalable, and Reproducible Simulations of Distributed Syste...
Running Accurate, Scalable, and Reproducible Simulations of Distributed Syste...
 
Selected design patterns (as part of the the PTT lecture)
Selected design patterns (as part of the the PTT lecture)Selected design patterns (as part of the the PTT lecture)
Selected design patterns (as part of the the PTT lecture)
 
Javarmi 130925082348-phpapp01
Javarmi 130925082348-phpapp01Javarmi 130925082348-phpapp01
Javarmi 130925082348-phpapp01
 
Metaprograms and metadata (as part of the the PTT lecture)
Metaprograms and metadata (as part of the the PTT lecture)Metaprograms and metadata (as part of the the PTT lecture)
Metaprograms and metadata (as part of the the PTT lecture)
 
XML data binding
XML data bindingXML data binding
XML data binding
 
Remote Method Invocation in JAVA
Remote Method Invocation in JAVARemote Method Invocation in JAVA
Remote Method Invocation in JAVA
 
RMI (Remote Method Invocation)
RMI (Remote Method Invocation)RMI (Remote Method Invocation)
RMI (Remote Method Invocation)
 
Report on mini project(Student database handling using RMI)
Report on mini project(Student database handling using RMI)Report on mini project(Student database handling using RMI)
Report on mini project(Student database handling using RMI)
 
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
Remote Method InvocationRemote Method Invocation
Remote Method Invocation
 
Remote Method Invocation
Remote Method InvocationRemote Method Invocation
Remote Method Invocation
 
Node.js Patterns for Discerning Developers
Node.js Patterns for Discerning DevelopersNode.js Patterns for Discerning Developers
Node.js Patterns for Discerning Developers
 
Communication middleware
Communication middlewareCommunication middleware
Communication middleware
 
Building Machine Learning Applications with Sparkling Water
Building Machine Learning Applications with Sparkling WaterBuilding Machine Learning Applications with Sparkling Water
Building Machine Learning Applications with Sparkling Water
 
Rpc, Rmi And Webservices 2
Rpc, Rmi And Webservices 2Rpc, Rmi And Webservices 2
Rpc, Rmi And Webservices 2
 
Comparison between-rpc-rmi-and-webservices-son-1228374226080667-8
Comparison between-rpc-rmi-and-webservices-son-1228374226080667-8Comparison between-rpc-rmi-and-webservices-son-1228374226080667-8
Comparison between-rpc-rmi-and-webservices-son-1228374226080667-8
 
Java RMI
Java RMIJava RMI
Java RMI
 
soap toolkit
soap toolkitsoap toolkit
soap toolkit
 
#4 (Remote Method Invocation)
#4 (Remote Method Invocation)#4 (Remote Method Invocation)
#4 (Remote Method Invocation)
 

More from Ralf Laemmel

Keynote at-icpc-2020
Keynote at-icpc-2020Keynote at-icpc-2020
Keynote at-icpc-2020Ralf Laemmel
 
Functional data structures
Functional data structuresFunctional data structures
Functional data structuresRalf Laemmel
 
Modeling software systems at a macroscopic scale
Modeling software systems  at a macroscopic scaleModeling software systems  at a macroscopic scale
Modeling software systems at a macroscopic scaleRalf Laemmel
 
An introduction on language processing
An introduction on language processingAn introduction on language processing
An introduction on language processingRalf Laemmel
 
Surfacing ‘101’ in a Linked Data manner as presented at SATToSE 2013
Surfacing ‘101’ in a Linked Data manner as presented at SATToSE 2013Surfacing ‘101’ in a Linked Data manner as presented at SATToSE 2013
Surfacing ‘101’ in a Linked Data manner as presented at SATToSE 2013Ralf Laemmel
 
Database programming including O/R mapping (as part of the the PTT lecture)
Database programming including O/R mapping (as part of the the PTT lecture)Database programming including O/R mapping (as part of the the PTT lecture)
Database programming including O/R mapping (as part of the the PTT lecture)Ralf Laemmel
 
Multithreaded programming (as part of the the PTT lecture)
Multithreaded programming (as part of the the PTT lecture)Multithreaded programming (as part of the the PTT lecture)
Multithreaded programming (as part of the the PTT lecture)Ralf Laemmel
 
Functional OO programming (as part of the the PTT lecture)
Functional OO programming (as part of the the PTT lecture)Functional OO programming (as part of the the PTT lecture)
Functional OO programming (as part of the the PTT lecture)Ralf Laemmel
 
The Expression Problem (as part of the the PTT lecture)
The Expression Problem (as part of the the PTT lecture)The Expression Problem (as part of the the PTT lecture)
The Expression Problem (as part of the the PTT lecture)Ralf Laemmel
 

More from Ralf Laemmel (9)

Keynote at-icpc-2020
Keynote at-icpc-2020Keynote at-icpc-2020
Keynote at-icpc-2020
 
Functional data structures
Functional data structuresFunctional data structures
Functional data structures
 
Modeling software systems at a macroscopic scale
Modeling software systems  at a macroscopic scaleModeling software systems  at a macroscopic scale
Modeling software systems at a macroscopic scale
 
An introduction on language processing
An introduction on language processingAn introduction on language processing
An introduction on language processing
 
Surfacing ‘101’ in a Linked Data manner as presented at SATToSE 2013
Surfacing ‘101’ in a Linked Data manner as presented at SATToSE 2013Surfacing ‘101’ in a Linked Data manner as presented at SATToSE 2013
Surfacing ‘101’ in a Linked Data manner as presented at SATToSE 2013
 
Database programming including O/R mapping (as part of the the PTT lecture)
Database programming including O/R mapping (as part of the the PTT lecture)Database programming including O/R mapping (as part of the the PTT lecture)
Database programming including O/R mapping (as part of the the PTT lecture)
 
Multithreaded programming (as part of the the PTT lecture)
Multithreaded programming (as part of the the PTT lecture)Multithreaded programming (as part of the the PTT lecture)
Multithreaded programming (as part of the the PTT lecture)
 
Functional OO programming (as part of the the PTT lecture)
Functional OO programming (as part of the the PTT lecture)Functional OO programming (as part of the the PTT lecture)
Functional OO programming (as part of the the PTT lecture)
 
The Expression Problem (as part of the the PTT lecture)
The Expression Problem (as part of the the PTT lecture)The Expression Problem (as part of the the PTT lecture)
The Expression Problem (as part of the the PTT lecture)
 

Recently uploaded

Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationKnoldus Inc.
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesThousandEyes
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical InfrastructureVarsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructureitnewsafrica
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Farhan Tariq
 
Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...itnewsafrica
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Mark Goldstein
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality AssuranceInflectra
 
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS:  6 Ways to Automate Your Data IntegrationBridging Between CAD & GIS:  6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integrationmarketing932765
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterMydbops
 
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesMuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesManik S Magar
 
Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Kaya Weers
 
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...itnewsafrica
 

Recently uploaded (20)

Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog Presentation
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical InfrastructureVarsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...
 
Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
 
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS:  6 Ways to Automate Your Data IntegrationBridging Between CAD & GIS:  6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL Router
 
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesMuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
 
Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)
 
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
 

Remote method invocation (as part of the the PTT lecture)

  • 1. Remote Method Invocation Prof. Dr. Ralf Lämmel Universität Koblenz-Landau Software Languages Team https://github.com/101companies/101repo/tree/master/languages/AspectJ/javaRmiSamples Non-101samples available here: http://101companies.org/wiki/ Contribution:javaRmi
  • 2. (C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable) Elevator speech What if the objects of interests are no longer located on the same computer, i.e., the objects are distributed instead? How to communicate between different computers in an OOP-friendly manner? Basically, we want to continue to hold references to objects (perhaps remote objects), and send them messages (i.e., perform method calls) as before. We will be looking into Java RMI as a technology of choice. Alternative options include Corba, WebServices, and SOA.
  • 3. (C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable) Non-distributed programming Caller and callee are on the same machine. MyMachine MyMachine Object1 (Client) Object2 (Server) Method Invocation - Arguments are evaluated. - Caller location is pushed onto stack. - Callee method is executed. - Result is returned. - Caller location resumes.
  • 4. (C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable) Distributed programming Caller and callee are on different machines. Host mymac.foo.edu Host myserver.bar.edu Object1 (Client) Remote Method Invocation Client holds on a server proxy. Args + result go over the network. In demo code, client and server may be on the same machine, perhaps even on the same JVM, but the invocation is handled (conceptually) over the network. Object2 (Server)
  • 5. (C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable) See package “helloworld” of javaRmiSamples (see 1st slide). Start the server as described in “Makefile”. Start the client by running the “Client” class. Observe how 42 was remotely incremented. DEMO A first look at the “hello world” of RMI
  • 6. (C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable) A more interesting scenario: a banking application to access account data remotely at a teller (ATM). Host koblenz1.db.de Host server.db.de Teller Bank Customer Account
  • 7. (C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable) Communication between different Java runtimes on the same machine or different machines, eventually involves the network layer of the OS. JRE JRE Host OS Network layer JRE JRE Host OS Network layer network cable
  • 8. (C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable) Stubs and skeletons • Client invokes a remote method on “stub” object. • The stub sends the call to the server-side “skeleton”. • That is, the stub: – opens a socket to the remote server, – marshals the method parameters, – forwards the data stream to the skeleton, – awaits and unmarshals result data stream from skeleton. • The skeleton contains a method that: – receives the remote calls, – unmarshals the method parameters, – invokes the actual remote (by now, local) implementation, and – marshals the result and delivers it back to the stub.
  • 9. (C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable) Remote-method invocation Host mymac.foo.edu Host myserver.bar.edu Object1 (Client) Object2 (Server) Remote Object Stub: serves as Remote Reference odd(3) 01101 odd(3) true10010true Same interface as remote object Serialized method name, parameters and return value Remote Object Skeleton
  • 10. (C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable) Parameters and return values Remote objects – by reference Serializable objects – by copy Others – cannot be passed (exception)
  • 11. (C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable) How to refer to / look up remote objects? Remote Object C Remote Object A Remote Object B Naming “X” “Y” “Z” Host myserver.bar.edu We need a naming service! A server-side directory that associates remote objects with names (URLs)
  • 12. (C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable) Naming service cont’d Host mymac.foo.edu Host myserver.bar.edu ObjectY Naming “X” “Y” “Z” lookup(“Y”) Remote reference to server
  • 13. (C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable) Designing a client/server app (Summary) Server Bind 1+ “service” objects via registry Client Looks up and interacts with service objects For example (see “helloworld” demo): Service: increment operation
  • 14. (C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable) Designing a client/server app (Detailed steps) 1. Design an interface for service (remote object). 2. Implement the service. 3. (Generate stub and skeleton classes.) 4. Implement a server to contact for binding. 5. Implement a client to invoke service. 6. Start the server. 7. Run the client. Done automatically.
  • 15. (C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable) Step 1: Design an interface for service (remote object). import java.rmi.Remote; import java.rmi.RemoteException; public interface Service extends Remote { public long inc(long x) throws RemoteException; } This is a regular interface except for the special base interface and the special throws declaration.
  • 16. (C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable) Step 2: Implement the service. import java.rmi.server.UnicastRemoteObject; import java.rmi.RemoteException; public class ServiceImpl extends UnicastRemoteObject implements Service { // Needed for serialization private static final long serialVersionUID = 6102178242852627613L; // Needed because of exception public ServiceImpl() throws RemoteException { super(); } public long inc(long x) throws RemoteException { return ++x; } }
  • 17. (C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable) Step 4: Implement a server to contact for binding. import java.rmi.Naming; public class Server { public Server() { try { Service s = new ServiceImpl(); Naming.rebind("rmi://localhost/Service", s); } catch (Exception e) { System.out.println("Trouble: " + e); } } public static void main(String args[]) { new Server(); } } Remote object Register with naming service
  • 18. (C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable) Name format for binding rmi://<host_name> [:<name_service_port>] /<service_name> Thus, URLs of a specific form are used for addressing remote objects.
  • 19. (C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable) Availability of registry • Binding requires that the registry is locally running. • Registry can be started programmatically as follows: import java.rmi.registry.LocateRegistry; import java.rmi.registry.Registry; LocateRegistry.createRegistry(Registry.REGISTRY_PORT); • Default TCP/IP port: 1099
  • 20. (C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable) Usage of “localhost” • localhost may fail to work in binding. • This depends on the network configuration. • Alternatively, one can use the following idiom: InetAddress addr = InetAddress.getLocalHost(); String hostname = addr.getHostName(); Naming.rebind("rmi://"+hostname+"/Service", s);
  • 21. (C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable) Step 5: Implement a client to invoke service. import java.rmi.Naming; public class Client { public static void main(String[] args) { try { Service s = (Service) Naming.lookup("rmi://localhost/Service"); System.out.println(s.inc(41)); } catch (Exception e) { ... } } }
  • 22. (C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable) Step 6: Start the server. JavaRmi> java helloworld.Server Server must be killed, e.g., with CTRL-C One may want to run the server (and the client) with a security policy. If you are using Eclipse, you cannot (easily) run both server and client simultaneously from within Eclipse. One of the two would be started from the command line.
  • 23. (C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable) Step 7: Run the client. JavaRmi> java helloworld.Client 42
  • 24. (C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable) Components of an RMI-based application • Services of remote objects (interfaces) • Implementation of services (classes) • Proxies for client-side (classes, generated) • A server that binds services (class) • A client that looks up services (class) • The RMI registry (component of RMI layer) • Security policies for client and server (optional)
  • 25. (C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable) Security of RMI • Useful constrains: – Service provision (“May an app provide services?”) – Naming lookups (“May an IP address look up services?”) – Remote invocations (“May an IP address invoke ...?”) • Use a non-default security manager: System.setSecurityManager(new SecurityManager()); • Assign a security policy to an application: java -Djava.security.policy=mySecurity.policy Server
  • 26. (C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable) – A non-C/S-based version as a reference: package “banking.local”. – The C/S-based version: package “banking.remote”. – Think of a refactoring to derive the latter from the former. DEMO An RMI-based banking app
  • 27. (C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable) DEMO http://101companies.org/wiki/ Contribution:javaRmi This implementation is interesting in so far that it readies all data objects for RMI. Further, the operation “total” is provided as a service, but “cut” is not. Thus, the client must implement “cut”, which essentially means that all company, department, and employee objects end up as proxies on the client.
  • 28. (C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable) Summary • RMI easily blends with OOP. – A simple form of distributed programming is enabled this way. – Client/Server applications are enabled this way. • RMI – semantics and concepts: – Use local proxy objects for access to remote objects. – Un-/marshal arguments and results for messages on the wire. – Bind objects to names (URLs) that can be used for lookup. • RMI – programming idioms: – Remote objects are looked up from server-side registry. – Remote objects may also be returned by RMI calls. – Remote objects may be created by factory methods. • Omissions: – Multiplicity of clients – Other distribution technologies: Corba, WebServices, SOA, HTTP, ...