CSCE 515: Computer Network Programming Chin-Tser Huang University of South Carolina.

Slides:



Advertisements
Similar presentations
COS 461 Fall 1997 Network Objects u first good implementation: DEC SRC Network Objects for Modula-3 u recent implementation: Java RMI (Remote Method Invocation)
Advertisements

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.
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.
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
CSCE 515: Computer Network Programming Chin-Tser Huang University of South Carolina.
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.
CSCE 515: Computer Network Programming Chin-Tser Huang University of South Carolina.
EEC-681/781 Distributed Computing Systems Lecture 5 Wenbing Zhao Department of Electrical and Computer Engineering Cleveland State University
CSCE 515: Computer Network Programming Chin-Tser Huang University of South Carolina.
Introduction to Remote Method Invocation (RMI)
Netprog 2002 Java RMI1 Remote Method Invocation Part II Based on Java Network Programming and Distributed Computing Chapter 11 Also based on Sun’s Online.
Java Remote Object Invocation (RMI) Overview of RMI Java RMI allowed programmer to execute remote function class using the same semantics as local functions.
CSCE 515: Computer Network Programming Chin-Tser Huang University of South Carolina.
CSCE 515: Computer Network Programming Chin-Tser Huang University of South Carolina.
CSCE 515: Computer Network Programming Chin-Tser Huang University of South Carolina.
CSCE 515: Computer Network Programming Chin-Tser Huang University of South Carolina.
Internet Software Development Remote Method Invocation Paul Krause.
Java RMI Essentials Based on Mastering RMI Rickard Oberg.
1 Java Programming II Java Network II (Distributed Objects in Java)
Silberschatz, Galvin and Gagne  2002 Modified for CSCI 399, Royden, Operating System Concepts Operating Systems Lecture 12 Communicating over.
CSCE 515: Computer Network Programming Chin-Tser Huang University of South Carolina.
+ A Short Java RMI Tutorial Usman Saleem
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.
School of Engineering and Computer Science Victoria University of Wellington Copyright: Peter Andreae david streader, VUW Echo Networking COMP
LAB 1CSIS04021 Briefing on Assignment One & RMI Programming February 13, 2007.
Java RMI: Remote Method Invocation January 2000 Nancy McCracken Syracuse University.
Spring/2002 Distributed Software Engineering C:\unocourses\4350\slides\DefiningThreads 1 RMI.
CSCE 515: Computer Network Programming Chin-Tser Huang University of South Carolina.
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 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.
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.
Fall 2007cs4251 Distributed Computing Umar Kalim Dept. of Communication Systems Engineering 17/10/2007.
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.
1 Java Remote Method Invocation java.rmi.* java.rmi.registry.* java.rmi.server.*
Creating Applications Using RMI Lesson 1B / Slide 1 of 19 Network and Distributed Programming in Java Pre-assessment Questions 1.Which of the following.
 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 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.
Li Tak Sing COMPS311F. Case study: a multithreaded chat server The source contains 3 files: ChatServer //the chat server ChatThread //the thread on the.
Netprog Java RMI1 Remote Method Invocation.
import java.io.*; public class Customer implements Serializable { public Customer(int theAge, int theSex, String[] theHobbies) { age = theAge; sex.
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.
School of Engineering and Computer Science Victoria University of Wellington Copyright: Peter Andreae david streader, VUW Echo Networking COMP
Distributed Web Systems Distributed Objects and Remote Method Invocation Lecturer Department University.
RMI Packages Overview java.rmi java.rmi.server java.rmi.registry
Remote Method Invocation
Remote Method Invocation
Chapter 40 Remote Method Invocation
Remote method invocation (RMI)
Overview of RMI Architecture
Chapter 46 Remote Method Invocation
Chapter 46 Remote Method Invocation
Java Remote Method Invocation
Overview of RMI Architecture
Java Chapter 5 (Estifanos Tilahun Mihret--Tech with Estif)
Presentation transcript:

CSCE 515: Computer Network Programming Chin-Tser Huang University of South Carolina

4/7/20052 Class RemoteObject Ultimate superclass of all remote objects Override hashCode(), equals(), toString() to reflect correct semantics of a remote object Implement interface Serializable to ensure correct serialization of remote objects

4/7/20053 Remote Objects as Parameters When a remote object implementation is sent as a parameter to a remote method call, a remote reference to the remote object, instead of a copy of remote object, is what is really sent When remote method calls method on the received remote object, further RMI calls will be made to the original remote object implementation

4/7/20054 Example of Remote Object Parameters public class MyImpl extends UnicastRemoteObject implements MyRemote { // … public static void main (String[] args) throws Exception { MyImpl mine = new MyImpl (); HisRemote his = (HisRemote) Naming.lookup (“//server/his”); his.invoke (mine); } public void invoke (Object object) throws RemoteException;  public void invoke (MyRemote remote) throws RemoteException;  public void invoke (MyImpl impl) throws RemoteException;X

4/7/20055 Class RemoteServer A subclass of RemoteObject Provide common functions for remote objects to be implemented as servers Static methods String getClientHost() throws ServerNotActiveException void setLog(OutputStream out) PrintStream getLog()

4/7/20056 Class UnicastRemoteObject Subclass of RemoteServer Superclass of most normal remote objects

4/7/20057 Class UnicastRemoteObject Constructors protected UnicastRemoteObject() throws RemoteException protected UnicastRemoteObject(int port) throws RemoteException protected UnicastRemoteObject(int port, RMIClientSocketFactory clients, RMIServerSocketFactory servers) throws RemoteException Static methods RemoteStub exportObject(Remote object) throws RemoteException RemoteStub exportObject(Remote object, int port) throws RemoteException RemoteStub exportObject(Remote object, int port, RMIClientSocketFactory clients, RMIServerSocketFactory servers) throws RemoteException boolean unexportObject(Remote object, boolean force) throws NoSuchObjectException

4/7/20058 Class RemoteStub Superclass for all remote stub classes Proxy all of remote methods into remote method calls on actual remote object implementation by connecting to and communicating with skeleton

4/7/20059 Interface Unreferenced RMI maintains a count of #references that exists to each remote object User code can use this interface to work with garbage collection mechanism Method void unreferenced()

4/7/ Class RMISocketFactory Static methods void setSocketFactory(RMISocketFactory factory) throws IOException RMISocketFactory getSocketFactory() RMISocketFactory getDefaultSocketFactory() void setFailureHandler(RMIFailureHandler failureHandler) RMIFailureHandler getFailureHandler() Methods abstract Socket createSocket(String host, int port) throws IOException abstract Socket createServerSocket(int port) throws IOException

4/7/ Interface RMIClientSocketFactory Describe a client-side socket factory Implement a per-object custom socket factory Method Socket createSocket(String host, int port) throws IOException

4/7/ Interface RMIServerSocketFactory Describe a server-side socket factory Implement a per-object custom socket factory Method Socket createServerSocket(int port) throws IOException

4/7/ Interface RMIFailureHandler A class that attempts to resolve the cause of RMI socket exception and correct it Method boolean failure(Exception ex)

4/7/ An RMI Chat Example An RMI-based client/server chat system Define remote interface RMIChatServer Server class RMIChatServerImpl accepts new messages and queries from client through interface RMIChatServer Client class RMIChatClient sends messages to server and uses an update thread to periodically query server

4/7/ Interface RMIChatServer /* Java Network Programming, Second Edition * Merlin Hughes, Michael Shoffner, Derek Hamner * Manning Publications Company; ISBN X * * * * Copyright (c) Merlin Hughes, Michael Shoffner, Derek Hamner; * all rights reserved; see license.txt for details. */ import java.rmi.*; public interface RMIChatServer extends Remote { public static final String REGISTRY_NAME = "Chat Server"; public abstract String[] getMessages (int index) throws RemoteException; public abstract void addMessage (String message) throws RemoteException; }

4/7/ Class RMIChatServerImpl /* Java Network Programming, Second Edition * Merlin Hughes, Michael Shoffner, Derek Hamner * Manning Publications Company; ISBN X * * * * Copyright (c) Merlin Hughes, Michael Shoffner, Derek Hamner; * all rights reserved; see license.txt for details. */ import java.rmi.*; import java.util.*; import java.rmi.server.*; import java.rmi.registry.*; public class RMIChatServerImpl extends UnicastRemoteObject implements RMIChatServer { // public RMIChatServerImpl () throws RemoteException … // public String[] getMessages (int index) … // public void addMessage (String message) … // public static void main (String[] args) throws RemoteException … }

4/7/ Methods of RMIChatServerImpl protected Vector messages; public RMIChatServerImpl () throws RemoteException { messages = new Vector (); } public String[] getMessages (int index) { int size = messages.size (); String[] update = new String[size - index]; for (int i = 0; i < size - index; ++ i) update[i] = (String) messages.elementAt (index + i); return update; } public void addMessage (String message) { messages.addElement (message); } public static void main (String[] args) throws RemoteException { RMIChatServerImpl chatServer = new RMIChatServerImpl (); Registry registry = LocateRegistry.getRegistry (); registry.rebind (REGISTRY_NAME, chatServer); }

4/7/ Class RMIChatClient /* Java Network Programming, Second Edition * Merlin Hughes, Michael Shoffner, Derek Hamner * Manning Publications Company; ISBN X * * * * Copyright (c) Merlin Hughes, Michael Shoffner, Derek Hamner; * all rights reserved; see license.txt for details. */ import java.awt.*; import java.rmi.*; import java.awt.event.*; import java.rmi.registry.*; public class RMIChatClient implements Runnable, ActionListener { protected static final int UPDATE_DELAY = 10000; // public RMIChatClient (String host) … // public synchronized void start () throws RemoteException, NotBoundException … // public synchronized void stop () … // public void run () … // public void actionPerformed (ActionEvent ev) … // public static void main (String[] args) throws RemoteException, NotBoundException … }

4/7/ Constructor RMIChatClient protected String host; protected Frame frame; protected TextField input; protected TextArea output; public RMIChatClient (String host) { this.host = host; frame = new Frame ("RMIChatClient [" + host + "]"); frame.add (output = new TextArea (), "Center"); output.setEditable (false); frame.add (input = new TextField (), "South"); input.addActionListener (this); frame.addWindowListener (new WindowAdapter () { public void windowOpened (WindowEvent ev) { input.requestFocus (); } public void windowClosing (WindowEvent ev) { stop (); } }); frame.pack (); }

4/7/ Methods start and stop protected RMIChatServer server; protected Thread updater; public synchronized void start () throws RemoteException, NotBoundException { if (updater == null) { Registry registry = LocateRegistry.getRegistry (host); server = (RMIChatServer) registry.lookup (RMIChatServer.REGISTRY_NAME); updater = new Thread (this); updater.start (); frame.setVisible (true); } public synchronized void stop () { if (updater != null) { updater.interrupt (); updater = null; server = null; } frame.setVisible (false); }

4/7/ Method run public void run () { try { int index = 0; while (!Thread.interrupted ()) { String[] messages = server.getMessages (index); int n = messages.length; for (int i = 0; i < n; ++ i) output.append (messages[i] + "\n"); index += n; Thread.sleep (UPDATE_DELAY); } } catch (InterruptedException ignored) { } catch (RemoteException ex) { input.setVisible (false); frame.validate (); ex.printStackTrace (); }

4/7/ Method actionPerformed public void actionPerformed (ActionEvent ev) { try { RMIChatServer server = this.server; if (server != null) server.addMessage (ev.getActionCommand ()); input.setText (""); } catch (RemoteException ex) { Thread tmp = updater; updater = null; if (tmp != null) tmp.interrupt (); input.setVisible (false); frame.validate (); ex.printStackTrace (); }

4/7/ Method main public static void main (String[] args) throws RemoteException, NotBoundException { if (args.length != 1) throw new IllegalArgumentException ("Syntax: RMIChatClient "); RMIChatClient chatClient = new RMIChatClient (args[0]); chatClient.start (); }

4/7/ Disadvantages of Example Waste of resources during idle periods Late updates during active periods Dynamically increasing delay during idle periods and decreasing delay during active periods is not good enough Alternative solution is callback mechanism

4/7/ Next Class More examples of RMI in practice Read JNP Ch. 24 Project 5 will be passed out