1 Java Programming II Java Network II (Distributed Objects in Java)

Slides:



Advertisements
Similar presentations
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.
Advertisements

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.
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.
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.
George Blank University Lecturer. RMI Introduction to RMI.
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.
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
CSE331: Introduction to Networks and Security Lecture 11 Fall 2002.
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,
Internet Software Development Remote Method Invocation Paul Krause.
CS603 Communication Mechanisms: DCE RPC (cont.) 23 January 2002.
Java RMI Essentials Based on Mastering RMI Rickard Oberg.
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.
Presentation: RMI Continued 2 Using The Registry & Callbacks.
1 Classnote#12 RMI. 2 RMI applications are often comprised of two separate programs: – a server and a client. A typical server application –creates some.
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.
Presentation 18: RMI introduction. Goals of this lesson After this 35 min. lesson you will be: Introduced to Java RMI Ready to present RMI’s position.
Spring/2002 Distributed Software Engineering C:\unocourses\4350\slides\DefiningThreads 1 RMI.
RMI-IIOP.  RMI-IIOP combines RMI-style ease of use with CORBA cross-language interoperability  Java™ Remote Method Invocation (RMI) provides a simple.
Silberschatz, Galvin, and Gagne  1999 Applied Operating System Concepts Chapter 15: Distributed Communication Sockets Remote Procedure Calls (RPCs) Remote.
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.
Tanenbaum & Van Steen, Distributed Systems: Principles and Paradigms, 2e, (c) 2007 Prentice-Hall, Inc. All rights reserved TDTS04 Föreläsning.
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.
 Remote Method Invocation  A true distributed computing application interface for Java, written to provide easy access to objects existing on remote.
Presentation: RMI introduction. Goals of this lesson After this 35 min. lesson you will be: Introduced to Java RMI Ready to present RMI’s position in.
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.
Presentation 11: RMI introduction. Ingeniørhøjskolen i Århus Slide 2 af 20 Goals of this lesson After these 2x35 lessons you will be –Introduced to Java.
Presentation: RMI Continued 2 Using The Registry & Callbacks.
DISTRIBUTED OBJECTS AND REMOTE INVOCATION 1. 2 Topics  Middleware  Remote Method Invocation  Remote Procedure Call.
 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.
1 RMI Russell Johnston Communications II. 2 What is RMI? Remote Method Invocation.
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.
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.
Presentation 13: RMI continued – more advanced issues: Activation & RMI over IIOP.
January 26, Ann Wollrath Copyright 1999 Sun Microsystems, Inc., all rights reserved. Java ™ RMI Overview Ann Wollrath Senior Staff Engineer Sun Microsystems,
Java Remote Method Invocation (RMI)
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
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:

1 Java Programming II Java Network II (Distributed Objects in Java)

2 Java Programming II Contents  Distributed Objects  Java RMI  Communication of Remote Object and Client  Writing Java RMI Application  Hello Example  RMI Structure  If room (RMI Callback)

3 Java Programming II Distributed Objects  Objects that can communicate with objects on heterogeneous run-time environments  Distribute Objects Standard Protocol – ex: JRMP  Robust  Reliable  Transparent  Distributed Objects Technology Multi-Platform Transparent access to distributed objects Language Neutral: RMI, CORBA, DCOM

4 Java Programming II Java Remote Method Invocation (RMI)  Can use objects on remote different run- time environments as like objects on a local run-time environment  Abstraction of low-level network code on distributed network to provide developers an environment where they focus on their application development.

5 Java Programming II Introduction to RMI  Distributed Processing on Network  Define of Remote Interface  Object Serialization  java.rmi and java.rmi.server  Create Stub and Skeleton

6 Java Programming II Communication of Remote Object and Client JVM ClientStub RMI Client Application Network JVM Remote Object Skeleton RMI Server Application

7 Java Programming II Writing Java RMI Application  Writing RMI Application Definition of Remote Interface Definition of Remote Implementation Class Write RMI Server Application Write Client Application  Compile and Run the Application Compilation of the Implementation Class Creation of Stub and Skeleton using “rmic” command Compilation of the Server Application Run the RMI Registry and Start the Server Program Compilation of the Client Program Run the Client

8 Java Programming II Hello Example : RMI import java.rmi.Remote; import java.rmi.RemoteException; public interface Hello extends Remote { String sayHello() throws RemoteException; } Interface

9 Java Programming II Hello Example : RMI import java.rmi.Naming; import java.rmi.RemoteException; import java.rmi.RMISecurityManager; import java.rmi.server.UnicastRemoteObject; public class HelloImpl extends UnicastRemoteObject implements Hello { public HelloImpl() throws RemoteException { super(); } public String sayHello() { return "Hello World!"; } public static void main(String args[]) { // Create and install a security manager if (System.getSecurityManager() == null) { System.setSecurityManager(new RMISecurityManager()); } Implementation (Server) try { HelloImpl obj = new HelloImpl(); // Bind this object instance to the name "HelloServer" Naming.rebind("HelloServer", obj); System.out.println("HelloServer bound in registry"); } catch (Exception e) { System.out.println("HelloImpl err: " + e.getMessage()); e.printStackTrace(); } Compile & Skeleton Creation : % javac Hello.java % javac HelloImpl.java % rmic HelloImpl “HelloImpl” object

10 Java Programming II Hello Example : RMI import java.rmi.Naming; import java.rmi.RemoteException; public class HelloClient { public static void main(String args[]) { String message = "Hello: This is my test message"; // "obj" is the identifier that we'll use to refer // to the remote object that implements the "Hello" // interface Hello obj = null; try { obj = (Hello)Naming.lookup("//" + "/HelloServer"); message = obj.sayHello(); } catch (Exception e) { System.out.println("HelloClient exception: " + e.getMessage()); e.printStackTrace(); } System.out.println("Message = " + message); } // end of main } // end of HelloClient A Client Application

11 Java Programming II Hello Example : RMI Start Registry Server & Run Server and Client % rmiregistry & % java – Djava.security.policy=policy HelloImpl % javac examples/hello/HelloClient.java % java [ – Djava.security.policy=policy] HelloClient grant { // Allow everything for now permission java.security.AllPermission; }; File “policy” Please ensure there is the “policy” file in the current directory Run the RMI Server Compile the Client Run the Client Start rmiregistry. Default port is 1099.

12 Java Programming II RMI Structure  Protocol Java Remote Method Protocol (JRMP) For distribute object environment by pure Java environment RMI/IIOP: Can communicate with CORBA  JRMP Communication Mechanism between Stub and Skeleton Object Serialization: Types of parameters and return type of a remote method should follow Java serialization mechanism

13 Java Programming II Stub and Skeleton JVM Client Remote Method Invocation Data Transformation Stub RMI Client Application Network JVM Remote Object Remote Method Invocation Remote Method Return Skeleton RMI Server Application Marshalling Unmarshalling Marshalling Object Serialization

14 Java Programming II Stub and Skeleton  Stubs and Skeleton When RMI client invokes a remote method of a remote object, it uses stub reference of the remote object instead of remote object reference. For marshalling and unmarshalling of stub and skeleton, object serialization and deserialization are used. Condition of Object for Object Serialization Object should implementjava.io.Serialization interface Built-in types can be serialized basically Member variables should implement the Serializable interface or be declared as transient Static member variables can not be serialized.

15 Java Programming II JRMP Class Virtual connection Network connection Marshall/Unmarshall (Object Serialization) Managing connection to remote object Creation of reference to remote object

16 Java Programming II Callback between Client and Server  Implementation of callback between a client and a server through reference passing What is callback? Usually, a server provide service objects with methods. When a client invoke a method of the server, the server executes the invocation and return result to the client. For the callback, a client (or invoker) provide services (methods) for server (or program to be invoked). The callback is that the server (callee) invokes client (caller)’s methods. If you are interested in an example for callback to a client’s method, refer to the “/home/course/java2/codes/ByTopics/RMI/RMI-ComputeEngine” A Simple Callback Example

17 Java Programming II RMI Callback Example import java.rmi.Remote; import java.rmi.RemoteException; public interface Callback extends Remote { public String speakJapanese() throws RemoteException; public String speakEnglish() throws RemoteException; public String greeting(String s) throws RemoteException; } Interface

18 Java Programming II RMI Callback Example import java.rmi.Naming; import java.rmi.RemoteException; import java.rmi.RMISecurityManager; import java.rmi.server.UnicastRemoteObject; public class CallbackImpl extends UnicastRemoteObject implements Callback { public CallbackImpl() throws RemoteException { super(); } public String greeting(String lang) throws RemoteException { CallbackServer server = new CallbackServer(); return server.sayHello(this, lang); } public String speakJapanese(){ return new String("Konnichiwa!"); } public String speakEnglish(){ return new String("How are you!"); } RMI Server (CallbackImpl) public static void main(String args[]) { // Create and install a security manager if (System.getSecurityManager() == null) { System.setSecurityManager(new RMISecurityManager()); } try { CallbackImpl obj = new CallbackImpl(); // Bind this object instance to the name "MyCallbackServer" Naming.rebind("MyCallbackServer", obj); System.out.println("MyCallbackServer bound in registry"); } catch (Exception e) { System.out.println("CallbackImpl err: " + e.getMessage()); e.printStackTrace(); } Call sayHello with “this” for callback routine

19 Java Programming II RMI Callback Example import java.rmi.Remote; import java.rmi.RemoteException; public class CallbackServer { public String sayHello(Callback callback, String lang) throws RemoteException { String message = null; if(lang.equals("JAPANESE")) { message = callback.speakJapanese(); System.out.println("In CallbackServer, " + message); return message; } else { message = callback.speakEnglish(); System.out.println("In CallbackServer, " + message); return message; } Callback Server Code for callback passed from the caller routine