Prof. Dr.-Ing. habil. B. Steinbach - Informatik / Softwaretechnologie und Programmierungstechnik - Institut für Informatik virtuelle Maschine Verteilte.

Slides:



Advertisements
Similar presentations
CS Network Programming CS 3331 Fall CS 3331 Outline Socket programming Remote method invocation (RMI)
Advertisements

Distributed Objects Remote Method Invokation: Conceptual model.
J0 1 Marco Ronchetti - Basi di Dati Web e Distribuite – Laurea Specialistica in Informatica – Università di Trento.
Prof. Dr.-Ing. habil. B. Steinbach - Informatik / Softwaretechnologie und Programmierungstechnik - Institut für Informatik Verteilte Software - Java -
Technische universität dortmund Service Computing Service Computing Prof. Dr. Ramin Yahyapour IT & Medien Centrum 24. November 2009.
1 Jini Tutorial, Part 3 Jini Programming. 2 Tutorial outline Part 1 Introduction Distributed systems Java basics Remote Method Invocation (RMI) Part 2.
Local vs. distributed Objects Differences between local and distributed objects in: –References (to objects) –Activation/Deactivation –Migration –Persistence.
Remote Method Invocation (RMI) and Distributed Observers in Java
Jini, third verse Richard Chapman October 13, 1999.
Mini project /2 Jini - a new computing paradigm.
Remote method invocation. Introduction First introduced in JDK 1.1. Allows distributed Java programs to work with each others by behaving as if they are.
1 Java Remote Method Invocation java.rmi.* java.rmi.registry.* java.rmi.server.*
RMI Varun SainiYing Chen. What is RMI? RMI is the action of invoking a method of a remote interface on a remote object. It is used to develop applications.
Remote Method Invocation CS587x Lecture Department of Computer Science Iowa State University.
15-May-15 RMI Remote Method Invocation. 2 “The network is the computer” Consider the following program organization: If the network is the computer, we.
Remote Method Invocation in Java Bennie Lewis EEL 6897.
Java Remote Method Invocation (RMI) In Java we implement object systems: O1O2 O3 thread 1thread 2 execution scheme JVM 1JVM 2 distribution scheme.
Java Remote Object Invocation (RMI) Overview of RMI Java RMI allowed programmer to execute remote function class using the same semantics as local functions.
Remote Method Invocation Chin-Chih Chang. Java Remote Object Invocation In Java, the object is serialized before being passed as a parameter to an RMI.
Java RMI. What is RMI? RMI is an RPC system for an object based language. Objects provide a natural granularity for the binding of functions. –RMI allows.
Introduction to Remote Method Invocation (RMI)
Java Remote Object Invocation (RMI) Overview of RMI Java RMI allowed programmer to execute remote function class using the same semantics as local functions.
Java RMI RMI = Remote Method Invocation. Allows Java programs to invoke methods of remote objects. Only between Java programs. Several versions (JDK-1.1,
1 Java Programming II Java Network II (Distributed Objects in Java)
CS 584 Lecture 18 l Assignment » Glenda assignment extended to the Java RMI Deadline » No Java RMI Assignment l Test » Friday, Saturday, Monday.
Presentation: RMI Continued 2 Using The Registry & Callbacks.
UDP vs TCP UDP Low-level, connectionless No reliability guarantee TCP Connection-oriented Not as efficient as UDP.
Java RMI: Remote Method Invocation January 2000 Nancy McCracken Syracuse University.
1 Java RMI G53ACC Chris Greenhalgh. 2 Contents l Java RMI overview l A Java RMI example –Overview –Walk-through l Implementation notes –Argument passing.
Spring/2002 Distributed Software Engineering C:\unocourses\4350\slides\DefiningThreads 1 RMI.
RMI RMI is the java API that facilitate distributed computing by allowing remote method calls. A remote method call represents a method invocation between.
RMI Continued IS Outline  Review of RMI  Programming example.
RMI remote method invocation. Traditional network programming The client program sends data to the server in some intermediary format and the server has.
RMI Remote Method Invocation Distributed Object-based System and RPC Together 2-Jun-16.
Presentation: RMI Continued 2 Using The Registry & Callbacks.
Java Remote Object Invocation (RMI) Overview of RMI Java RMI allowed programmer to execute remote function class using the same semantics as local functions.
Example: RMI Program How to write it.
 Remote Method Invocation  A true distributed computing application interface for Java, written to provide easy access to objects existing on remote.
Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved Chapter 43 Remote Method Invocation.
Fall 2007cs4251 Distributed Computing Umar Kalim Dept. of Communication Systems Engineering 17/10/2007.
Java Remote Method Invocation (RMI) Overview of RMI Java RMI allowed programmer to execute remote function class using the same semantics as local functions.
Remote Method Invocation Instructors: Fu-Chiung Cheng ( 鄭福炯 ) Associate Professor Computer Science & Engineering Tatung University.
Presentation: RMI Continued 2 Using The Registry & Callbacks.
 Java RMI Distributed Systems IT332. Outline  Introduction to RMI  RMI Architecture  RMI Programming and a Sample Example:  Server-Side RMI programming.
Remote Method Invocation A Client Server Approach.
UMBC Distributed Computing with Objects RMI/Corba CMSC 432 Shon Vick.
Java RMI. RMI Any object whose methods can be invoked from another Java VM is called a remote object.
1 Lecture 15 Remote Method Invocation Instructors: Fu-Chiung Cheng ( 鄭福炯 ) Associate Professor Computer Science & Engineering Tatung Institute of Technology.
Distributed programming in Java Faculty:Nguyen Ngoc Tu Session 5 - RMI.
CSC 480 Software Engineering Lab 6 – RMI Nov 8, 2002.
Netprog Java RMI1 Remote Method Invocation.
Using RMI The Example of A Remote Calculator 1. Parts of A Working RMI System A working RMI system is composed of several parts. –Interface definitions.
RMI1 Remote Method Invocation Adapted from “Core Java 2” by Cay Horstmann.
Java Remote Method Invocation (RMI)
Remote Method Invocation
Java RMI (more) CS-328 Internet Programming.
null, true, and false are also reserved.
Creating a Distributed System with RMI
Chapter 40 Remote Method Invocation
Creating a Distributed System with RMI
Remote method invocation (RMI)
Remote Method Invocation
Creating a Distributed System with RMI
Chapter 46 Remote Method Invocation
Using RMI -The Example of A Remote Calculator
Chapter 46 Remote Method Invocation
CS 584 Lecture 18 Assignment Glenda assignment extended to the Java RMI Deadline No Java RMI Assignment Test Friday, Saturday, Monday.
Java Remote Method Invocation
Creating a Distributed System with RMI
Java Chapter 5 (Estifanos Tilahun Mihret--Tech with Estif)
Presentation transcript:

Prof. Dr.-Ing. habil. B. Steinbach - Informatik / Softwaretechnologie und Programmierungstechnik - Institut für Informatik virtuelle Maschine Verteilte Software - Java - RMI 1 Objekt 2Objekt 1 lokaler Methodenaufruf Methodenaufruf virtuelle Maschine Objekt 2Objekt 1 entfernter Methodenaufruf Methodenaufruf RMI RMI Architektur ClientServer Netzwerkschicht Server-Stub (proxy) Remote Ref. Schicht Transport Schicht Remote Ref. Schicht Transport Schicht Skeleton Methodenaufruf

Prof. Dr.-Ing. habil. B. Steinbach - Informatik / Softwaretechnologie und Programmierungstechnik - Institut für Informatik Verteilte Software - Java - RMI 2 java.rmi.Server.UnicastRemoteObject > RMIDemoServer > java.rmi.Remote RMIDemoServerImplementation RMIDemoClient +int countString() > +main() +int countString() import java.rmi.*; public interface RMIDemoServer extends Remote { // remote ausführbare Methode des DemoServers int countString(String str) throws RemoteException; }

Prof. Dr.-Ing. habil. B. Steinbach - Informatik / Softwaretechnologie und Programmierungstechnik - Institut für Informatik Verteilte Software - Java - RMI 3 import java.rmi.*; import java.net.*; import java.rmi.server.*; public class RMIDemoServerImplementation extends UnicastRemoteObject implements RMIDemoServer { public RMIDemoServerImplementation() throws RemoteException { try { Naming.rebind("rmi:///DemoServer", this); System.out.println("Server gebunden"); } catch (MalformedURLException e) { // bei falscher URL System.out.println("URL falsch: " + e.getMessage() ) } public int countString(String s) { System.out.println(s); return s.length(); } public static void main(String[] args) { try { RMIDemoServerImplementation server = new RMIDemoServerImplementation(); } catch (RemoteException e) { System.out.println("Fehler beim Instanziieren von: " + e.getMessage() ); } }

Prof. Dr.-Ing. habil. B. Steinbach - Informatik / Softwaretechnologie und Programmierungstechnik - Institut für Informatik Verteilte Software - Java - RMI 4 import java.rmi.*; import java.net.*; public class RMIDemoClient { public static void main(String[] args) { int zeichenanzahl; String s; if (args.length != 1) s = "Aufruf mit java RMIDemoClient \"Zeichenkette\""; else s = args[0]; try { // Server in Registry suchen RMIDemoServer server = (RMIDemoServer)Naming.lookup("rmi:///DemoServer"); if(args.length != 1) System.out.println(s); //Servermethode ausführen zeichenanzahl = server.countString(s); System.out.println("Anzahl der Zeichen: " + zeichenanzahl); } catch (NotBoundException e) { System.out.println("Server nicht gebunden: " + e.getMessage() ); } catch (MalformedURLException e) { System.out.println("URL ungültig: " + e.getMessage() ); } catch (RemoteException e) { System.out.println("Fehler bei der Kommunikation: " + e.getMessage() ); } }

Prof. Dr.-Ing. habil. B. Steinbach - Informatik / Softwaretechnologie und Programmierungstechnik - Institut für Informatik virtuelle Maschine Verteilte Software - Java - RMI 5 import java.io.*; public class Aufgabe implements Serializable { double op1; // erster Operand double op2; // zweiter Operand char opz; // Operatoionszeichen public void setOp1(double v) { op1 = v; } public void setOp2(double v) { op2 = v; } public void setOpz(char c) { opz = c; } public double getOp1() { return op1; } public double getOp2() { return op2; } public char getOpz() { return opz; } } virtuelle Maschine ClientServer Objekt a Object by Value

Prof. Dr.-Ing. habil. B. Steinbach - Informatik / Softwaretechnologie und Programmierungstechnik - Institut für Informatik Verteilte Software - Java - RMI 6 import java.rmi.*; import java.net.*; import java.rmi.server.*; public class RMITRServerImplementation extends UnicastRemoteObject implements RMITRServer { public RMITRServerImplementation() throws RemoteException { try { Naming.rebind("rmi:///TRServer", this); System.out.println("TRServer gebunden"); } catch (MalformedURLException e) { // bei falscher URL System.out.println("URL falsch: " + e.getMessage() ); } import java.rmi.*; public interface RMITRServer extends Remote { // remote ausführbare Methode des DemoServers double solve(Aufgabe aufg) throws RemoteException; }

Prof. Dr.-Ing. habil. B. Steinbach - Informatik / Softwaretechnologie und Programmierungstechnik - Institut für Informatik Verteilte Software - Java - RMI 7 public double solve(Aufgabe a) { double result; System.out.println("Aufgabe: " + a.getOp1() + a.getOpz() + a.getOp2()); switch(a.getOpz()) { case '+': result = a.getOp1() + a.getOp2(); break; case '-': result = a.getOp1() - a.getOp2(); break; case '*': result = a.getOp1() * a.getOp2(); break; case '/': result = a.getOp1() / a.getOp2(); break; case '%': result = a.getOp1() % a.getOp2(); break; default: result = 0.0; } return result; } public static void main(String[] args) { try { RMITRServerImplementation server = new RMITRServerImplementation(); } catch (RemoteException e) { System.out.println("Fehler beim Instanziieren von: " + e.getMessage() ); }

Prof. Dr.-Ing. habil. B. Steinbach - Informatik / Softwaretechnologie und Programmierungstechnik - Institut für Informatik Verteilte Software - Java - RMI 8 import java.rmi.*; import java.net.*; import java.util.*; public class RMITRClient { public static void main(String[] args) { Aufgabe a = new Aufgabe(); double ergebnis; if (args.length != 1) System.out.println("Aufruf mit java RMITRClient \"Aufgabe (z.B. 1.2 * 3.4)\""); else try { // Server in Registry suchen RMITRServer server = (RMITRServer)Naming.lookup("rmi:///TRServer"); // parse task StringTokenizer st = new StringTokenizer(args[0], "+-*/%", true); if( st.hasMoreTokens()) a.setOp1(new Double(st.nextToken()).doubleValue()); if( st.hasMoreTokens()) a.setOpz(st.nextToken().charAt(0)); if( st.hasMoreTokens()) a.setOp2(new Double(st.nextToken()).doubleValue()); //Servermethode ausführen ergebnis = server.solve(a); System.out.println(args[0] + " = " + ergebnis); }

Prof. Dr.-Ing. habil. B. Steinbach - Informatik / Softwaretechnologie und Programmierungstechnik - Institut für Informatik Verteilte Software - Java - RMI 9 catch (NumberFormatException e) { System.out.println("Eingabeformat falsch in: " + e.getMessage() ); } catch (NotBoundException e) { System.out.println("Server nicht gebunden: " + e.getMessage() ); } catch (MalformedURLException e) { System.out.println("URL ungültig: " + e.getMessage() ); } catch (RemoteException e) { System.out.println("Fehler bei der Kommunikation: " + e.getMessage() ); } Ausnahmen im RMITRClient

Prof. Dr.-Ing. habil. B. Steinbach - Informatik / Softwaretechnologie und Programmierungstechnik - Institut für Informatik Server Computer virtuelle Maschine Verteilte Software - Java - RMI 10 Server Client Computer virtuelle Maschine Client virtuelle Maschine RMI- Registry 1. bind() 2. lookup() 3. Stub-Objekt (codebase) WWW-Server Computer WWW- Server / codebase 4. download Stub-Klasse

Prof. Dr.-Ing. habil. B. Steinbach - Informatik / Softwaretechnologie und Programmierungstechnik - Institut für Informatik Verteilte Software - Java - RMI 11 import java.rmi.*; import java.net.*; import java.rmi.server.*; public class RMIServerImplementation extends UnicastRemoteObject implements RMIServer { public RMIServerImplementation(String host) throws RemoteException { System.setSecurityManager(new RMISecurityManager()); String name = "rmi://" + host + "/Server"; try { Naming.rebind(name, this); System.out.println("Server gebunden"); } catch (MalformedURLException e) { // bei falscher URL System.out.println("URL falsch: " + e.getMessage() ); } import java.rmi.*; public interface RMIServer extends Remote { // remote ausführbare Methode des DemoServers int countString(String str) throws RemoteException; }

Prof. Dr.-Ing. habil. B. Steinbach - Informatik / Softwaretechnologie und Programmierungstechnik - Institut für Informatik Verteilte Software - Java - RMI 12 public int countString(String s) { System.out.println(s); return s.length(); } public static void main(String[] args) { try { RMIServerImplementation server = new RMIServerImplementation(args[0]); } catch (RemoteException e) { System.out.println("Fehler beim Instanziieren von: " + e.getMessage() ); } grant { permission java.security.AllPermission "", ""; }; policy.all

Prof. Dr.-Ing. habil. B. Steinbach - Informatik / Softwaretechnologie und Programmierungstechnik - Institut für Informatik Verteilte Software - Java - RMI 13 import java.rmi.*; import java.net.*; public class RMIClient { public static void main(String[] args) { int zeichenanzahl; String s; if (args.length != 2) { s = "Aufruf mit java RMIClient "; s += "-Djava.security.policy=policy.all host \"Zeichenkette\""; } else s = args[1]; System.setSecurityManager(new RMISecurityManager()); try { // Server in Registry suchen RMIServer server = (RMIServer)Naming.lookup("rmi://" + args[0] + "/Server"); if (args.length != 1) System.out.println(s); //Servermethode ausführen zeichenanzahl = server.countString(s); System.out.println("Anzahl der Zeichen: " + zeichenanzahl); } catch (NotBoundException e) { System.out.println("Server nicht gebunden: " + e.getMessage() ); } catch (MalformedURLException e) { System.out.println("URL ungültig: " + e.getMessage() ); } catch (RemoteException e) { System.out.println("Fehler bei der Kommunikation: " + e.getMessage() ); } catch (Exception e) { System.out.println("sonstiger Fehler bei: "); e.printStackTrace(); } }

Prof. Dr.-Ing. habil. B. Steinbach - Informatik / Softwaretechnologie und Programmierungstechnik - Institut für Informatik Verteilte Software - Java - RMI 14 RMIServer.class RMIServerImplementation.class RMIServerImplementation_Stub.class RMIServerImplementation_Skel.class policy.all RMIServer.class RMIClient.class policy.all RMIServer.class RMIServerImplementation_Stub.class server client codebase