Advanced Remote Method Invocations

Slides:



Advertisements
Similar presentations
Message Passing Vs Distributed Objects
Advertisements

Remote Method Invocation CS587x Lecture Department of Computer Science Iowa State University.
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
6 Maart 2006ISS Distributed Objects and Advanced Remote Method Invocations René de Vries Based on the slides by M.L. Liu and Marko van Eekelen.
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,
Java RMI Essentials Based on Mastering RMI Rickard Oberg.
1 Java Programming II Java Network II (Distributed Objects in Java)
Chapter 4 Distributed objects and Remote Method Invocation
CS 584 Lecture 18 l Assignment » Glenda assignment extended to the Java RMI Deadline » No Java RMI Assignment l Test » Friday, Saturday, Monday.
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.
LAB 1CSIS04021 Briefing on Assignment One & RMI Programming February 13, 2007.
Java RMI: Remote Method Invocation January 2000 Nancy McCracken Syracuse University.
Java Remote Method Invocation (RMI) ). Distributed Systems  a collection of independent computers that appears to its users as a single coherent system.
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-IIOP.  RMI-IIOP combines RMI-style ease of use with CORBA cross-language interoperability  Java™ Remote Method Invocation (RMI) provides a simple.
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.
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.
Example: RMI Program How to write it.
 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.
 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)
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.
RMI1 Remote Method Invocation Adapted from “Core Java 2” by Cay Horstmann.
Presentation 13: RMI continued – more advanced issues: Activation & RMI over IIOP.
Java Distributed Computing
Java Remote Method Invocation (RMI)
Remote Method Invocation
Remote Method Invocation
Java RMI (more) CS-328 Internet Programming.
Knowledge Byte In this section, you will learn about:
Network and Distributed Programming in Java
Chapter 40 Remote Method Invocation
Overview of RMI Architecture
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
Overview of RMI Architecture
Java Chapter 5 (Estifanos Tilahun Mihret--Tech with Estif)
Presentation transcript:

Advanced Remote Method Invocations 9/20/2018

RMI – Advanced topics The Java RMI API has a rich collection of features. We will look at some of RMI’s more interesting advanced features, namely: stub downloading security manager client callback. Although these features are not inherent to the distributed object paradigm, they are helpful mechanisms and can be useful to application developers. 9/20/2018

The Java RMI Architecture 9/20/2018

Java RMI Client Server Interaction 9/20/2018

RMI Stub Downloading RMI is designed to allow stubs to be made available to the client dynamically (in HW_#3). Doing so allows changes to be made in the remote methods without affecting the client program. The stub can be filed with an web server and be downloaded using HTTP/FTP. Security measures are needed in both the client side and the server side: A java security policy file needs to be set on the server host and also on the client host. A Java Security Manager should be instantiated in both the client and server programs. 9/20/2018

Stub downloading If the stub will be downloaded from a remote server, transfer the stub class to the appropriate directory that HTTP server can reach, e.g., www.csc.calpoly.edu/~mliu/www, and make sure that the RIGHT access permission to the file is set. When activating the server, specify command option java -D java.rmi.server.codebase = <URL> \ -D java.rmi.server.hostname=<server host name> \ -D java.security.policy=<full directory path to java.policy file> 9/20/2018

The java.policy file The RMI security manager does not permit network access. Exceptions can be made via the specification in a java.policy file. grant { // permits socket access to all common TCP ports, including the default // RMI registry port (1099) – need for both the client and the server. permission java.net.SocketPermission "*:1024-65535", "connect,accept,resolve"; // permits socket access to port 80, the default HTTP port – needed // by client to contact an HTTP server for stub downloading permission java.net.SocketPermission "*:80", "connect"; }; grant { // Allow everything hw_#3 permission java.security.AllPermission; 9/20/2018

The java.policy file - 2 This file can be filed in the same directory as the server class file. When activating the client, a java.policy file also should be specified: java -D java.rmi.server.useCodebaseOnly=true -D java.rmi.server.codebase =http://hostname:80/stub_dir/ -D java.security.manager -D java.security.policy=java.policy SomeClient [ -D property=value ] [ -Djava.security.policy=someURL SomeApp where someURL is a URL specifying the location of a policy file ] java.rmi.server.codebase: this property specifies the locations from which classes that are published by this JVM. java.rmi.server.useCodebaseOnly: If this value is true, automatic loading of classes is prohibited except from the local CLASSPATH and from the java.rmi.server.codebase property set on this JVM. Default security policy file: $java_jre_home/lib/security/java.policy permission java.net.SocketPermission "localhost:1024-", "listen"; 9/20/2018

The java.policy file - 3 The "-D java.security.manager" argument ensures that the default security manager is installed, and thus the application is subject to policy checks. Default security manager is not required if the application installs a security manager. If you use java -Djava.security.manager –D java.security.policy==someURL SomeApp, then just the specified policy file will be used; all the ones indicated in the security properties file will be ignored. Ref: http://java.sun.com/j2se/1.4.2/docs/guide/security/PolicyFiles.html 9/20/2018

File Placements 9/20/2018

RMI Security Manager Since RMI involves access to/from a remote/foreign host, and possibly object downloading, it is important for both the server and the client to protect its system from malicious access. The RMISecurityManager--a Java class, can be instantiated in both the client and the server for limiting access privileges. RMI's class loader will not download any classes from remote locations if no security manager has been set. RMISecurityManager does not apply to applets, which run under the protection of their browser's security manager. You can instantiate/write your own security manager, if so desired. try { System.setSecurityManager(new RMISecurityManager( )); }catch { …} 9/20/2018

Sample Code for Stub Downloading The possible ways--accept, connect, listen, and resolve, to connect to a host in SocketPermission java class. The "listen" action is only meaningful when used with "localhost". The "resolve" action is implied when any of the other actions are present. The action "resolve" refers to host/ip name service lookups. p1 = new SocketPermission(“ise.gmu.edu:7777", "connect, accept"); allows that code to connect to port 7777 on ise.gmu.edu, and to accept connections on that port. p2 = new SocketPermission("localhost:1024-", "accept, connect, listen"); allows that code to accept connections on, connect to, or listen on any port between 1024 and 65535 on the local host. Ref: http://java.sun.com/j2se/1.4.2/docs/api/java/net/SocketPermission.html 9/20/2018

Algorithm for building an RMI Application Server side: Open a directory for all the files to be generated for this application. Specify the remote-server interface, and compile it to generate the interface class file. Build the remote server class by implementing the interface, and compile it using javac. Use rmic to process the server class to generate a stub.class file and a skelton.class file: rmic SomeServerImpl If stub downloading is desired, copy the stub file to an appropriate directory on the HTTP host. Activate the RMIRegistry, if it has not already been activated. Set up a java.policy file. Activate the server, specifying (i) the codebase if stub downloading is desired, (ii) the server host name, and (iii) the security policy file.   9/20/2018

Sample Code for Stub Downloading public interface HelloInterface extends Remote { public String sayHello() throws java.rmi.RemoteException; } // end of HelloInterface interface public class HelloImpl extends UnicastRemoteObject implements HelloInterface { public HelloImpl() throws RemoteException { super( ); } public String sayHello() throws RemoteException { return "Hello, World!"; } } // end HelloImpl class 9/20/2018

Sample Code for Stub Downloading public class HelloServer { public static void main(String args[]) { try{ // System.setSecurityManager( new RMISecurityManager()); startRegistry(RMIPortNum); HelloImpl exportedObj = new HelloImpl(); registryURL = "rmi://cs1.cs.gmu.edu:" + portNum + "/hello"; Naming.rebind(registryURL, exportedObj); System.out.println("Hello Server ready."); }// end try catch (Exception re) { System.out.println("Exception in HelloServer.main: " + re); } } // end main 9/20/2018

Sample Code for Stub Downloading grant { // Allows RMI clients to make socket connections to the // public ports on any host. // If you start the RMI registry on a port in this range, you // will not incur a resolve access violation. permission java.net.SocketPermission "*:1024-65535", "connect, accept, resolve"; // Permits socket access to port 80, the default HTTP port - // needed by client to contact an HTTP server for stub // downloading. permission java.net.SocketPermission "*:80", }; 9/20/2018

Sample Code for Stub Downloading build: $(JAVAC) HelloInterface.java $(JAVAC) HelloServer.java $(JAVAC) HelloImpl.java rmic: $(RMIC) HelloImpl runs: $(JAVA) -D java.security.policy=java.policy -D java.rmi.server.codebase=http://server_URL HelloServer 9/20/2018

Algorithm for building an RMI Application Client side: Open a directory for all the files to be generated for this application. Implement the client program or applet, and compile it to generate the client class. If stub downloading is not in effect, copy the server interface stub class file. Set up a java.policy file. Activate the client, specifying (i) the server host name, (ii) the security policy file, and (iii) the codebase if stub downloading is desired. 9/20/2018

Client Code for Stub Downloading - 1 public class HelloClient { public static void main(String args[]) { try { System.setSecurityManager(new RMISecurityManager()); String registryURL = "rmi://ise.gmu.edu:" + portNum + "/hello"; // find the remote object and cast it to an interface object HelloInterface h = (HelloInterface)Naming.lookup(registryURL); // invoke the remote method String message = h.sayHello(); } // end try catch (Exception e) { System.out.println("Exception in HelloClient: " + e); } // end catch } //end main }//end class 9/20/2018

Client Code for Stub Downloading - 2 build: $(JAVAC) HelloClient.java $(JAVAC) HelloInterface.java runc: $(JAVA) –D java.rmi.server.useCodebaseOnly=true -D java.rmi.server.codebase=http://URL_stub_dir/ -D java.security.policy=java.policy HelloClient 9/20/2018

RMI Callbacks 9/20/2018

Introduction In the client server model, the server is passive: the IPC is initiated by the client; the server waits for the arrival of requests and provides responses. Some applications require the server to initiate communication upon certain events. Examples applications are: monitoring games auctioning voting/polling chat-room message/bulletin board groupware 9/20/2018

Polling vs. Callback In the absence of callback, a client will have to poll a passive server repeatedly if it needs to be notified that an event has occurred at the server end. 9/20/2018

Two-way communications Some applications require that both sides may initiate IPC. Using sockets, duplex communication can be achieved by using two sockets on either side. With connection-oriented sockets, each side acts as both a client and a server. Process 2 9/20/2018

RMI Callbacks A callback client registers itself with an RMI server. The server makes a callback to each registered client upon the occurrence of a certain event. 9/20/2018

Callback Client-Server Interactions 9/20/2018

Callback application files 9/20/2018

RMI Callback file placements 9/20/2018

The Hello Application with Callback 9/20/2018

RMI Callback Interface The server provides a remote method (in server interface), which allows a client to register itself for callbacks. A client remote interface for the callback is needed, in addition to the server-side interface. The client remote interface specifies a method for accepting a callback from the server. The client program is a subclass of RemoteObject, and implements the callback (client) remote interface, including the callback method—NotifyMe(). The client registers itself for callback in its main method, by passing an object reference to the client remote interface. The server invokes the client’s remote method—NotifyMe(), upon the occurrence of the anticipated event. 9/20/2018

Algorithm for building an RMI Callback Application Server side: Open a directory for all the files to be generated for this application. Specify the remote-server interface, and compile it to generate the interface class file. Build the remote server class by implementing the interface, and compile it using javac. Use rmic to process the server class to generate a stub class file and a skeleton class file: rmic ServerInterfaceImpl If stub downloading is desired, copy the stub file to an appropriate directory on the HTTP host. Activate the RMIRegistry, if it has not already been activated. Set up a java.policy file. Activate the server, specifying (i) the codebase if stub downloading is desired, (ii) the server host name, and (iii) the security policy file. Obtain the CallbackClientInterface and its stub file. Use rmic CallbackClientInterfaceImpl to generate the stub file for the callback.   9/20/2018

Remote Interface for Server public interface CallbackServerInterface extends Remote { // remote method public String sayHello() throws java.rmi.RemoteException; // method to be invoked by a client to add itself to the callback list public void registerForCallback ( CallbackClientInterface CallbackObject) throws java.rmi.RemoteException; public void unregisterForCallback( } 9/20/2018

Client Remote Interface for Callback // a remote interface specifying a callback method public interface CallbackClientInterface extends java.rmi.Remote { // callback method to be called by the server public void NotifyMe ( String message ) throws java.rmi.RemoteException; } 9/20/2018

ServerInterfaceImpl with callback public class CallbackServerInterfaceImpl extends UnicastRemoteObject implements CallbackServerInterface { public CallbackServerInterfaceImpl() throws RemoteException { super( ); clientList = new Vector(); } public String sayHello( ) throws java.rmi.RemoteException { return("hello"); } public synchronized void registerForCallback( CallbackClientInterface callbackClientObject) throws java.rmi.RemoteException{ if (!(clientList.contains(callbackClientObject))) { clientList.addElement(callbackClientObject); doCallbacks(); } } private synchronized void doCallbacks( ) throws java.rmi.RemoteException{ for (int i = 0; i < clientList.size(); i++){ CallbackClientInterface nextClient = (CallbackClientInterface)clientList.elementAt(i); String returnMsg = nextClient.notifyMe("Num of clients=" + clientList.size()); } } } 9/20/2018

ClientInterfaceImpl with callback public class CallbackClientInterfaceImpl extends UnicastRemoteObject implements CallbackClientInterface { public CallbackClientInterfaceImpl() throws RemoteException { super( ); } public String notifyMe (String message){ String retMessage = "Call back received: " + message; return retMessage; } } 9/20/2018

Algorithm for building an RMI Callback Application Client side: Open a directory for all the files to be generated for this application. Implement the client program or applet, and compile it to generate the client class. If stub downloading is not in effect, copy the server interface stub class file by hand. Implement the callback client interface—client interface impl class using rmic to generate a stub class and a skeleton class for it for both client callback interface and server interface. Set up a java.policy file. Activate the client, specifying (i) the server host name, (ii) the security policy file, and (iii) the codebase if stub downloading is desired. 9/20/2018

CallbackClient public class CallbackClient { public static void main(String args[]) { try { // stub downloading System.setSecurityManager(new RMISecurityManager()); String registryURL = "rmi://cs1.cs.gmu.edu:" + portNum + "/callback"; CallbackServerInterface h = (CallbackServerInterface)Naming.lookup(registryURL); CallbackClientInterface callbackObj = new CallbackClientInterfaceImpl(); // register for callback h.registerForCallback(callbackObj); System.out.println (“Registered for callback."); h.unregisterForCallback(callbackObj); } catch (Exception e) { System.out.println ("Exception in CallbackClient: " + e); } // end catch } // end of main() }//end class 9/20/2018

Summary-1 Stub downloading allows a stub class to be downloaded to an object client at runtime, thereby allowing a remote object’s implementation to be modified and its stub class regenerated without affecting the software on the client host. A security manager oversees access restrictions specified in a Java security policy file, which can be a system-wide policy file, or a policy file applied to an individual application only. For security protection, the use of security managers is recommended in all RMI applications, regardless of whether stub downloading is involved. 9/20/2018

Summary-2 Client callback: Client callback is useful for an application where the clients desire to be notified by the server of the occurrence of some event. Client callback allows an object server to make a remote method call to a client via a reference to a client remote interface. 9/20/2018

Summary-3 Client callback: To provide client callback, the client-side supplies a remote interface, instantiates a callback interface object passes a reference to the object to the server via a remote method call to the server. The object server: collects these client references in a data structure. invokes a callback method, defined in the client remote interface, to pass data to the client, when the awaited event occurs. Two sets of stub-skeletons are needed: one for the server remote interface, the other one for the client remote interface. 9/20/2018