Java Chapter 5 (Estifanos Tilahun Mihret--Tech with Estif)

Slides:



Advertisements
Similar presentations
Remote Method Invocation CS587x Lecture Department of Computer Science Iowa State University.
Advertisements

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.
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.
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
Company LOGO Remote Method Invocation Georgi Cholakov, Emil Doychev, University of Plovdiv “Paisii.
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:
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.
CSCE 515: Computer Network Programming Chin-Tser Huang University of South Carolina.
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
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.
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.
Remote Method Invocation onlineTraining/rmi/RMI.html.
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.
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.
Distributed Software Engineering Lecture 3 Middleware Solutions Cont. Sam Malek SWE 622, Fall 2012 George Mason University.
 Java RMI Distributed Systems IT332. Outline  Introduction to RMI  RMI Architecture  RMI Programming and a Sample Example:  Server-Side RMI programming.
Florida State UniversityCOP Advanced Unix Programming Remote Method Invocation /rmi/index.html.
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.
Khoa CNTT 1/37 PHẠM VĂN TÍNH   Java RMI (Remote Method Invocation)
1 Lecture 15 Remote Method Invocation Instructors: Fu-Chiung Cheng ( 鄭福炯 ) Associate Professor Computer Science & Engineering Tatung Institute of Technology.
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.
Distributed Web Systems Distributed Objects and Remote Method Invocation Lecturer Department University.
Remote Method Invocation Internet Computing Workshop Lecture 17.
Java Distributed Computing
Java Remote Method Invocation (RMI)
Principles of Software Development
Java Distributed Computing
Java Remote Method Invocation (RMI)
RMI Packages Overview java.rmi java.rmi.server java.rmi.registry
Remote Method Invocation
What is RMI? Remote Method Invocation
Remote Method Invocation
Advanced Remote Method Invocations
Java RMI (more) CS-328 Internet Programming.
Network and Distributed Programming in Java
Creating a Distributed System with RMI
Creating a Distributed System with RMI
Overview of RMI Architecture
Remote Method Invocation
Creating a Distributed System with RMI
Using RMI -The Example of A Remote Calculator
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
Overview of RMI Architecture
Presentation transcript:

Advanced Programming Estifanos T. (MSc in Computer Networking)

CHAPTER FIVE Remote Method Invocation (RMI) Estifanos T. (MSc in Computer Networking)

Objectives 3 Lecture 5: Remote Method Invocation (RMI) 9/10/2019 Estifanos T. (MSc in Computer Networking) To overview the Concept of RMI To explain the RMI Registry To describe the Remote Interface To demonstrate How to Implement RMI

“The Network is the Computer” 4 9/10/2019 Estifanos T. (MSc in Computer Networking) Lecture 5: Remote Method Invocation (RMI) Consider the following program organization: If the network is the computer, we ought to be able to put the two classes on different computers RMI is a suit technology that makes this possible SomeClass AnotherClass Method Call Returned Object Computer 1Computer 2

What is Needed for RMI 5 9/10/2019 Estifanos T. (MSc in Computer Networking) Lecture 5: Remote Method Invocation (RMI) To send a message to a remote “server object,” The “client object” has to find the object Do this by looking it up in a registry The client object then has to marshal the parameters (prepare them for transmission) Java requires Serializable parameters The server object has to unmarshal its parameters, do its computation, and marshal its response The client object has to unmarshal the response Much of this is done for you by special software

Terminology 6 9/10/2019 Estifanos T. (MSc in Computer Networking) Lecture 5: Remote Method Invocation (RMI) A remote object is an object on another computer The client object is the object making the request (sending a message to the other object) The server object is the object receiving the request As usual, “client” and “server” can easily trade roles (each can make requests of the other) The rmiregistry is a special server that looks up objects by name rmic is a special compiler for creating stub (client) and skeleton (server) classes

Processes 7 9/10/2019 Estifanos T. (MSc in Computer Networking) Lecture 5: Remote Method Invocation (RMI) For RMI, we need to be running three processes The Client The Server The Object Registry, rmiregistry, which is like a DNS service for objects We also need TCP/IP active

Interfaces 8 9/10/2019 Estifanos T. (MSc in Computer Networking) Lecture 5: Remote Method Invocation (RMI) Interfaces define behavior Classes define implementation Therefore, In order to use a remote object, the client must know its behavior (interface), but does not need to know its implementation (class) In order to provide an object, the server must know both its interface (behavior) and its class (implementation) In short, The interface must be available to both client and server The class of any transmitted object must be on both client and server The class whose method is being used should only be on the server

Classes 9 9/10/2019 Estifanos T. (MSc in Computer Networking) Lecture 5: Remote Method Invocation (RMI) A Remote class is one whose instances can be accessed remotely On the computer where it is defined, instances of this class can be accessed just like any other object On other computers, the remote object can be accessed via object handles A Serializable class is one whose instances can be marshaled (turned into a linear sequence of bits) Serializable objects can be transmitted from one computer to another It probably isn’t a good idea for an object to be both remote and serializable

Conditions for Serializability 10 9/10/2019 Estifanos T. (MSc in Computer Networking) Lecture 5: Remote Method Invocation (RMI) If an object is to be serialized: The class must be declared as public The class must implement Serializable However, Serializable does not declare any methods The class must have a no-argument constructor All fields of the class must be serializable: either primitive types or Serializable objects Exception: Fields marked transient will be ignored during serialization

Remote Interfaces and Class 11 9/10/2019 Estifanos T. (MSc in Computer Networking) Lecture 5: Remote Method Invocation (RMI) A Remote class has two parts: The interface (used by both client and server): Must be public Must extend the interface java.rmi.Remote Every method in the interface must declare that it throws java.rmi.RemoteException (other exceptions may also be thrown) The class itself (used only by the server): Must implement the Remote interface Should extend java.rmi.server.UnicastRemoteObject May have locally accessible methods that are not in its Remote interface

Remote and Serializable 12 9/10/2019 Estifanos T. (MSc in Computer Networking) Lecture 5: Remote Method Invocation (RMI) A Remote object lives on another computer (such as the Server) You can send messages to a Remote object and get responses back from the object All we need to know about the Remote object is its interface Remote objects don’t pose much of a security issue We can transmit a copy of a Serializable object between computers The receiving object needs to know how the object is implemented; it needs the class as well as the interface There is a way to transmit the class definition Accepting classes does pose a security issue

Security 13 9/10/2019 Estifanos T. (MSc in Computer Networking) Lecture 5: Remote Method Invocation (RMI) It isn’t safe for the client to use somebody else’s code on some random server System.setSecurityManager(new RMISecurityManager()); The security policy of RMISecurityManager is the same as that of the default SecurityManager Our client program should use a more conservative security manager than the default Most discussions of RMI assume we should do this on both the client and the server Unless our server also acts as a client, it isn’t really necessary on the server

The Server Class 14 9/10/2019 Estifanos T. (MSc in Computer Networking) Lecture 5: Remote Method Invocation (RMI) The class that defines the server object should extend UnicastRemoteObject This makes a connection with exactly one other computer If we must extend some other class, we can use exportObject() instead Sun does not provide a MulticastRemoteObject class The server class needs to register its server object: String url = "rmi://" + host + ":" + port + "/" + objectName; The default port is 1099 Naming.rebind(url, object); Every remotely available method must throw a RemoteException (because connections can fail) Every remotely available method should be synchronized

Demo - API 15 9/10/2019 Estifanos T. (MSc in Computer Networking) Lecture 5: Remote Method Invocation (RMI) package com.dt.project.api; import java.rmi.Remote; import java.rmi.RemoteException; public interface LuckyNumber extends Remote { String process(String value) throws RemoteException; String process(String value) throws RemoteException; }

Demo – Client Side 16 9/10/2019 Estifanos T. (MSc in Computer Networking) Lecture 5: Remote Method Invocation (RMI) package com.dt.project.client; import com.dt.project.api.LuckyNumber; import java.rmi.NotBoundException; import java.rmi.RemoteException; import java.rmi.registry.LocateRegistry; import java.rmi.registry.Registry; import java.util.Scanner;

Demo – Client Side 17 9/10/2019 Estifanos T. (MSc in Computer Networking) Lecture 5: Remote Method Invocation (RMI) public class Main { public static void main(String[] args) throws RemoteException, NotBoundException{ Registry registry = LocateRegistry.getRegistry("localhost", Registry.REGISTRY_PORT); LuckyNumber luckyNumber = (LuckyNumber) registry.lookup("lucky"); Scanner input = new Scanner(System.in); String again = ""; while(!again.equalsIgnoreCase("no")){ System.out.println("Please Input The Lucky Number ?"); String response = luckyNumber.process(input.nextLine()); System.out.println(response); System.out.println("\nInput Again ?"); again = input.nextLine(); }}}

Demo – Server Side - Impl 18 9/10/2019 Estifanos T. (MSc in Computer Networking) Lecture 5: Remote Method Invocation (RMI) package com.dt.project.server; import com.dt.project.api.LuckyNumber; import java.rmi.RemoteException; public class LuckyNumberImpl implements LuckyNumber{ private int luckyNumber = 100; public String process(String value) throws RemoteException { int num; int num; try { num=Integer.parseInt(value); } try { num=Integer.parseInt(value); } catch (Exception e){ return "Please Input a Number.";} catch (Exception e){ return "Please Input a Number.";} if (num == luckyNumber){ if (num == luckyNumber){ return "Congratulation Estifanos !"; return "Congratulation Estifanos !"; }else { return "Sorry, Please Try Again."; }}} }else { return "Sorry, Please Try Again."; }}}

Demo – Server Side - Main 19 9/10/2019 Estifanos T. (MSc in Computer Networking) Lecture 5: Remote Method Invocation (RMI) package com.dt.project.server; import com.dt.project.api.LuckyNumber; import java.rmi.RemoteException; import java.rmi.registry.LocateRegistry; import java.rmi.registry.Registry; import java.rmi.server.UnicastRemoteObject; public class Main { public static void main(String[] args) throws RemoteException{ Registry registry = LocateRegistry.createRegistry(Registry.REGISTRY_PORT); LuckyNumberImpl luckyNumberImpl = new LuckyNumberImpl(); LuckyNumber luckyNumber = (LuckyNumber) UnicastRemoteObject.exportObject(luckyNumberImpl, 0); registry.rebind("lucky", luckyNumber); System.out.println("CoSc RMI Server is Running"); }}

rmic 20 9/10/2019 Estifanos T. (MSc in Computer Networking) Lecture 5: Remote Method Invocation (RMI) The class that implements the remote object should be compiled as usual Then, it should be compiled with rmic: rmic Hello This will generate files Hello_Stub.class and Hello_Skel.class These classes do the actual communication The “Stub” class must be copied to the client area The “Skel” was needed in SDK 1.1 but is no longer necessary

Summary 21 9/10/2019 Estifanos T. (MSc in Computer Networking) Lecture 5: Remote Method Invocation (RMI) 1.Start the registry server, rmiregistry 2.Start the object server The object server registers an object, with a name, with the registry server 3.Start the client The client looks up the object in the registry server 4.The client makes a request 1.The request actually goes to the Stub class 2.The Stub classes on client and server talk to each other 3.The client’s Stub class returns the result

End Of Chapter Five