RMI , Naming Service, Serialization and Internationalization Chapter 4

Slides:



Advertisements
Similar presentations
Message Passing Vs Distributed Objects
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.
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
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.
CSCE 515: Computer Network Programming Chin-Tser Huang University of South Carolina.
Java RMI RMI = Remote Method Invocation. Allows Java programs to invoke methods of remote objects. Only between Java programs. Several versions (JDK-1.1,
Internet Software Development Remote Method Invocation Paul Krause.
Lesson 3 Remote Method Invocation (RMI) Mixing RMI and sockets Rethinking out tic-tac-toe game.
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
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.
LAB 1CSIS04021 Briefing on Assignment One & RMI Programming February 13, 2007.
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.
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.
1 Java Remote Method Invocation java.rmi.* java.rmi.registry.* java.rmi.server.*
Remote Method Invocation Instructors: Fu-Chiung Cheng ( 鄭福炯 ) Associate Professor Computer Science & Engineering Tatung University.
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.
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.
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.
Java Distributed Object Model A remote object is one whose methods can be invoked from another JVM on a different host. It implements one or more remote.
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.
Liang, Introduction to Java Programming, Fifth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 29 Remote Method.
Assignment 2 Multithreading/Synchronization UDP – How to maintain connections Testing: Mentioning test cases Plagiarism.
Remote Method Invocation Internet Computing Workshop Lecture 17.
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
Creating a Distributed System with RMI
Chapter 40 Remote Method Invocation
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
Java Chapter 5 (Estifanos Tilahun Mihret--Tech with Estif)
Presentation transcript:

RMI , Naming Service, Serialization and Internationalization Chapter 4

A Simple Overview Java RMI allows one Java object to call methods on another Java object in a different JVM Client JVM Method parameters Local Object Remote Object Result or exception Server JVM 2

What is RMI? RMI stands for “Remote Method Invocation” means communicating the object across the network. RMI is a system that allows an object running in one Java virtual machine (Client) to invoke methods on an object running in another Java virtual machine (Server). This object is called a Remote Object and such a system is also called RMI Distributed Application

Distributed Programming Java RMI is interface based A remote object (or distributed service) is specified by its interface “interfaces define behaviour and classes define implementations” Termed Remote Interfaces Interface Implementation Client Program Server Program RMI System 4

RMI vs. Socket-Level Programming Higher level of abstraction. It hides the details of socket server, socket, connection, and sending or receiving data Scalable and easy to maintain. RMI clients can directly invoke the server method, whereas socket-level programming is limited to passing values.

RMI Architecture The complete RMI system has a FOUR layer, (1)  Application Layer (2)  Proxy Layer (3)  Remote Reference Layer (4)  Transport Layer Mainly the RMI application contains the THREE components, (1) RMI Server (2)  RMI Client (3)  RMI Registry

Stubs and Skeleton Layer Stubs and skeletons are generated from the remote interface Using the “rmic” Java tool Interface Client Stub Server Skel Stub communicates with a skeleton rather than the remote object This a Proxy approach Marshalls the parameters and results to be sent across the wire 8

Stub and Skeleton

Parameter Passing(1) Parameter Passing in Java RMI is different from standard Java Reminder: In Java, primitives are passed by value, Objects are passed by reference In Java RMI Objects and primitives are passed by value Remote objects are passed by reference 11

Parameter Passing (2) RMI-Pass by Value RMI-Pass by Reference All ordinary objects and primitives are serialised and a copy is passed Any changes to the copy do not affect the original RMI-Pass by Reference Remote Object is the parameter, a stub (reference) is sent the stub is used to modify the object, the original object is modified 12

Remote Reference Layer Responsible for Connection management (stub and skeleton) For example, if a remote object is part of a replicated object, the client-side component can forward the invocation to each replica rather than just a single remote object.

The RMI Registry Registry names have a URL format The RMI Registry is a naming service Separately Running service Initiated using Java’s “rmiregistry” tool Server programs register remote objects Give the object a name it can be found using Client programs lookup object references that match this service name Registry names have a URL format rmi://<hostname>:<port>/<ServiceName> E.g. rmi://localhost:1099/CalculatorService E.g. rmi://194.80.36.30:1099/ChatService 16

The RMI Registry Interface 17

Lookup in Java RMI RMIRegistry Local Machine Interface Remote Object Client Program Server Program naming.lookup(“rmi://localhost:1099/ TestService”) naming.rebind(“rmi://localhost:1099/TestS ervice”, RemoteObjectReference) Server Client RMIRegistry Local Machine 18

Calculator.java import java.rmi.Remote; import java.rmi.RemoteException; public interface Calculator extends Remote { public long addition (long a,long b) throws RemoteException; public long subtraction (long a,long b) throws RemoteException; public long multiplication (long a,long b) throws RemoteException; public long division (long a,long b) throws RemoteException; }

CalculatorImpl.java import java.rmi.RemoteException; import java.rmi.server.UnicastRemoteObject;   public class CalculatorImpl extends UnicastRemoteObject implements Calculator {     protected CalculatorImpl() throws RemoteException     {         super();     }     public long addition (long a, long b) throws RemoteException         return a+b;     public long subtraction (long a, long b) throws RemoteException         return a-b;     public long multiplication (long a, long b) throws RemoteException         return a*b;     public long division (long a, long b) throws RemoteException         return a/b;   

CalculatorServer.java import java.rmi.Naming; public class CalculatorServer { CalculatorServer() try Calculator c = new CalculatorImpl(); Naming.rebind("rmi://localhost:1099/CalculatorService", c); } catch (Exception e) System.out.println("Exception is : "+e); public static void main(String[] args) new CalculatorServer();

CalculatorClient.java import java.rmi.Naming; public class CalculatorClient { public static void main(String[] args) try Calculator c = (Calculator) Naming.lookup("//127.0.0.1:1099/CalculatorService"); System.out.println("Addition : "+c.addition(10,5)); System.out.println("Subtraction : "+c.subtraction(10,5)); System.out.println("Multiplication :"+c.multiplication(10,5)); System.out.println("Division : "+c. division(10,5)); } catch (Exception e) System.out.println("Exception is :"+e); } }

Steps to Run RMI Program(1) javac Calculator.java javac CalculatorImpl.java javac CalculatorServer.java javac CalculatorClient.java

RUN Java File rmic CalculatorImpl   start rmiregistry

Steps to Run RMI Program(2) rmic CalculatorImpl start rmiregistry

Run RMI Registry

Steps to Run RMI Program(3) After Opening Registry java CalculatorServer Open another Command Prompt java CalculatorClient

Run Client

Example: Distributed TicTacToe Using RMI , “Distributed TicTacToe Game,” was developed using stream socket programming.

Naming Service Assign a standard name to a given set of data Ex : Email address Binding a Web Name with URL. DNS(Domain Name Server)

Object Serialization BYTES To pass user created objects as parameters in RMI they must be serializable This is easy in Java – simply make the class implement the Serializable interface If you want to optimise the serialisation you can overide the methods of serializable with your own implementation e.g. ObjectInput(Output)Stream Transforming an Object in a stream of bytes Can be sent across the network BYTES 31

Serialization Demo import java.io.*; class Student implements java.io.Serializable { public String name; public String address; public int en_no; public int number; } public class SerializeDemo public static void main(String [] args) Student e = new Student(); e.name = "ABC"; e.address = "Gujarat"; e.en_no= 001; e.number = 67667676; try { FileOutputStream fileOut = new FileOutputStream("abc.txt"); ObjectOutputStream out = new ObjectOutputStream(fileOut); out.writeObject(e); out.close(); fileOut.close(); System.out.printf("Serialized data is "+e.name+"\n"+e.address+“ \n "+e.en_no+"\n"+e.number ); } catch(IOException i) i.printStackTrace();

try { FileInputStream fileIn = new FileInputStream("abc try { FileInputStream fileIn = new FileInputStream("abc.txt"); ObjectInputStream in = new ObjectInputStream(fileIn); e = (Student) in.readObject(); in.close(); fileIn.close(); } catch(IOException i) i.printStackTrace(); return; catch(ClassNotFoundException c) System.out.println("Student class not found"); c.printStackTrace(); System.out.println("\n\nDeserialized Employee..."); System.out.println("Name: " + e.name); System.out.println("Address: " + e.address); System.out.println("En_No: " + e.en_no); System.out.println("Number: " + e.number);

Output

Serialized Notepad File

Before Internationalization public class Demo { public static void main(String[] args) System.out.println("Hello."); System.out.println("How are you?"); System.out.println("Goodbye."); }

After Internationalization import java.util.*; public class I18NSample { public static void main(String[] args) throws MissingResourceException { String language; String country; if (args.length != 2) { language = new String("en"); country = new String("US"); } else { language = new String(args[0]); country = new String(args[1]); Locale currentLocale; ResourceBundle messages; currentLocale = new Locale(language, country); messages = ResourceBundle.getBundle("MessagesBundle", currentLocale); System.out.println(messages.getString("greetings")); System.out.println(messages.getString("inquiry")); System.out.println(messages.getString("farewell"));

Running the Sample Program MessagesBundle.properties greetings = Hello. farewell = Goodbye. inquiry = How are you? MessagesBundle_de_DE.properties greetings = Hallo. farewell = Tschüß. inquiry = Wie geht's? MessagesBundle_en_US.properties MessagesBundle_fr_FR.properties greetings = Bonjour. farewell = Au revoir. inquiry = Comment allez-vous?

Output