Network and Distributed Programming in Java

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.
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.
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.
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.
1 HANDOUT 14 Remote Method Invocation (RMI) BY GEORGE KOUTSOGIANNAKIS THIS DOCUMENT CAN NOT BE REPRODUCED OR DISTRIBUTED WITHOUT TH E WRITTEN PERMISSION.
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
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 Essentials Based on Mastering RMI Rickard Oberg.
RMI Components java.rmi: client-side RMI classes, interfaces, and exceptions java.rmi.server: server-side RMI classes, interfaces, and exceptions java.rmi.registry:
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.
Presentation: RMI Continued 2 Using The Registry & Callbacks.
Java RMI: Remote Method Invocation January 2000 Nancy McCracken Syracuse University.
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.
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.
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.
Khoa CNTT 1/37 PHẠM VĂN TÍNH   Java 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.
CSC 480 Software Engineering Lab 6 – RMI Nov 8, 2002.
RMI1 Remote Method Invocation Adapted from “Core Java 2” by Cay Horstmann.
Liang, Introduction to Java Programming, Fifth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 29 Remote Method.
Distributed Web Systems Distributed Objects and Remote Method Invocation Lecturer Department University.
Java Distributed Computing
Chapter 4 Remote Method Invocation
Java Remote Method Invocation (RMI)
RMI Packages Overview java.rmi java.rmi.server java.rmi.registry
Remote Method Invocation
Java RMI CS-328 Internet Programming.
What is RMI? Remote Method Invocation
Remote Method Invocation
Java RMI (more) CS-328 Internet Programming.
Knowledge Byte In this section, you will learn about:
Creating a Distributed System with RMI
Chapter 40 Remote Method Invocation
Creating a Distributed System with RMI
Overview of RMI Architecture
Remote Method Invocation
Creating a Distributed System with RMI
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
Creating a Distributed System with RMI
Overview of RMI Architecture
Presentation transcript:

Network and Distributed Programming in Java Objectives In this lesson, you will learn about: Evolution of distributed applications Components and architecture of RMI Classes and interfaces of RMI packages Steps to create and host RMI application Network and Distributed Programming in Java

Network and Distributed Programming in Java Overview of Distributed Application The approaches to develop a distributed application are: Traditional Client/Server Component-based Network and Distributed Programming in Java

Network and Distributed Programming in Java Overview of Distributed Application (Contd.) In the traditional approach of developing a distributed application: A single application handles the presentation logic, business logic and database interactivity. These application are also called monolithic applications. You need to recompile and integrate the entire application, if you want to change, extend or enhance the application created using traditional approach. Network and Distributed Programming in Java

Network and Distributed Programming in Java Overview of Distributed Application (Contd.) In the client/server approach of creating a distributed application: Data is centrally stored on the server. The business logic and presentation logic are combined together at client side or server side. fat client: Business logic and presentation logic are combined together at client side. fat server: Business logic and presentation logic are combined together at server side. Any change in the business policies requires a change in the business logic. It is difficult to scale-up the client because a client has a limited number of database connections. Network and Distributed Programming in Java

Network and Distributed Programming in Java Overview of Distributed Application (Contd.) In the component-based approach of creating a distributed application: The presentation logic resides at client-side. The business logic resides between the client and server and is known as middle-tier. The database access is controlled at the server-side. A database connection is established only when data access is required and is released as the data is retrieved or sent to the server. The applications run on the middle-tier and are independent of both the presentation interface and database implementation. Network and Distributed Programming in Java

Network and Distributed Programming in Java Overview of Distributed Application (Contd.) Three-tier distributed application Network and Distributed Programming in Java

Network and Distributed Programming in Java Remote Method Invocation RMI: Is an easy alternative to the complex coding involved in server-socket programming. Enables you to create distributed applications. Is a specification that enables one Java Virtual Machine (JVM) to invoke methods in an objcet located in another JVM. Is implemented on the middle-tier of the three-tier architecture framework. Network and Distributed Programming in Java

Network and Distributed Programming in Java Remote Method Invocation (Contd.) Components of RMI Application The two components of RMI application are: RMI server: Contains the objects whose methods are to be invoked remotely. Creates several remote objects and makes a reference of these objects in the RMI registry. RMI client: Gets the references of one or more remote objects from the RMI registry. Invokes the methods on the remote object to access the services of the remote object. Network and Distributed Programming in Java

Network and Distributed Programming in Java Remote Method Invocation (Contd.) Functionality of RMI application Network and Distributed Programming in Java

Network and Distributed Programming in Java Remote Method Invocation (Contd.) The RMI Architecture The three layers of RMI architecture are: Stub/Skeleton Layer Remote Reference Layer Transport Layer Network and Distributed Programming in Java

Network and Distributed Programming in Java Remote Method Invocation (Contd.) RMI Architecture Network and Distributed Programming in Java

Network and Distributed Programming in Java Remote Method Invocation (Contd.) Stub/Skeleton Layer: Listens to remote method calls by a client and redirect these calls to the remote RMI services on the server. Consists of: Stub: Provides methods of the remote object. Communicates the method invocations to the remote object. Skeleton: Reads the parameter for the method call. Makes the call to the remote service implementation object. Accepts the return value. Writes the return value back to the stub. Network and Distributed Programming in Java

Network and Distributed Programming in Java Remote Method Invocation (Contd.) Remote Reference Layer: Interprets and manages the references made by a client to a remote object on the server. Contains: Client-side RRL Receives a request from a stub. Marshals the request. Sends the marshaled request stream to the server. Server-side RRL Unmarshals the parameter that are sent to a remote method. Returns the value back to the client. Network and Distributed Programming in Java

Network and Distributed Programming in Java Remote Method Invocation (Contd.) Transport Layer: Establish new connections and manages the existing connections between the client and server. Handles remote objects that resides in transport layer address space. Connects a client to the server using the following steps: Establishes a socket connection to the server through server-side RRL. Passes the established socket connection to the client-side RRL. Adds a remote reference to the connection in its reference table. Network and Distributed Programming in Java

Network and Distributed Programming in Java Remote Method Invocation (Contd.) RMI Packages The java.rmi package: Provides the Remote interface, a class for accessing the remote names registered on the server, and a security manager for RMI. The java.rmi.registry package: Provides classes and interfaces that are used by the remote registry. The java.rmi.server package: Provides classes and interfaces used to implement remote objects, stubs and skeletons, and support for RMI communication. The java.rmi.dgc package: Provides classes and interfaces that are used by the RMI-distributed garbage collector. Network and Distributed Programming in Java

Network and Distributed Programming in Java Remote Method Invocation (Contd.) The classes and interfaces of java.rmi package are: Remote interface Naming class rebind() method unbind() method lookup() method list() method RMISecurityManager class Network and Distributed Programming in Java

Network and Distributed Programming in Java Remote Method Invocation (Contd.) The classes and interfaces of java.rmi.registry package are: Registry interface RegistryHandler interface Network and Distributed Programming in Java

Network and Distributed Programming in Java Remote Method Invocation (Contd.) The classes and interfaces of java.rmi.server package are: RemoteObjcet class RemoteServer class UnicastRemoteObjcet class RemoteStub class RemoteCall interface Skeleton interface Unreferenced interface Network and Distributed Programming in Java

Network and Distributed Programming in Java Remote Method Invocation (Contd.) The classes and interfaces of java.rmi.dgc package are: Lease class dirty() method clean() method Network and Distributed Programming in Java

Network and Distributed Programming in Java Remote Method Invocation (Contd.) Distributed Garbage Collection Is a mechanism to automatically deletes the remote objects that RMI clients are not using. Uses the reference counting garbage collection algorithm to manage the references of the remote object. Uses the objects of the Lease class to keep the references of remote objects that reside in the JVM. Network and Distributed Programming in Java

Network and Distributed Programming in Java Creating a Distributed Application Using RMI The steps to create an RMI application are: Create a remote interface Implement a remote interface Create an RMI server Create an RMI client Run the RMI application Network and Distributed Programming in Java

Network and Distributed Programming in Java Creating a Distributed Application Using RMI (Contd.) Creating a Remote Interface Import the java.rmi package. Declare the remote interface with public identifier. Extend the java.rmi.Remote interface. Use the java.rmi.RemoteException class with every method that declared in the remote interface. The code snippet to create a remote interface is: import java.rmi.*; public interface Hello extends Remote { public String sayHello() throws RemoteException; } Network and Distributed Programming in Java

Network and Distributed Programming in Java Creating a Distributed Application Using RMI (Contd.) Implementing the Remote Interface Import the java.rmi and java.rmi.server packages. import java.rmi; import java.rmi.server; Create a remote service that implements the remote interface and extends the UnicastRemoteObject class. public class HelloImpl implements Hello extends UincastRemoteObjcet { .. } Network and Distributed Programming in Java

Network and Distributed Programming in Java Creating a Distributed Application Using RMI (Contd.) Hierarchy of UnicastRemoteObjcet Class Network and Distributed Programming in Java

Network and Distributed Programming in Java Creating a Distributed Application Using RMI (Contd.) Define the default constructor of the remote service class. public HelloImpl() throws RemoteException { super(); } Define the method that are declared in the remote interface. public String sayHello() throws RemoteException return “Hello! Peter Smith.”; Network and Distributed Programming in Java

Network and Distributed Programming in Java Creating a Distributed Application Using RMI (Contd.) Creating an RMI Server Create the object of the remote service class in the main() method of the RMI server class. Hello h = new HelloImpl(); Register the server object in the bootstrap registry before the server object is ready to accept request from the client. Naming.rebind("server",h); Create and install the security manager for the RMI application: System.setSecurityManager(new RMISecurityManager()); Network and Distributed Programming in Java

Network and Distributed Programming in Java Creating a Distributed Application Using RMI (Contd.) Creating the Security Policy File Type the command, policytool, on command prompt to display the Policy Tool utility of Java. The Policy Tool window is displayed with an Error dialog box. Network and Distributed Programming in Java

Network and Distributed Programming in Java Creating a Distributed Application Using RMI (Contd.) Policy Tool Window Network and Distributed Programming in Java

Network and Distributed Programming in Java Creating a Distributed Application Using RMI (Contd.) Click the OK button of the Error dialog box. Now, click the Add Policy Entry button to add a new security policy file. This displays the Policy Entry dialog box as shown: Network and Distributed Programming in Java

Network and Distributed Programming in Java Creating a Distributed Application Using RMI (Contd.) Click the Add Permission button to grant the required permission to access the resources of the server by the client. The following figure shows the Permissions dialog box: Network and Distributed Programming in Java

Network and Distributed Programming in Java Creating a Distributed Application Using RMI (Contd.) Select AllPermission from the Permission list box of the Permissions dialog box. Click the OK button to close the Permissions dialog box. Click the Done button of the Policy Entry dialog box. Select the FileSave As command of the Policy Tool window to save the new security policy. Save the security policy file as .java.policy in the HOME directory of the operating system. A confirmation message is displayed on the Status dialog box. The following figure shows the Status message box: Network and Distributed Programming in Java

Network and Distributed Programming in Java Creating a Distributed Application Using RMI (Contd.) Click the OK button of the Status message box. Select the FileExit command of the Policy Tool window to close the Policy Tool utility of Java. Network and Distributed Programming in Java

Network and Distributed Programming in Java Creating a Distributed Application Using RMI (Contd.) Creating an RMI Client Find the stub object by specifying the name of the server object as a parameter in the lookup() method. Hello h = (Hello)Naming.lookup("rmi://192.168.0.52/server"); Running the RMI Application Generate the stub and skeleton of the remote service class. Start the RMI registry. Run the RMI server. Run the RMI client. Network and Distributed Programming in Java

Network and Distributed Programming in Java Creating a Distributed Application Using RMI (Contd.) Generating the Stub and Skeleton The command to generate the stub and skeleton is: rmic [Option] <ClassFile> The following table lists the various options of RMI compiler: Options Description -bootclasspath <path> Overrides the location of the bootstrap class file. -classpath <path> Overrides the default classpath environment variables. -d <directory> Specifies the name of the directory where you want to generate the stub and skeleton. Network and Distributed Programming in Java

Network and Distributed Programming in Java Creating a Distributed Application Using RMI (Contd.) Options of RMI compiler (Contd.) Options Description -depend Compiles all the files that are referenced to the remote service class. -extdirs <path> Overrides the location of the installed extensions. -g Generates the line numbers and local variables in the form of a table. -keep Stores '.java' file that generates the stub and skeleton. -nowarn Does not display any warning when you generate the stub and skeleton. Network and Distributed Programming in Java

Network and Distributed Programming in Java Creating a Distributed Application Using RMI (Contd.) Options of RMI compiler (Contd.) Options Description -vcompat Creates stub and skeleton that are compatible with earlier versions of RMI protocols. -verbose Display a message, when the remote service file is compiled by rmic. -v <version> Create a stub and skeleton for the specified versions of the Java Development Kit (JDK). Network and Distributed Programming in Java

Network and Distributed Programming in Java Creating a Distributed Application Using RMI (Contd.) Starting the RMI Registry The command to start the RMI registry at specified port number(1234) is: start rmiregistry 1234 The command to start the RMI registry at default port number (1099) is: start rmiregistry Network and Distributed Programming in Java

Network and Distributed Programming in Java Creating a Distributed Application Using RMI (Contd.) Running an RMI Server The command to run the RMI server is: java HelloServer Running an RMI Client The command to run the RMI client is: java HelloClient Network and Distributed Programming in Java

Network and Distributed Programming in Java Creating a Distributed Application Using RMI (Contd.) Working of RMI Application Network and Distributed Programming in Java

Network and Distributed Programming in Java Demonstration-Implementing an RMI Application Problem Statement Earnest publishing house has branches in all major cities across the globe. They have a central database in Chicago. The publishing house wants to create an application that will allow its authors to register with the publishing house. The details submitted by the authors needs to be updated in the database server. Network and Distributed Programming in Java

Network and Distributed Programming in Java Demonstration-Implementing an RMI Application (Contd.) Solution The steps to create the distributed application using RMI are: Create the AuthorServer remote interface. Create the AuthorServerImpl class. Create the Client class. Run the application. Network and Distributed Programming in Java

Network and Distributed Programming in Java Summary In this lesson, you learned that: Distributed applications are applications that execute across multiple host systems. The RMI is implemented on the middle-tier of the three-tier architecture framework. RMI allows a client on one JVM to invoke an object of a method present on another JVM. The RMI architecture consists of three layers: the Stub/Skeleton Layer,the Remote Reference Layer, and the Transport Layer Network and Distributed Programming in Java

Network and Distributed Programming in Java Summary (Contd.) RMI consists of the following four packages: java.rmi: Provides classes and interfaces to access the remote objects using the name registered in the RMI registry. java.rmi.server: Provides classes and interfaces to implement remote interface and generate the stub/skeleton. java.rmi.registry: Provides classes and interfaces to register an object and access the object by a name across network. java.rmi.dgc: Provides classes for implementing distributed garbage collector. The registry is an RMI service that resides on the server and allows remote clients to get reference of a remote object. A remote interface declares the methods that can be invoked remotely by a client. Network and Distributed Programming in Java

Network and Distributed Programming in Java Summary (Contd.) A remote service class for the RMI server must: Implement a remote interface. Define a constructor in the remote service class to initialize a remote object. Provide implementation for remote method. Create and install the security manager. Instantiate a remote object. Register a remote object with the RMI registry. Java provides security to applications by using the security manager. Network and Distributed Programming in Java

Network and Distributed Programming in Java Summary (Contd.) The steps to create and run an RMI application are: Define the remote interface. Create a remote service class that implements the remote interface. Create an RMI server. Create an RMI client. Compile and generate the stub and skeleton. Start the RMI registry. Run the RMI server application. Run the RMI client application. Network and Distributed Programming in Java