Lesson 3 Remote Method Invocation (RMI) Mixing RMI and sockets Rethinking out tic-tac-toe game.

Slides:



Advertisements
Similar presentations
Message Passing Vs Distributed Objects
Advertisements

What is RMI? Remote Method Invocation –A true distributed computing application interface for Java, written to provide easy access to objects existing.
Remote Method Invocation (RMI) Mixing RMI and sockets
1 Chapter 9 Network Programming. 2 Overview Java has rich class libraries to support network programming at various levels. There are standard classes.
Copyright © 2001 Qusay H. Mahmoud RMI – Remote Method Invocation Introduction What is RMI? RMI System Architecture How does RMI work? Distributed Garbage.
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.
Advanced Programming Rabie A. Ramadan Lecture 4. A Simple Use of Java Remote Method Invocation (RMI) 2.
Java Remote Method Invocation (RMI) In Java we implement object systems: O1O2 O3 thread 1thread 2 execution scheme JVM 1JVM 2 distribution scheme.
Remote Method Invocation
FONG CHAN SING (143334) WONG YEW JOON (143388). JAVA RMI is a distributive system programming interface introduced in JDK 1.1. A library that allows an.
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.
Advanced Java Class Network Programming. Network Protocols Overview Levels of Abstraction –HTTP protocol: spoken by Web Servers and Web Clients –TCP/IP:
Sockets  Defined as an “endpoint for communication.”  Concatenation of IP address + port.  Used for server-client communication.  Server waits for.
EEC-681/781 Distributed Computing Systems Lecture 5 Wenbing Zhao Department of Electrical and Computer Engineering Cleveland State University
EEC-681/781 Distributed Computing Systems Lecture 5 Wenbing Zhao Department of Electrical and Computer Engineering Cleveland State University
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.
How Does Remote Method Invocation Work? –Systems that use RMI for communication typically are divided into two categories: clients and servers. A server.
Java RMI RMI = Remote Method Invocation. Allows Java programs to invoke methods of remote objects. Only between Java programs. Several versions (JDK-1.1,
Java RMI Essentials Based on Mastering RMI Rickard Oberg.
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.
+ A Short Java RMI Tutorial Usman Saleem
Cli/Serv.: rmiCORBA/131 Client/Server Distributed Systems v Objectives –introduce rmi and CORBA , Semester 1, RMI and CORBA.
15 - RMI. Java RMI Architecture Example Deployment RMI is a part of J2SE (standard edition), but is used by J2EE) A J2EE server is not nessesary for using.
Presentation: RMI Continued 2 Using The Registry & Callbacks.
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.
Java Remote Method Invocation RMI. Idea If objects communicate with each other on one JVM why not do the same on several JVM’s? If objects communicate.
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.
Distributed Objects and Middleware. Sockets and Ports Source: G. Coulouris et al., Distributed Systems: Concepts and Design.
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  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.
Java Programming: Advanced Topics 1 Networking Programming Chapter 11.
Li Tak Sing COMPS311F. RMI callbacks In previous example, only the client can initiate a communication with the server. The server can only response to.
Java Remote Method Invocation (RMI) Overview of RMI Java RMI allowed programmer to execute remote function class using the same semantics as local functions.
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.
Remote Method Invocation RMI architecture stubs and skeletons for remote services RMI server and client in Java Creating an RMI Application step-by- step.
Java RMI. RMI Any object whose methods can be invoked from another Java VM is called a remote object.
1 RMI Russell Johnston Communications II. 2 What is RMI? Remote Method Invocation.
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.
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.
Liang, Introduction to Java Programming, Fifth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 29 Remote Method.
Remote Method Invocation Internet Computing Workshop Lecture 17.
Java Distributed Computing
Java Distributed Computing
Java Remote Method Invocation (RMI)
Remote Method Invocation
Java RMI CS-328 Internet Programming.
What is RMI? Remote Method Invocation
Remote Method Invocation
Lesson 3 Remote Method Invocation (RMI) Mixing RMI and sockets
Network and Distributed Programming in Java
Lecture 4: RPC Remote Procedure Call Coulouris et al: Chapter 5
Chapter 40 Remote Method Invocation
Lecture 4: RPC Remote Procedure Call CDK: Chapter 5
Chapter 46 Remote Method Invocation
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
Presentation transcript:

Lesson 3 Remote Method Invocation (RMI) Mixing RMI and sockets Rethinking out tic-tac-toe game

Distributed Objects  Simple idea – objects existing on one machine (server) may be accessed from another machine through regular method call.  Eliminates need to “marshal” and “unmarshal” data sent over sockets  Underlying socket code still exists, but is not programmed by user.

RMI vs. CORBA  RMI is Java framework for creating distributed object applications – Remote Method Invocation  CORBA is alternative technology based on open standard – Common Object Request Broker Architecture  RMI is only for pure Java applications; CORBA is language independent  JNI makes this distinction a little less rigid since it allows Java to interact with other languages

Socket flow of events -- synchronous Await client message … Receive client message Decode client message Perform action Create client message Send to client Get user input Decode user input Create server message Send message to server Await server response … Receive server message Decode reply Send output to user Client Server Method call on standalone object

Socket flow - asynchronous Wait … Receive client msg Decode client msg Perform action Create client message Send to client1 Send to client2 User input (UI) Decode UI Create srvr msg Send srvr msg Await srvr reply … Receive server message Decode reply Output to user Client1 Server User input (UI) Decode UI Create srvr msg Send srvr msg Await srvr reply … Receive server message Decode reply Output to user Client2

RMI flow of events -- synchronous Instantiate object(s) Bind to registry … Get/cache remote obj ref Get user input Decode user input Remote method call Decode return value Send output to user Client Server

RMI Cartoon1

RMI Cartoon2

Steps for RMI Application  Implement both client and server on single machine to test  Create two directories –client –server

RMI steps, server side  Three files need to be created: –The implementation class (Foo.java) –An interface listing the methods in the implementation class which you want to make remote (FooInterface.java) –A server class, which creates one or more implementation objects and posts them to the registry (FooServer.java)

Creating the interface  Interface file (e.g. StoreInterface.java) –StoreInterface must extend java.rmi.Remote –All methods in interface must throw java.rmi.RemoteException  Implementation file (e.g Store.java) –Store must extend java.rmi.server.UnicastRemoteObject –Store must implement StoreInterface –Program implementations. Be sure to throw RemoteException in remote methods –Explicitly include a null construct that calls super()

Creating Stubs  The stub or proxy code is generated automatically by using the rmic utility.  Once the interface and implementation classes are complete, generate the stubs as follows: rmic –v1.2 Store This creates Store_Stub.java – the java networking layer that transparently handles the underlying message passing.

Creating the server class  Server class (e.g. StoreServer.java) –Create a new object instance –Call java.rmi.Naming.bind(…) to store the register the object with the naming service –… contains String name associated with bound object

Steps for RMI, cont.  Create the client –Change to the client dir and copy Store.class and Store_Stub.class (or you can import them but remember that these will ultimately be on different machines). –Create StoreClient.java and import: java.rmi.Naming; java.rmi.RemoteException; java.net.MalformedURLException; java.rmi.NotBoundException;

Steps for rmi, cont. –Call Naming.lookup() to get remote object reference (be sure to cast to interface type). –Be sure to handle imported exceptions –Once you get remote object reference, handle as regular object (there are some subtle differences that we’ll explore later).

Deploying the Application  Start the rmiregistry –rmiregistry & (Unix) –start rmiregistry (Windows)  Start the StoreServer class –java StoreServer & (Unix)  Run the client  That’s it!

Additional Issues – covered next time  Objects which are not remote are copied (slow!)  Stub and interface codes can be downloaded by client (typical for real distributed systems)  Security issues in real system (see ch. 5 in Core Java 2)  Subtleties with Object methods (clone, etc)  Using callbacks with RMI  Synchronization  Registering multiple objects  Bottom Line: Don’t be too fancy!

Examples  tic-tac-toe reorganized as standalone back- end object  single-threaded test of TTT object  multithreaded test of TTT object using polling  client-server TTT using RMI and polling  client-server TTT using RMI over sockets  client-server TTT using RMI callbacks.