RMI - Remote Method Invocation SYSTEM SOFTWARE 1

Size: px
Start display at page:

Download "RMI - Remote Method Invocation SYSTEM SOFTWARE 1"

Transcription

1 RMI - Remote Method Invocation SYSTEM SOFTWARE 1

2 RMI Motivation Architecture Implementation of Remote Objects Parameter Passing Callbacks RMI and Threads Distributed Garbage Collection Distribution and Class Loading Literature SYSTEM SOFTWARE 2

3 Motivation Normal method calls Based on object references within JVM client request server response client server Remote methods calls Method calls between objects in different JVMs Requires a remotereference request response request response JVM 1 JVM 2 SYSTEM SOFTWARE 3

4 Problems with Remote Method Invocations Object references What is a remote reference? How can one get a reference to an object in a different? Method calls How can the jump address of remote method be determined? Parameter passing and return values How are parameter passed and values returned from a remote method? Object creation How can one create an object in a remote JVM? Garbage collection When can a remote object be garbage collection? Class loading How and from where can the class of a remote object be loaded? SYSTEM SOFTWARE 4

5 RMI Motivation Architecture Implementation of Remote Objects Parameter Passing Callbacks RMI and Threads Distributed Garbage Collection Distribution and Class Loading Literature SYSTEM SOFTWARE 5

6 Proxy Pattern request() Client Subject interface interface the client sees and the server has to implement Subject implementation implements interface to provide functions Subject proxy used by client implements interface by delegating requests to real implementation SYSTEM SOFTWARE 6

7 Proxy Pattern in RMI Proxy server server_skeleton server_stub client request request response response JVM 2 JVM 1 Stub represents proxy for client Proxy sends requests over network to server Skeleton receives requests and forwards request to server implementation Server handles requests Results is sent back by skeleton Stub returns result to client SYSTEM SOFTWARE 7

8 Communication Architecture Client and server applications Stubs and skeletons Remote reference layer Network connection Network connection based on TCP/IP sockets JVM JVM JVM JVM SYSTEM SOFTWARE 8

9 Remote Object Registration and Lookup Registry service support Registration of remote objects with RMI-URL Lookup for remote objects Provided by RMI registration service utility rmiregistry RMI service classes Naming, Registry, and LocateRegistry SYSTEM SOFTWARE 9

10 Remote Object Registration and Lookup: Approach LocateRegistry: Access to registry service Registration: bind or rebind for registration of a remote object Must provide a unique id for the object. default port 1099, others allowed try { Bank bank = new BankImpl(); Registry reg = LocateRegistry.createRegistry(1099); reg.bind("bank", bank);... unique object name Remote object then is registered with unique RMI-URL rmi://<hostcomputer>:1099/bank Client can access remote object from server using unique name server and port // Client try { Registry reg = LocateRegistry.getRegistry("<Hostcomputer>", 1099); Bank bank = (Bank) reg.lookup("bank");... unique object name... SYSTEM SOFTWARE 10

11 RMI Motivation Architecture Implementation of Remote Objects Parameter Passing Callbacks RMI and Threads Distributed Garbage Collection Distribution and Class Loading Literature SYSTEM SOFTWARE 11

12 Implementation of Remote Objects Interfaces and classes Interface for remote object must extend interface java.rmi.remote declares public methods for remote object methods must be declared to throw RemoteException «Schnittstelle» java.rmi.remote «Schnittstelle» ServerSpec java.rmi.server.remotestub Server object implementation must implement interface must be exported to RMI system Stub (since Java 1.5 by dynamic proxy) implements Interface extends java.rmi.server.remotestub explicitly created by rmic compiler, or since Java 1.5 by dynamic proxy Skeleton (only used in Java 1.1) extends java.rmi.server.skeleton explicitly created by rmic compiler, or since Java 1.1 by dynamic proxy ServerImpl +() +changed() «Schnittstelle» java.rmi.server.skeleton ServerImpl_Skel ServerImpl_Stub since Java 1.5 also as Dynamic Proxy SYSTEM SOFTWARE 12

13 Example Bank Server The following example shows the implementation of a RMI The following steps are required Developing the application Definition of interfaces for remote objects Implementation of interface for server application Generation for stub and skeleton classes (can be omitted since Java 1.5) Implementation of server main program which creates and registers server object Implementation of client program which accesses remote object Start application Start of rmiregistry (not required since Java 1.5) Start of server program Start of client program SYSTEM SOFTWARE 13

14 Example Bank Server: Interface Bank Interface Bank defines methods for working with accounts package bank.common; import java.rmi.remote; import java.rmi.remoteexception; public interface Bank extends Remote { public static final int PORT = 1099; public long getbalance(int account) throws RemoteException; RemoteExceptions for all remote methods required! public void deposit(int account, long amount) throws RemoteException; public boolean transfer(int from, int to, long amount) throws RemoteException; SYSTEM SOFTWARE 14

15 Example Bank Server: BankImpl Class BankImpl implements interfaces should extend UnicastRemoteObject package bank.server; import java.rmi.remoteexception; import java.rmi.server.unicastremoteobject; import bank.common.bank; Extending UnicastRemoteObject! public class BankImpl extends UnicastRemoteObject implements Bank { private long[] accounts = new long[100]; Constructor with RemoteException! protected BankImpl() throws RemoteException { super(); public synchronized long getbalance(int account) throws RemoteException { return accounts[account]; public synchronized void deposit(int account, long amount) throws RemoteException { accounts[account] += amount; public synchronized boolean transfer(int from, int to, long amount) throws RemoteException { accounts[from] -= amount; accounts[to] += amount; return true; SYSTEM SOFTWARE 15

16 Example Bank Server: Stub and Skeleton Stub and skeleton classes are created by rmi-compiler program rmic > rmic keep BankImpl Or since 1.5 are created dynamically as dynamic proxies (see below) rmic <options> <class names> where <options> includes: -keep Do not delete intermediate generated source files -g Generate debugging info -depend Recompile out-of-date files recursively -nowarn Generate no warnings -verbose Output messages about what the compiler is doing -classpath <path> Specify where to find input source and class files -d <directory> Specify where to place generated class files -J<runtime flag> Pass argument to the java interpreter -v1.1 Create stubs/skeletons for JDK 1.1 stub protocol version -vcompat (default) Create stubs/skeletons compatible with both JDK 1.1 and Java 2 stub protocol versions -v1.2 Create stubs for Java 2 stub protocol version only public final class BankImpl_Stub extends java.rmi.server.remotestub implements Bank, java.rmi.remote {... public final class BankImpl_Skel implements java.rmi.server.skeleton {... SYSTEM SOFTWARE 16

17 Example Bank Server: Server Program Server program must create remote object implementation export it to RMI registry register it under unique URL package bank.server; import java.rmi.registry.locateregistry; import java.rmi.registry.registry; import bank.common.bank; public class BankServer { public BankServer() { try { Bank bank = new BankImpl(); Registry reg = LocateRegistry.createRegistry(Bank.PORT); reg.bind("bank", bank); catch (Exception e) { System.out.println("Trouble: " + e); public static void main(string args[]) { new BankServer(); SYSTEM SOFTWARE 17

18 Example Bank Server: Client Program Client program will retrieve remote object from RMI registry using URL call remote method (by calling methods of stub) catch exceptions package bank.client; import java.rmi.registry.locateregistry; import java.rmi.registry.registry; import bank.common.bank; public class BankClient { Name of server, e.g., "localhost" public static void main(string[] args) { try { Registry reg = LocateRegistry.getRegistry(" Server Adr ", Bank.PORT); Bank bank = (Bank) reg.lookup("bank"); bank.deposit(1, 10000); bank.deposit(2, 20000); boolean success = bank.transfer(1, 2, 3000); if (success) { System.out.println(bank.getBalance(1)); System.out.println(bank.getBalance(2)); else { catch (Exception e) { SYSTEM SOFTWARE 18

19 Exporting Remote Objects Remote objects must be exported to RMI system 2 possibilities Extending UnicastRemoteObject then export is done in constructor of this base class With static method exportobject of UnicastRemoteObject static Remote exportobject(remote obj, int port) throws RemoteException public class BankImpl implements Bank {... public class BankServer { private Bank bank; public BankServer() { try { bank = new BankImpl(); Registry reg = LocateRegistry.createRegistry(Registry.REGISTRY_PORT); Remote rstub = UnicastRemoteObject.exportObject(bank, Bank.PORT); reg.bind("bank", bank);... catch (Exception e) { System.out.println("Trouble: " + e); SYSTEM SOFTWARE 19

20 Unexporting Remote Objects Remote objects can be unexported from RMI (when no longer needed) with static method unexportobject of UnicastRemoteObject public static boolean unexportobject(remote obj, boolean force) throws java.rmi.nosuchobjectexception public class BankServer { private Bank bank; public start() { try { bank = new BankImpl(); Registry reg = LocateRegistry.createRegistry(PORT); RemoteStub bstub = UnicastRemoteObject.export(bank); reg.bind("bank", bstub); catch (Exception e) { System.out.println("Trouble: " + e); public static void main(string[] args) throws Exception { new BankServer().start(); // wait for termination UnicastRemoteObject.unexportObject(bank, true); SYSTEM SOFTWARE 20

21 RMI Excursion: Dynamic Proxy SYSTEM SOFTWARE 23

22 Excursion: Dynamic Proxy package java.lang.reflect Dynamic Proxy allows creating object which implements list of interfaces and delegates method calls to an InvocationHandler created by static method Proxy.newProxyInstance public class Proxy { public static Object newproxyinstance(classloader loader, Class<?>[] interfaces, InvocationHandler h) throws IllegalArgumentException; Implemented interfaces InvocationHandler Application: Foo f = (Foo)Proxy.newProxyInstance(null, new Class[] {Foo.class, handler); Created proxy object now implements interfaces by calling invoke of InvocationHandler public interface InvocationHandler { Object invoke(object proxy, Method method, Object[] args) throws Throwable Reflection API SYSTEM SOFTWARE 24

23 Example Dynamic Proxy: TraceHandler (1/2) TraceHandler implements InvocationHandler prints out a trace message then calls real method class TraceHandler implements InvocationHandler { private Object target; private PrintStream tracelog; public TraceHandler(Object target, PrintStream tracelog) { this.target = target; this.tracelog = tracelog; public Object invoke(object proxy, Method m, Object[] args) throws Throwable { tracelog.print(target + "." + m.getname() + "("); if (args!= null) { for (int i = 0; i < args.length; i++) { tracelog.print(args[i]); if (i < args.length - 1) tracelog.print(", "); tracelog.println(")"); return m.invoke(target, args); Output of trace info Call of real method using reflection API SYSTEM SOFTWARE 25

24 Example Dynamic Proxy: TraceHandler (2/2) Test of Proxy for Integer values which implement Comparable interface Trace of compareto method of Comparable public class ProxyTest { public static void main(string[] args) { Object[] elements = new Object[1000]; // fill elements with proxies for the integers for (int i = 0; i < elements.length; i++) { Integer value = i + 1; Class[] interfaces = value.getclass().getinterfaces(); InvocationHandler handler = new TraceHandler(value, System.out); Object proxy = Proxy.newProxyInstance(null, interfaces, handler); elements[i] = proxy; Integer key = 547; // search for the key int result = Arrays.binarySearch(elements, key); // print match if found if (result >= 0) System.out.println(elements[result]); 500.compareTo(547) 750.compareTo(547) 625.compareTo(547) 562.compareTo(547) 531.compareTo(547) 546.compareTo(547) 554.compareTo(547) 550.compareTo(547) 548.compareTo(547) 547.compareTo(547) { Comparable.class SYSTEM SOFTWARE 26

25 RMI Motivation Architecture Implementation of Remote Objects Parameter Passing Callbacks RMI and Threads Distributed Garbage Collection Distribution and Class Loading Literature SYSTEM SOFTWARE 27

26 Parameter Passing and Return Values Must marshall and unmarshall parameters and return values for network transfer boolean success = bank.transfer(1, 2, 3000); marshall unmarshall :BankClient :Bank_Stub :Bank_Skeleton :Bank_Impl transfer(1,2,3000) transfer(1,2,3000) true 111 true JVM 1 unmarshall marshall JVM 1 SYSTEM SOFTWARE 28

27 Parameter Passing and Return Values Marshalling dependent on type of values Built-in data types (int, double, boolean, char etc.) are transferred as is in byte stream Serializable objects (implement interface Serializable) objects get serialized by internal serialization mechanism and on the other side a copy is created by deserializing it Remote objects (implement interface Remote) a stub is created at the client side all others (not serializable and not remote) cannot be used as parameters or return values in remote method calls Object serialization: see slides on InputOutput streaming SYSTEM SOFTWARE 29

28 Marshalling Serializable Objects Serializable objects implement interface Serializable object information and (non-transient) fields will be serialized public class AccountInfo implements Serializable { private final int id; private final String owner; private final long balance; public AccountInfo(int id, String owner, long balance) { public interface Bank extends Remote { public AccountInfo getaccountinfo(int accountnumber) throws RemoteException; Deserialize object from stream at client side public class BankClient { public static void main(string[] args) { try { AccountInfo info = bank.getaccountinfo(acc1.getid()); deserialized object SYSTEM SOFTWARE 30

29 Marshalling Serializable Objects Will serialize object into byte stream transfer byte stream deserialize and create new object from byte stream :BankClient :Bank_Stub :Bank_Skeleton :Bank_Impl Info info = getaccountinfo(id) getaccountinfo(id) :AccountInfo :AccountInfo Info info = getaccountinfo(id) deserialize serialize getaccountinfo(id) :AccountInfo :AccountInfo JVM 1 new object created JVM 1 SYSTEM SOFTWARE 31

30 Serializable / Not Serializable Data Types Serializable : built-in data types (int, boolean, double, ) arrays with serializable element type String Collections: ArrayList, LinkedList, TreeSet, Calendar, Date, etc. Example of not serializable types : Thread, ClassLoader, etc. Objects local to the VM InputStream, Socket, etc. Objects accessing os resources SYSTEM SOFTWARE 32

31 Marshalling Remote Objects Not the object values is transmitted but a remote reference is created by RMI system client server_stub server_skeleton server getremotemember() getremotemember() create() remote_stub remote_stub remote remote Remote-Reference to remote JVM 1 JVM 2 SYSTEM SOFTWARE 33

32 Extended Bank Example Remote objects Account Customer Bank with extended interface public interface Account extends Remote { public int getid() throws RemoteException; public Customer getcustomer() throws RemoteException; public long getbalance() throws RemoteException; public long withdraw(long amount) throws RemoteException; public void deposit(long diff) throws RemoteException; public interface Customer extends Remote { public String getname() throws RemoteException; public Account[] getaccounts() throws RemoteException; public interface Bank extends Remote { public Customer getcustomer(string name) throws RemoteException; public Customer createcustomer(string name) throws RemoteException; public Account getaccount(int accountnumber) throws RemoteException; public Account createaccount(string customer) throws RemoteException; public void transfer(int from, int to, long amount) throws RemoteException; methods return remote objects SYSTEM SOFTWARE 34

33 Extended Bank Example: BankImpl BankImpl stores sets of customers and accounts and provides access to customers and accounts public class BankImpl extends UnicastRemoteObject implements Bank { private static BankImpl instance; public synchronized static Bank getinstance() { if (instance == null) { try { instance = new BankImpl(); catch (RemoteException e) { return instance; private static int id = 0; private final Map<Integer, AccountImpl> accounts; private final Map<String, CustomerImpl> customers; private BankImpl() throws RemoteException { accounts = new HashMap<Integer, Account>(); customers = new HashMap<String, public synchronized Customer getcustomer(string name) throws RemoteException { return public synchronized Account getaccount(int id) throws RemoteException { return accounts.get(id);... SYSTEM SOFTWARE 35

34 Extended Bank Example: CustomerImpl public class CustomerImpl extends UnicastRemoteObject implements Customer { private final String name; final List<Account> accounts; protected CustomerImpl(String name) throws RemoteException { super(); this.name = name; this.accounts = new public String getname() throws RemoteException { return public synchronized Account[] getaccounts() throws RemoteException { return accounts.toarray(new Account[0]); SYSTEM SOFTWARE 36

35 Extended Bank Example: AccountImpl public class AccountImpl extends UnicastRemoteObject implements Account { private final int id; private final String customer; private long balance; public AccountImpl(int id, String customer) throws RemoteException { super(); this.id = id; this.customer = customer; balance = public int getid() throws RemoteException { return public Customer getcustomer() throws RemoteException { return public synchronized long getbalance() throws RemoteException { return balance; SYSTEM SOFTWARE 37

36 Extended Bank Example: Server Program Server program registers Bank as single access point public class BankServer { private static Bank bank; private static void start() throws Exception { bank = BankImpl.getInstance(); Registry reg = LocateRegistry.createRegistry(Registry.REGISTRY_PORT); reg.bind("bank", bank); System.out.println("Server started on port " + Registry.REGISTRY_PORT); public static void main(string[] args) throws Exception { start(); SYSTEM SOFTWARE 38

37 Extended Bank Example: Client Program Client program then retrieves Bank from RMI registry other remote objects, Customers and Accounts, are then retrieved from Bank public class BankClient { public static void main(string[] args) { try { Registry reg = LocateRegistry.getRegistry("localhost", Bank.PORT); Bank bank = (Bank) reg.lookup("bank"); Customer cust1 = bank.createcustomer("berger"); Customer cust2 = bank.createcustomer("maier"); retrieve Bank Account acc1 = bank.createaccount("berger"); Account acc2 = bank.createaccount("maier"); acc1.deposit(10000); acc2.deposit(20000); boolean success = bank.transfer(acc1.getid(), acc2.getid(), 3000); if (success) { System.out.println(acc1.getBalance()); System.out.println(acc2.getBalance()); else { System.out.println("Transfer not successful"); catch (Exception exc) { exc.printstacktrace(); Create and access remote objects Customer and Account from Bank SYSTEM SOFTWARE 39

38 Combining Serializable and Remote Objects When a Serializable object contains a remote object, the deserialized object will contain a Stub to the remote object public interface Customer extends Remote { public Account[] getaccounts() throws RemoteException; array Serializable, Account Remote public class BankClient { public static void main(string[] args) { try { Account[] accounts = customer.getaccounts(); array of stubs Note: Remote object reference in a Serializable object can be problematic public class RemoteAccountEvent extends EventObject implements Serializable { private final Account account; NOT A GOOD IDEA!! public RemoteAccountEvent(Account source) { Event object contains remote stub! super(source); SYSTEM SOFTWARE 40

39 == and equals for Serializable Objects == of serialized objects with every remote access a new object is created by deserialization public class BankClient_Equals { public static void main(string[] args) { try { Customer berger = bank.getcustomer("berger"); String name1 = berger.getname(); String name2 = berger.getname(); if (name1 == name2) { false!!! equals when Serializable object implements equals public class BankClient_Equals { public static void main(string[] args) { try { Customer berger = bank.getcustomer("berger"); String name1 = berger.getname(); String name2 = berger.getname(); if (name1.equals(name2)) { true!!! SYSTEM SOFTWARE 41

40 == and equals for Remote References == of remote references with every remote access an new stub is created Stub objects are not == public class BankClient_Equals { public static void main(string[] args) { try { Customer cust1 = bank.getcustomer("berger"); Customer cust2 = bank.getcustomer("berger"); if (cust1 == cust2) { false!!! equals of remote references Stub implements equals so that stubs of same remote objects are equals Stub objects are equals when stubs reference same remote object public class BankClient_Equals { public static void main(string[] args) { try { Customer cust1 = bank.getcustomer("berger"); Customer cust2 = bank.getcustomer("berger"); if (cust1.equals(cust2)) { true!!! SYSTEM SOFTWARE 42

41 == and equals for Remote References CustomerImpl implements equals has no effect on client public class CustomerImpl extends UnicastRemoteObject implements Customer {... public synchronized boolean equals(object obj) { if (obj instanceof CustomerImpl) { return name.equals((customerimpl) obj).name; return false; public class BankImpl extends UnicastRemoteObject implements Bank { Server... CarStore erzeugt immer neue CarImpl-Objekte public synchronized Customer getcustomer(string name) throws RemoteException { return new CustomerImpl(name); public class BankClient_Equals { public static void main(string[] args) { try { Customer berger1 = bank.getcustomer("berger"); Customer berger2 = bank.getcustomer("berger"); Diese Objekte werden am Client nicht als equals erkannt if (cust1.equals(cust2)) { new Customer objects with same name are created false, because equals of stub is used and not same remote object SYSTEM SOFTWARE 43

42 Remote References as Parameter public boolean transfer(account from, Account to, long amount) throws RemoteException; Remote reference as parameter problematic client retrieves remote object client hold stub object when using stub as parameter stub is sent back to server connection to original remote object lost better use ids as parameters client server_stub server_skeleton server remote_stub remote callwithref(remote_stub) returnref(remote_stub)?? Remote-Reference to remote_stub remote_stub JVM 1 JVM 2 SYSTEM SOFTWARE 44

43 Extended Bank Example: Bad transfer Method public interface Bank extends Remote { public boolean transfer(account from, Account to, long amount) throws RemoteException; Implementation of remote method public class BankImpl extends UnicastRemoteObject implements Bank public boolean transfer(account from, Account to, long amount) throws RemoteException { if (from == to) { return false; // does not work as expected!! will never become true if (! accounts.containsvalue(to)) { return false; // does not work as expected!! will always be true return transfer(from.getid(), to.getid(), amount); must work with ids anyway SYSTEM SOFTWARE 45

44 RMI Motivation Architecture Implementation of Remote Objects Parameter Passing Callbacks RMI and Threads Distributed Garbage Collection Distribution and Class Loading Literature SYSTEM SOFTWARE 46

45 Callbacks Callbacks are calls from server to client e.g., to send clients change notifications Role of client and server is changed client must provide a remote object server has a remote reference client implements Remote!! client server_stub server_skel server addchangelistener(client) addchangelistener(client_stub) client_skel Remote-Reference to client client_stub changed() JVM 1 JVM 2 SYSTEM SOFTWARE 47

46 Bank Example with Callback Remote listener interface for client public interface RemoteAccountListener extends Remote { public void accountchanged(remoteaccountevent e) throws RemoteException; Account gets add- and removeaccountlistener methods public interface Account extends Remote { public void addremoteaccountlistener(remoteaccountlistener l) throws RemoteException; public void removeremoteaccountlistener(remoteaccountlistener l) throws RemoteException; public class AccountImpl extends UnicastRemoteObject implements Account { private final List<RemoteAccountListener> listeners = public void addremoteaccountlistener(remoteaccountlistener l) throws RemoteException { public void removeremoteaccountlistener(remoteaccountlistener l) throws RemoteException listeners.remove(l); private void fireaccountchanged() { SYSTEM SOFTWARE 48

47 Bank Example with Callback Client has to create and register listener object public class BankClient_Callback { public static void main(string[] args) { try { acc1watcher = new AccountWatcher("Berger"); acc2watcher = new AccountWatcher( Maier"); acc1.addremoteaccountlistener(acc1watcher); acc2.addremoteaccountlistener(acc2watcher); add remote listeners acc1.deposit(10000); acc2.deposit(20000); boolean success = bank.transfer(acc1.getid(), acc2.getid(), 3000); catch (Exception e) { System.out.println("Trouble: " + e); finally { try { acc1.removeremoteaccountlistener(acc1watcher); catch (Exception e) { try { acc2.removeremoteaccountlistener(acc2watcher); catch (RemoteException e) { try { UnicastRemoteObject.unexportObject(acc1Watcher, true); catch (NoSuchObjectExce try { UnicastRemoteObject.unexportObject(acc2Watcher, true); catch (NoSuchObjectExcep private static class AccountWatcher extends UnicastRemoteObject implements RemoteAccountListener { DO NOT FORGET: remove listener and unexport from RMI Listener as remote object private final String name; public AccountWatcher(String name) throws RemoteException { public void accountchanged(remoteaccountevent e) throws RemoteException { SYSTEM SOFTWARE 49

48 RMI Motivation Architecture Implementation of Remote Objects Parameter Passing Callbacks RMI and Threads Distributed Garbage Collection Distribution and Class Loading Literature SYSTEM SOFTWARE 50

49 RMI and Threads Each request executed in its own thread client 1 client 2 request1() Server Thread request2() request3() Synchronisation required Synchronization of remote access operations required!! SYSTEM SOFTWARE 51

50 Bank Example: Synchronization E.g., by synchronization der remote methods public class BankImpl extends UnicastRemoteObject implements Bank public synchronized Customer getcustomer(string name) throws RemoteException { return customers.get(name); synchronized on public synchronized Customer createcustomer(string name) throws RemoteException public synchronized Account getaccount(int id) throws RemoteException public synchronized Account createaccount(string c) throws RemoteException {... public class AccountImpl extends UnicastRemoteObject implements Account { private final List<RemoteAccountListener> listeners; public AccountImpl(int id, String customer) throws RemoteException { this.listeners = new CopyOnWriteArrayList<>(); thread-safe listener list SYSTEM SOFTWARE 52

51 Problem: Long Running Processes Long running code blocks whole application public class BankImpl extends UnicastRemoteObject implements Bank {... public synchronized void makeannualbalance() { // long lasting activity... Long running code blocks other clients Solution: Long running code in background thread! SYSTEM SOFTWARE 53

52 Problem: Reentrancy Java locks are reentrant i.e., thread which holds lock can enter synchronized code of same lock public class BankImpl extends UnicastRemoteObject implements Bank public synchronized void transfer(int from, int to, long amount) throws RemoteException { Account afrom = getaccount(from); Account ato = getaccount(to); with lock to BankImpl public synchronized Account getaccount(int id) throws RemoteException { with lock to BankImpl SYSTEM SOFTWARE 54

53 Problem: Reentrancy When calling remote methods in callbacks, a different thread will execute second client request cannot enter synchronized code and application deadlocks client 1 Server callback() request1() request2() synchronized(this) synchronized(this) Deadlock because different threads SYSTEM SOFTWARE 55

54 Problem: Reentrancy Bank Example: Remote method call in callback public class BankClient extends UnicastRemoteObject { private static class AccountWatcher extends UnicastRemoteObject implements AccountListener { public void accountchanged(accountchangedevent evt) throws RemoteException { bank.getaccount()... ; public class BankImpl extends UnicastRemoteObject... Thread public synchronized void transfer(int from, int to, long am Account afrom = getaccount(from); Account ato = getaccount(to); ato.fireaccountchanged(); Thread public synchronized Account getaccount(int id) throws Remot SYSTEM SOFTWARE 56

55 Problem: Reentrancy Solution: Asynchronous Callbacks client Server callback() request2() request1() synchronized(this) can terminate Callback in asynchronous runnable, non blocking, not synchronized(this) synchronized(this) SYSTEM SOFTWARE 57

56 Problem: Reentrancy Bank Example: Asynchous execution of callback public class AccountImpl extends UnicastRemoteObject implements Account { private final ExecutorService executor = public void deposit(long diff) throws RemoteException { synchronized (this) { balance = balance + diff; fireaccountchangedevent(); First method can terminate private void fireaccountchanged() { final AccountChangedEvent evt = new AccoutChangedEvent( ); for (final AccountListener l : listeners) { executor.submit(() -> { l.accountchanged(evt); ); Do callback in asynchronous Runnable SYSTEM SOFTWARE 58

57 RMI Motivation Architecture Implementation of Remote Objects Parameter Passing Callbacks RMI and Threads Distributed Garbage Collection Distribution and Class Loading Literature SYSTEM SOFTWARE 59

58 Distributed Garbage Collection Normal garbage collector frees objects in VM which cannot be accessed any more Cannot function for remote objects Gargabe collector has no reference to remote object Distributed Garbage Collector works by: Reference Counting: the references of the remote object by clients are counted Lease Time: Does a client not access a remote object for some time the lease time it is allowed to collect the memory of the remote object Clients have to be aware that remote objects can disappear which lead to exceptions Lease Time: System property: java.rmi.dgc.leasevalue Default value 10 min Set as VM argument: java Djava.rmi.dgc.leaseValue=20000 SYSTEM SOFTWARE 60

59 RMI Motivation Architecture Implementation of Remote Objects Parameter Passing Callbacks RMI and Threads Distributed Garbage Collection Distribution and Class Loading Literature SYSTEM SOFTWARE 61

60 Distribution of Code and Class Loading Dynamic loading of classes in clients for stubs for parameter and return values Example: Stub Client Server client server_stub server_skeleton server getremotemember() getremotemember() create() remote_stub remote_stub remote remote Remote-Reference to remote JVM 1 JVM 2 SYSTEM SOFTWARE 62

61 Motivation Dynamic Class Loading public interface Bank extends Remote { public Customer getcustomer(string customername) throws RemoteException; PrivateCustomer Customer BusinessCustomer There are different subclasses of Customer! Client has to have code for those special classes! public class BankImpl extends UnicastRemoteObject implements Bank { public synchronized Customer getcustomer(string customername) throws RemoteException { if ( ) return privateclients.get(customername); else return businessclients.get(customername); Client: There has to be a way that client can load code as needed Concrete object of type PrivateCustomer_Stub or BusinessCustomer_Stub try { Customer customer = account.getcustomer(name); catch (RemoteException remoteexception) { System.err.println(remoteException); SYSTEM SOFTWARE 63

62 Dynamic Class Loading Code usually loaded from download folder of Web server To allow code to be loaded from an external site: a SecurityManager has to be installed program has to get permissions as follows Socket connection to server for RMI connection on port 1099 Socket connection for remote class loading from Web server on port 80 (or 8080) Example: Client program: public class MyClient { public static void main(string[] args) { System.setProperty("java.security.policy", "client.policy"); System.setSecurityManager(new SecurityManager());... Policy file for client: grant { permission java.net.socketpermission server-url: , connect ; permission java.net.socketpermission server-url:80, connect ; permission java.net.socketpermission server-url:8080, connect ; SYSTEM SOFTWARE 64

63 Distribution of Code Code divided in 3 parts server: all classes required for server program download: all classes eventually needed by client and possibly dynamically loaded by client including all dependent classes, e.g., base classes, interfaces client: classes to run the client the policy file (e.g., client.policy) 3 parts deployed then : server: computer running server application download: download folder of Web server client: computer running client application SYSTEM SOFTWARE 65

64 RMI Motivation Architecture Implementation of Remote Objects Parameter Passing Callbacks RMI and Threads Distributed Garbage Collection Distribution and Class Loading Literature SYSTEM SOFTWARE 66

65 Literature Horstmann, Cornell, Core Java 2, Volume II. Advance Features, Sun Microsystems, 2008: Chapter 5 Krüger, Handbuch der Java-Programmierung, 3. Auflage, Addison-Wesley, 2003, Kapitel 46 Fundamentals of RMI, Short Course, SYSTEM SOFTWARE 67

Generic architecture

Generic architecture Java-RMI Lab Outline Let first builds a simple home-made framework This is useful to understand the main issues We see later how java-rmi works and how it solves the same issues Generic architecture object

More information

IBD Intergiciels et Bases de Données

IBD Intergiciels et Bases de Données IBD Intergiciels et Bases de Données RMI-based distributed systems Fabien Gaud, Fabien.Gaud@inrialpes.fr Overview of lectures and practical work Lectures Introduction to distributed systems and middleware

More information

CS555: Distributed Systems [Fall 2017] Dept. Of Computer Science, Colorado State University

CS555: Distributed Systems [Fall 2017] Dept. Of Computer Science, Colorado State University CS 555: DISTRIBUTED SYSTEMS [RMI] Frequently asked questions from the previous class survey Shrideep Pallickara Computer Science Colorado State University L21.1 L21.2 Topics covered in this lecture RMI

More information

Object Interaction. Object Interaction. Introduction. Object Interaction vs. RPCs (2)

Object Interaction. Object Interaction. Introduction. Object Interaction vs. RPCs (2) Introduction Objective To support interoperability and portability of distributed OO applications by provision of enabling technology Object interaction vs RPC Java Remote Method Invocation (RMI) RMI Registry

More information

Remote Method Invocation

Remote Method Invocation Non-101samples available here: https://github.com/101companies/101repo/tree/master/languages/aspectj/javarmisamples Remote Method Invocation Prof. Dr. Ralf Lämmel Universität Koblenz-Landau Software Languages

More information

Remote Method Invocation

Remote Method Invocation Remote Method Invocation A true distributed computing application interface for Java, written to provide easy access to objects existing on remote virtual machines Provide access to objects existing on

More information

How are classes loaded into the Java Virtual Machine (JVM)? from the local file system (CLASSPATH). by an instance of ClassLoader

How are classes loaded into the Java Virtual Machine (JVM)? from the local file system (CLASSPATH). by an instance of ClassLoader 36 ClassLoader How are classes loaded into the Java Virtual Machine (JVM)? from the local file system (CLASSPATH). by an instance of ClassLoader... and when? - When they are needed the first time. class

More information

JAVA RMI. Remote Method Invocation

JAVA RMI. Remote Method Invocation 1 JAVA RMI Remote Method Invocation 2 Overview Java RMI is a mechanism that allows one to invoke a method on an object that exists in another address space. The other address space could be: On the same

More information

JAVA RMI Java, summer semester

JAVA RMI Java, summer semester JAVA RMI Overview Remote Method Invocation usage of remote object objects in a different VM (on the same computer or over the network) as there would be local objects (almost) calls just take longer time

More information

Lecture 18 Inside Java RMI

Lecture 18 Inside Java RMI CMSC 433 Fall 2014 Sec/on 0101 Mike Hicks (slides due to Rance Cleaveland) Lecture 18 Inside Java RMI Recall Java RMI applica/ons consist of three en//es Remote object servers Host remote objects Handle

More information

RMI Example RMI. CmpE 473 Internet Programming RMI

RMI Example RMI. CmpE 473 Internet Programming RMI CmpE 473 Internet Programming Pınar Yolum pinar.yolum@boun.edu.tr Department of Computer Engineering Boğaziçi University RMI Examples from Advanced Java: Internet Applications, Art Gittleman Remote Method

More information

presentation DAD Distributed Applications Development Cristian Toma

presentation DAD Distributed Applications Development Cristian Toma Lecture 8 S4 - Core Distributed Middleware Programming in JEE presentation DAD Distributed Applications Development Cristian Toma D.I.C.E/D.E.I.C Department of Economic Informatics & Cybernetics www.dice.ase.ro

More information

Remote Method Invocation Benoît Garbinato

Remote Method Invocation Benoît Garbinato Remote Method Invocation Benoît Garbinato 1 Fundamental idea (1) Rely on the same programming paradigm for distributed applications as for centralized applications In procedural languages, we will rely

More information

Remote Method Invocation. Benoît Garbinato

Remote Method Invocation. Benoît Garbinato Remote Method Invocation Benoît Garbinato Fundamental idea (1) Rely on the same programming paradigm for distributed applications as for centralized applications In procedural languages, we will rely on

More information

Remote Method Invocation

Remote Method Invocation Remote Method Invocation RMI Dr. Syed Imtiyaz Hassan Assistant Professor, Deptt. of CSE, Jamia Hamdard (Deemed to be University), New Delhi, India. s.imtiyaz@jamiahamdard.ac.in 1 Agenda Introduction Creating

More information

RMI. (Remote Method Invocation)

RMI. (Remote Method Invocation) RMI (Remote Method Invocation) Topics What is RMI? Why RMI? Architectural components Serialization & Marshaled Objects Dynamic class loading Code movement Codebase ClassLoader delegation RMI Security Writing

More information

SUMMARY INTRODUCTION REMOTE METHOD INVOCATION

SUMMARY INTRODUCTION REMOTE METHOD INVOCATION SUMMARY 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 Introduction

More information

5.4. Events and notifications

5.4. Events and notifications 5.4. Events and notifications Distributed event-based systems extend local event model Allowing multiple objects at diff. locations to be notified of events taking place at an object Two characteristics:

More information

Agent and Object Technology Lab Dipartimento di Ingegneria dell Informazione Università degli Studi di Parma. Distributed and Agent Systems RMI

Agent and Object Technology Lab Dipartimento di Ingegneria dell Informazione Università degli Studi di Parma. Distributed and Agent Systems RMI Agent and Object Technology Lab Dipartimento di Ingegneria dell Informazione Università degli Studi di Parma Distributed and Agent Systems RMI Prof. Agostino Poggi What is RMI? Its acronym means Remote

More information

Distributed Systems. 02r. Java RMI Programming Tutorial. Paul Krzyzanowski TA: Long Zhao Rutgers University Fall 2017

Distributed Systems. 02r. Java RMI Programming Tutorial. Paul Krzyzanowski TA: Long Zhao Rutgers University Fall 2017 Distributed Systems 02r. Java RMI Programming Tutorial Paul Krzyzanowski TA: Long Zhao Rutgers University Fall 2017 1 Java RMI RMI = Remote Method Invocation Allows a method to be invoked that resides

More information

RMI (Remote Method Invocation) Over the year, there have been 3 different approaches to application development:

RMI (Remote Method Invocation) Over the year, there have been 3 different approaches to application development: RMI (Remote Method Invocation) History: Over the year, there have been 3 different approaches to application development: 1. the traditional approach. 2. the client / server approach and 3. the component-

More information

CC755: Distributed and Parallel Systems

CC755: Distributed and Parallel Systems CC755: Distributed and Parallel Systems Dr. Manal Helal, Spring 2016 moodle.manalhelal.com Lecture 7: Remote Method Invocation (RMI) 1 RMI Y Daniel Liang, Introduction to JAVA Programming, 9th Edition,

More information

Introduction & RMI Basics. CS3524 Distributed Systems Lecture 01

Introduction & RMI Basics. CS3524 Distributed Systems Lecture 01 Introduction & RMI Basics CS3524 Distributed Systems Lecture 01 Distributed Information Systems Distributed System: A collection of autonomous computers linked by a network, with software to produce an

More information

Distributed Programming in Java. Distribution (2)

Distributed Programming in Java. Distribution (2) Distributed Programming in Java Distribution (2) Remote Method Invocation Remote Method Invocation (RMI) Primary design goal for RMI is transparency Should be able to invoke remote objects with same syntax

More information

Contents. Java RMI. Java RMI. Java RMI system elements. Example application processes/machines Client machine Process/Application A

Contents. Java RMI. Java RMI. Java RMI system elements. Example application processes/machines Client machine Process/Application A Contents Java RMI G53ACC Chris Greenhalgh Java RMI overview A Java RMI example Overview Walk-through Implementation notes Argument passing File requirements RPC issues and RMI Other problems with RMI 1

More information

Remote Procedure Call

Remote Procedure Call Remote Procedure Call Suited for Client-Server structure. Combines aspects of monitors and synchronous message passing: Module (remote object) exports operations, invoked with call. call blocks (delays

More information

Lecture VI: Distributed Objects. Remote Method Invocation

Lecture VI: Distributed Objects. Remote Method Invocation Lecture VI: Distributed Objects. Remote Method Invocation CMPT 401 Summer 2007 Dr. Alexandra Fedorova Remote Method Invocation In an object-oriented language (usually Java) A way to call a method on an

More information

55:182/22C:182. Distributed Application Frameworks Java RMI, CORBA, Web Services (SOAP)

55:182/22C:182. Distributed Application Frameworks Java RMI, CORBA, Web Services (SOAP) 55:182/22C:182 Distributed Application Frameworks Java RMI, CORBA, Web Services (SOAP) Broker Architecture Example Java Remote Method Invocation (RMI) Invoking a method which lies in a different address

More information

RMI. Remote Method Invocation. 16-Dec-16

RMI. Remote Method Invocation. 16-Dec-16 RMI Remote Method Invocation 16-Dec-16 The network is the computer Consider the following program organization: method SomeClass call AnotherClass returned object computer 1 computer 2 If the network is

More information

REMOTE METHOD INVOCATION INTRODUCTION TO RMI, A JAVA API FOR RPC-STYLE INVOCATION OF REMOTE OBJECT METHODS

REMOTE METHOD INVOCATION INTRODUCTION TO RMI, A JAVA API FOR RPC-STYLE INVOCATION OF REMOTE OBJECT METHODS RMI Remote Method RMI Invocation REMOTE METHOD INVOCATION INTRODUCTION TO RMI, A JAVA API FOR RPC-STYLE INVOCATION OF REMOTE OBJECT METHODS Peter R. Egli 1/19 Contents 1. What is RMI? 2. Important RMI

More information

Outline. EEC-681/781 Distributed Computing Systems. The OSI Network Architecture. Inter-Process Communications (IPC) Lecture 4

Outline. EEC-681/781 Distributed Computing Systems. The OSI Network Architecture. Inter-Process Communications (IPC) Lecture 4 EEC-681/781 Distributed Computing Systems Lecture 4 Department of Electrical and Computer Engineering Cleveland State University wenbing@ieee.org Outline Inter-process communications Computer networks

More information

Java RMI. Algorithmen und Programmierung V Netzprogrammierung. Volker Roth. Wintersemester 2009/2010. Institut für Informatik Freie Universität Berlin

Java RMI. Algorithmen und Programmierung V Netzprogrammierung. Volker Roth. Wintersemester 2009/2010. Institut für Informatik Freie Universität Berlin Java RMI Algorithmen und Programmierung V Netzprogrammierung Volker Roth Institut für Informatik Freie Universität Berlin Wintersemester 2009/2010 Overview 1. Factory design pattern 2. Codebases 3. Remote

More information

Remote Method Invocation in Java

Remote Method Invocation in Java Remote Method Invocation in Java Ajay Khatri Senior Assistant Professor,Department IT Acropolis Institute of Technology & Research ajay.acropolis@gmail.com What is RMI RMI is an API that provides a mechanism

More information

Written by: Dave Matuszek

Written by: Dave Matuszek RMI Remote Method Invocation Written by: Dave Matuszek appeared originally at: http://www.cis.upenn.edu/~matuszek/cit597-2003/ 28-May-07 The network is the computer * Consider the following program organization:

More information

Distributed Objects SPL/ SPL 201 / 0 1

Distributed Objects SPL/ SPL 201 / 0 1 Distributed Objects 1 distributed objects objects which reside on different machines/ network architectures, benefits, drawbacks implementation of a remote object system 2 Why go distributed? large systems

More information

Distributed Computing

Distributed Computing Distributed Computing Computing on many systems to solve one problem Why? - Combination of cheap processors often more cost-effective than one expensive fast system - Flexibility to add according to needs

More information

Desarrollo de Aplicaciones en Red RMI. Introduction. Considerations. Considerations. RMI architecture

Desarrollo de Aplicaciones en Red RMI. Introduction. Considerations. Considerations. RMI architecture session Desarrollo de Aplicaciones en Red José Rafael Rojano Cáceres http://www.uv.mx/rrojano RMI Remote Method Invocation Introduction Java RMI let s work calling remote methods. Underneath it works with

More information

The UNIVERSITY of EDINBURGH. SCHOOL of INFORMATICS. CS4/MSc. Distributed Systems. Björn Franke. Room 2414

The UNIVERSITY of EDINBURGH. SCHOOL of INFORMATICS. CS4/MSc. Distributed Systems. Björn Franke. Room 2414 The UNIVERSITY of EDINBURGH SCHOOL of INFORMATICS CS4/MSc Distributed Systems Björn Franke bfranke@inf.ed.ac.uk Room 2414 (Lecture 3: Remote Invocation and Distributed Objects, 28th September 2006) 1 Programming

More information

Last Class: Network Overview. Today: Distributed Systems

Last Class: Network Overview. Today: Distributed Systems Last Class: Network Overview =>Processes in a distributed system all communicate via a message exchange. Physical reality: packets Abstraction: messages limited size arbitrary size unordered (sometimes)

More information

Distributed Systems. Distributed Object Systems 2 Java RMI. Java RMI. Example. Applet continued. Applet. slides2.pdf Sep 9,

Distributed Systems. Distributed Object Systems 2 Java RMI. Java RMI. Example. Applet continued. Applet. slides2.pdf Sep 9, Distributed Object Systems 2 Java RMI Piet van Oostrum Distributed Systems What should a distributed system provide? Illusion of one system while running on multiple systems Transparancy Issues Communication,

More information

RMI Case Study. A Typical RMI Application

RMI Case Study. A Typical RMI Application RMI Case Study This example taken directly from the Java RMI tutorial http://java.sun.com/docs/books/tutorial/rmi/ Editorial note: Please do yourself a favor and work through the tutorial yourself If you

More information

Chapter 15: Distributed Communication. Sockets Remote Procedure Calls (RPCs) Remote Method Invocation (RMI) CORBA Object Registration

Chapter 15: Distributed Communication. Sockets Remote Procedure Calls (RPCs) Remote Method Invocation (RMI) CORBA Object Registration Chapter 15: Distributed Communication Sockets Remote Procedure Calls (RPCs) Remote Method Invocation (RMI) CORBA Object Registration Sockets Defined as an endpoint for communcation Concatenation of IP

More information

Distributed Systems. 5. Remote Method Invocation

Distributed Systems. 5. Remote Method Invocation Distributed Systems 5. Remote Method Invocation Werner Nutt 1 Remote Method Invocation 5.1 Communication between Distributed Objects 1. Communication between Distributed Objects 2. RMI 2 Middleware Middleware

More information

Info 408 Distributed Applications programming 2 nd semester of Credits: 5 Lecturer: Antoun Yaacoub Ph.D.

Info 408 Distributed Applications programming 2 nd semester of Credits: 5 Lecturer: Antoun Yaacoub Ph.D. Lebanese University Faculty of Sciences I Master 1 degree Computer Sciences Info 408 Distributed Applications programming 2 nd semester of 2018-2019 Credits: 5 Lecturer: Antoun Yaacoub Ph.D. RMI Serialization

More information

5 Distributed Objects: The Java Approach

5 Distributed Objects: The Java Approach 5 Distributed Objects: The Java Approach Main Points Why distributed objects Distributed Object design points Java RMI Dynamic Code Loading 5.1 What s an Object? An Object is an autonomous entity having

More information

Questions and Answers. A. RMI allows us to invoke a method of java object that executes on another machine.

Questions and Answers. A. RMI allows us to invoke a method of java object that executes on another machine. Q.1) What is Remote method invocation (RMI)? A. RMI allows us to invoke a method of java object that executes on another machine. B. RMI allows us to invoke a method of java object that executes on another

More information

CS 5523 Operating Systems: Remote Objects and RMI

CS 5523 Operating Systems: Remote Objects and RMI CS 5523 Operating Systems: Remote Objects and RMI Instructor: Dr. Tongping Liu Thank Dr. Dakai Zhu and Dr. Palden Lama for providing their slides. Outline Distributed/Remote Objects Remote object reference

More information

Remote Objects and RMI

Remote Objects and RMI Outline Remote Objects and RMI Instructor: Dr. Tongping Liu Distributed/Remote Objects Remote object reference (ROR) Remote Method Invocation (RMI) Case study and example: Java RMI Other issues for objects

More information

Distributed Systems. 6. Remote Method Invocation. Werner Nutt

Distributed Systems. 6. Remote Method Invocation. Werner Nutt Distributed Systems 6. Remote Method Invocation Werner Nutt 1 Remote Method Invocation 6.1 Communication between Distributed Objects 1. Communication between Distributed Objects 2. Java RMI 3. Dynamic

More information

Distributed object component middleware I - Java RMI

Distributed object component middleware I - Java RMI Prof. Dr. Claudia Müller-Birn Institute for Computer Science, Networked Information Systems Distributed object component middleware I - Java RMI Nov 15th, 2011 Netzprogrammierung (Algorithmen und Programmierung

More information

Distributed object component middleware I - Java RMI

Distributed object component middleware I - Java RMI Prof. Dr. Claudia Müller-Birn Institute for Computer Science, Networked Information Systems Distributed object component middleware I - Java RMI Nov 15th, 2011 Netzprogrammierung (Algorithmen und Programmierung

More information

JAC444 - Lecture 11. Remote Method Invocation Segment 2 - Develop RMI Application. Jordan Anastasiade Java Programming Language Course

JAC444 - Lecture 11. Remote Method Invocation Segment 2 - Develop RMI Application. Jordan Anastasiade Java Programming Language Course JAC444 - Lecture 11 Remote Method Invocation Segment 2 - Develop RMI Application 1 Remote Method Invocation In this lesson you will be learning about: Designing RMI application Developing distributed object

More information

Grid Computing. Java Remote Method Invocation (RMI) RMI Application. Grid Computing Fall 2006 Paul A. Farrell 9/5/2006

Grid Computing. Java Remote Method Invocation (RMI) RMI Application. Grid Computing Fall 2006 Paul A. Farrell 9/5/2006 Grid Computing Paradigms for Distributed Computing 2 RMI Fall 2006 Traditional paradigms for distributed computing The Grid: Core Technologies Maozhen Li, Mark Baker John Wiley & Sons; 2005, ISBN 0-470-09417-6

More information

A Typical RMI Application. Case Study

A Typical RMI Application. Case Study A Typical RMI Application Client and Server run on different machines Remote Object(s) registered in rmiregistry by Server Remote Object(s) look d up by Client When necessary, code transferred from web

More information

Core Java SYLLABUS COVERAGE SYLLABUS IN DETAILS

Core Java SYLLABUS COVERAGE SYLLABUS IN DETAILS Core Java SYLLABUS COVERAGE Introduction. OOPS Package Exception Handling. Multithreading Applet, AWT, Event Handling Using NetBean, Ecllipse. Input Output Streams, Serialization Networking Collection

More information

03 Remote invocation. Request-reply RPC. Coulouris 5 Birrel_Nelson_84.pdf RMI

03 Remote invocation. Request-reply RPC. Coulouris 5 Birrel_Nelson_84.pdf RMI 03 Remote invocation Request-reply RPC Coulouris 5 Birrel_Nelson_84.pdf RMI 2/16 Remote Procedure Call Implementation client process Request server process client program client stub procedure Communication

More information

RPC and RMI. 2501ICT Nathan

RPC and RMI. 2501ICT Nathan RPC and RMI 2501ICT Nathan Contents Client/Server revisited RPC Architecture XDR RMI Principles and Operation Case Studies Copyright 2002- René Hexel. 2 Client/Server Revisited Server Accepts commands

More information

Firewall Issues. The possible scenarios: the RMI client, the server, or both can be operating from behind a firewall

Firewall Issues. The possible scenarios: the RMI client, the server, or both can be operating from behind a firewall Firewall Issues Firewalls are inevitably encountered by any networked enterprise application that has to operate beyond the confines of an Intranet Typically, firewalls block all network traffic, with

More information

A Typical RMI Application

A Typical RMI Application A Typical RMI Application Client and Server run on different machines Remote Object(s) registered in rmiregistry by Server Remote Object(s) look d up by Client When necessary, code transferred from web

More information

Lecture 17 Java Remote Method Invoca/on

Lecture 17 Java Remote Method Invoca/on CMSC 433 Fall 2014 Sec/on 0101 Mike Hicks (slides due to Rance Cleaveland) Lecture 17 Java Remote Method Invoca/on 11/4/2014 2012-14 University of Maryland 0 Recall Concurrency Several opera/ons may be

More information

Network. Dr. Jens Bennedsen, Aarhus University, School of Engineering Aarhus, Denmark

Network. Dr. Jens Bennedsen, Aarhus University, School of Engineering Aarhus, Denmark Network Dr. Jens Bennedsen, Aarhus University, School of Engineering Aarhus, Denmark jbb@ase.au.dk Outline Socket programming If we have the time: Remote method invocation (RMI) 2 Socket Programming Sockets

More information

Developing RMI Based Server (ChatServer)

Developing RMI Based Server (ChatServer) Introduction Developing RMI Based Server (ChatServer) In the last module, we have learnt about RMI. In this module we will look at how to create an interactive application like chat server using RMI. Demo

More information

Verteilte Systeme (Distributed Systems)

Verteilte Systeme (Distributed Systems) Verteilte Systeme (Distributed Systems) Karl M. Göschka Karl.Goeschka@tuwien.ac.at http://www.infosys.tuwien.ac.at/teaching/courses/ VerteilteSysteme/ Lecture 3: Communication (Part 2) Remote Procedure

More information

Activation of remote objects

Activation of remote objects Activation of remote objects The Activatable class Prior to the release of Java 2 SDK, an instance of a UnicastRemoteObject could be accessed from a server program that created an instance of the remote

More information

Lecture 9 : Basics of Reflection in Java

Lecture 9 : Basics of Reflection in Java Lecture 9 : Basics of Reflection in Java LSINF 2335 Programming Paradigms Prof. Kim Mens UCL / EPL / INGI (Slides partly based on the book Java Reflection in Action, on The Java Tutorials, and on slides

More information

DISTRIBUTED OBJECTS AND REMOTE INVOCATION

DISTRIBUTED OBJECTS AND REMOTE INVOCATION DISTRIBUTED OBJECTS AND REMOTE INVOCATION Introduction This chapter is concerned with programming models for distributed applications... Familiar programming models have been extended to apply to distributed

More information

Component-Based Software Engineering

Component-Based Software Engineering Component-Based Software Engineering Remote Method Invocation Paul Krause Introduction to RMI Lecture 11 - RMI Simple Example - DivideServer Demo of this example Review a more complex example - StudentEnrollment

More information

Chapter 5 Distributed Objects and Remote Invocation

Chapter 5 Distributed Objects and Remote Invocation CSD511 Distributed Systems 分散式系統 Chapter 5 Distributed Objects and Remote Invocation 吳俊興 國立高雄大學資訊工程學系 Chapter 5 Distributed Objects and Remote Invocation 5.1 Introduction 5.2 Communication between distributed

More information

15CS45 : OBJECT ORIENTED CONCEPTS

15CS45 : OBJECT ORIENTED CONCEPTS 15CS45 : OBJECT ORIENTED CONCEPTS QUESTION BANK: What do you know about Java? What are the supported platforms by Java Programming Language? List any five features of Java? Why is Java Architectural Neutral?

More information

Distributed Systems COMP 212. Lecture 10 Othon Michail

Distributed Systems COMP 212. Lecture 10 Othon Michail Distributed Systems COMP 212 Lecture 10 Othon Michail RMI: Remote Method Invocation Allows an object running in one Java virtual machine to invoke methods on an object running in another Java virtual machine.

More information

Distributed Objects. Remote Method Invokation

Distributed Objects. Remote Method Invokation Distributed Objects Remote Method Invokation Distributed Systems Object Oriented Paradigm invoke method Object 1 Object 2 respond Distributed Object Oriented Paradigm Client Host/Process invoke method

More information

Dynamic code downloading using Java TM (Using the java.rmi.server.codebase Property)

Dynamic code downloading using Java TM (Using the java.rmi.server.codebase Property) Pagina 1 Dynamic code downloading using Java TM RMI (Using the java.rmi.server.codebase Property) This tutorial is organized as follows: 1. Starting out 2. What is a codebase? 3. How does it work? 4. Using

More information

Distributed Software Systems

Distributed Software Systems RMI Programming Distributed Software Systems RMI Programming RMI software Generated by IDL compiler Proxy Behaves like remote object to clients (invoker) Marshals arguments, forwards message to remote

More information

1 interface TemperatureSensor extends java.rmi.remote 2 { 3 public double gettemperature() throws java.rmi.remoteexception; 4 public void

1 interface TemperatureSensor extends java.rmi.remote 2 { 3 public double gettemperature() throws java.rmi.remoteexception; 4 public void 1 interface TemperatureSensor extends java.rmi.remote 2 { 3 public double gettemperature() throws java.rmi.remoteexception; 4 public void addtemperaturelistener ( TemperatureListener listener ) 5 throws

More information

CS193k, Stanford Handout #12. Threads 4 / RMI

CS193k, Stanford Handout #12. Threads 4 / RMI CS193k, Stanford Handout #12 Spring, 99-00 Nick Parlante Threads 4 / RMI Semaphore1 Semaphore1 from last time uses the count in a precise way to know exactly how many threads are waiting. In this way,

More information

Project 1: Remote Method Invocation CSE 291 Spring 2016

Project 1: Remote Method Invocation CSE 291 Spring 2016 Project 1: Remote Method Invocation CSE 291 Spring 2016 Assigned: Tuesday, 5 April Due: Thursday, 28 April Overview In this project, you will implement a remote method invocation (RMI) library. RMI forwards

More information

Course Snapshot. The Next Few Classes. Parallel versus Distributed Systems. Distributed Systems. We have covered all the fundamental OS components:

Course Snapshot. The Next Few Classes. Parallel versus Distributed Systems. Distributed Systems. We have covered all the fundamental OS components: Course Snapshot The Next Few Classes We have covered all the fundamental OS components: Architecture and OS interactions Processes and threads Synchronization and deadlock Process scheduling Memory management

More information

RPC flow. 4.3 Remote procedure calls IDL. RPC components. Procedure. Program. sum (j,k) int j,k; {return j+k;} i = sum (3,7); Local procedure call

RPC flow. 4.3 Remote procedure calls IDL. RPC components. Procedure. Program. sum (j,k) int j,k; {return j+k;} i = sum (3,7); Local procedure call 4.3 Remote procedure calls RPC flow Client process Server process Program i = sum (3,7); Procedure sum (j,k) int j,k; {return j+k; Client stub Program Return Call Unpack Pack result para s Invisible to

More information

Chapter 4 Remote Procedure Calls and Distributed Transactions

Chapter 4 Remote Procedure Calls and Distributed Transactions Prof. Dr.-Ing. Stefan Deßloch AG Heterogene Informationssysteme Geb. 36, Raum 329 Tel. 0631/205 3275 dessloch@informatik.uni-kl.de Chapter 4 Remote Procedure Calls and Distributed Transactions Outline

More information

Compaq Interview Questions And Answers

Compaq Interview Questions And Answers Part A: Q1. What are the difference between java and C++? Java adopts byte code whereas C++ does not C++ supports destructor whereas java does not support. Multiple inheritance possible in C++ but not

More information

Communication and Distributed Processing

Communication and Distributed Processing Prof. Dr.-Ing. Stefan Deßloch AG Heterogene Informationssysteme Geb. 36, Raum 329 Tel. 0631/205 3275 dessloch@informatik.uni-kl.de Chapter 4 Remote Procedure Calls and Distributed Transactions Outline

More information

Distributed Programming with RMI. Overview CORBA DCOM. Prepared By: Shiba R. Tamrakar

Distributed Programming with RMI. Overview CORBA DCOM. Prepared By: Shiba R. Tamrakar Distributed Programming with RMI Overview Distributed object computing extends an object-oriented programming system by allowing objects to be distributed across a heterogeneous network, so that each of

More information

Bharati Vidyapeeth s Institute of Computer Applications and Management A-4, Paschim Vihar, New Delhi-63.

Bharati Vidyapeeth s Institute of Computer Applications and Management A-4, Paschim Vihar, New Delhi-63. Bharati Vidyapeeth s Institute of Computer Applications and Management A-4, Paschim Vihar, New Delhi-63. MCA III rd Semester Second Internal: Java Programming (MCA-205) Note: All the questions are compulsory.

More information

COMP 6231: Distributed System Design

COMP 6231: Distributed System Design COMP 6231: Distributed System Design Remote Invocation and RMI Based on Chapters 5, 7 of the text book and the slides from Prof. M.L. Liu, California Polytechnic State University COMP 6231, Fall 2013 Remote

More information

AP COMPUTER SCIENCE JAVA CONCEPTS IV: RESERVED WORDS

AP COMPUTER SCIENCE JAVA CONCEPTS IV: RESERVED WORDS AP COMPUTER SCIENCE JAVA CONCEPTS IV: RESERVED WORDS PAUL L. BAILEY Abstract. This documents amalgamates various descriptions found on the internet, mostly from Oracle or Wikipedia. Very little of this

More information

Java Remote Method Invocation Specification

Java Remote Method Invocation Specification Java Remote Method Invocation Specification Java Remote Method Invocation (RMI) is a distributed object model for the Java language that retains the semantics of the Java object model, making distributed

More information

THE UNIVERSITY OF WESTERN AUSTRALIA SAMPLE EXAM QUESTIONS 2007 WITH SOLUTIONS SCHOOL OF COMPUTER SCIENCE CITS3213 CONCURRENT PROGRAMMING (PART II)

THE UNIVERSITY OF WESTERN AUSTRALIA SAMPLE EXAM QUESTIONS 2007 WITH SOLUTIONS SCHOOL OF COMPUTER SCIENCE CITS3213 CONCURRENT PROGRAMMING (PART II) THE UNIVERSITY OF WESTERN AUSTRALIA SAMPLE EXAM QUESTIONS 2007 WITH SOLUTIONS SCHOOL OF COMPUTER SCIENCE CITS3213 CONCURRENT PROGRAMMING (PART II) The exam will contain: 6 questions (3 for each part) Time

More information

A Quick Tour p. 1 Getting Started p. 1 Variables p. 3 Comments in Code p. 6 Named Constants p. 6 Unicode Characters p. 8 Flow of Control p.

A Quick Tour p. 1 Getting Started p. 1 Variables p. 3 Comments in Code p. 6 Named Constants p. 6 Unicode Characters p. 8 Flow of Control p. A Quick Tour p. 1 Getting Started p. 1 Variables p. 3 Comments in Code p. 6 Named Constants p. 6 Unicode Characters p. 8 Flow of Control p. 9 Classes and Objects p. 11 Creating Objects p. 12 Static or

More information

Introduction to Reflection

Introduction to Reflection Introduction to Reflection Mark Allen Weiss Copyright 2000 1 What is Reflection The Class class Outline of Topics Run Time Type Identification (RTTI) Getting Class Information Accessing an arbitrary object

More information

Communication and Distributed Processing

Communication and Distributed Processing Prof. Dr.-Ing. Stefan Deßloch AG Heterogene Informationssysteme Geb. 36, Raum 329 Tel. 0631/205 3275 dessloch@informatik.uni-kl.de Chapter 4 Remote Procedure Calls and Distributed Transactions Outline

More information

CSci Introduction to Distributed Systems. Communication: RPC In Practice

CSci Introduction to Distributed Systems. Communication: RPC In Practice CSci 5105 Introduction to Distributed Systems Communication: RPC In Practice Linux RPC Language-neutral RPC Can use Fortran, C, C++ IDL compiler rpgen N to generate all stubs, skeletons (server stub) Example:

More information

Architecture of So-ware Systems RMI and Distributed Components. Mar<n Rehák

Architecture of So-ware Systems RMI and Distributed Components. Mar<n Rehák Architecture of So-ware Systems RMI and Distributed Components Mar

More information

Message Passing vs. Distributed Objects. 5/15/2009 Distributed Computing, M. L. Liu 1

Message Passing vs. Distributed Objects. 5/15/2009 Distributed Computing, M. L. Liu 1 Message Passing vs. Distributed Objects 5/15/2009 Distributed Computing, M. L. Liu 1 Distributed Objects M. L. Liu 5/15/2009 Distributed Computing, M. L. Liu 2 Message Passing versus Distributed Objects

More information

Course Snapshot. The Next Few Classes

Course Snapshot. The Next Few Classes Course Snapshot We have covered all the fundamental OS components: Architecture and OS interactions Processes and threads Synchronization and deadlock Process scheduling Memory management File systems

More information

Distributed Objects and Remote Invocation. Programming Models for Distributed Applications

Distributed Objects and Remote Invocation. Programming Models for Distributed Applications Distributed Objects and Remote Invocation Programming Models for Distributed Applications Extending Conventional Techniques The remote procedure call model is an extension of the conventional procedure

More information

Communication Basics, RPC & RMI. CS403/534 Distributed Systems Erkay Savas Sabanci University

Communication Basics, RPC & RMI. CS403/534 Distributed Systems Erkay Savas Sabanci University Communication Basics, RPC & RMI CS403/534 Distributed Systems Erkay Savas Sabanci University 1 Communication Models 1. Remote Procedure Call (RPC) Client/Server application 2. Remote Method Invocation

More information

Java Remote Method Invocation Specification

Java Remote Method Invocation Specification Java Remote Method Invocation Specification Java Remote Method Invocation (RMI) is a distributed object model for the Java language that retains the semantics of the Java object model, making distributed

More information

BEA WebLogic. Server. Programming WebLogic RMI

BEA WebLogic. Server. Programming WebLogic RMI BEA WebLogic Server Programming WebLogic RMI Release 8.1 Document Revised: December 5, 2002 Copyright Copyright 2002 BEA Systems, Inc. All Rights Reserved. Restricted Rights Legend This software and documentation

More information

1 OBJECT-ORIENTED PROGRAMMING 1

1 OBJECT-ORIENTED PROGRAMMING 1 PREFACE xvii 1 OBJECT-ORIENTED PROGRAMMING 1 1.1 Object-Oriented and Procedural Programming 2 Top-Down Design and Procedural Programming, 3 Problems with Top-Down Design, 3 Classes and Objects, 4 Fields

More information

Reflection/RMI 4/28/2009

Reflection/RMI 4/28/2009 Reflection/RMI 4/28/2009 1 Opening Discussion Solutions to the interclass problem. Do you have any questions about the assignment? Minute Essays Why are heap operations always O(log n)? Java programs connecting

More information