Assignment 1 : Java RMI Assignment 1 : Java RMI OBJECTIVE The objective of this exercise is to gain experience programming in the Java programming environment and to understand the steps in using Java Remote Method Invocation (RMI) for building a distributed application. By the end of this exercise you should understand the tradeoffs in using RMI as compared to local procedure calls, and you should understand differences and similarities between Remote Procedure Call (RPC)and RMI. You will also modify a simple client/server application using Java RMI. STEP 0: Preparation Verify that you have an account on cohn.cs.kent.edu. If you have trouble logging in to your account send me email. This exercise assumes that you have some preliminary experience with Java. If you have never programmed in Java then you should spend some time going through the tutorial on Learning the Java Language at http://java.sun.com/docs/books/tutorial/java. This exercise also assumes that you have had exposure to some basic Internet concepts. Some helpful references for this are at: http://www.webopedia.com/quick_ref/OSI_Layers.asp http://www.cs.kent.edu/~farrell/lectures/grid02.pdf The steps of this exercise are: Read the introductory material on RMI and RPC from the lectures and on-line references. Follow the instructions in the Java RMI Tutotial at Sun and Intro to RMI to understand how to write, compile and run an example Java RMI program. Examine the Java RMI application from Intro to RMI and extend it as described below. The corrected source for this is in the directory http://www.cs.kent.edu/~farrell/RMI/CO. You will do all of your programming for this assignment on cohn.cs.kent.edu, or one if its nodes but you may use other platforms for testing. Answer the post-exercise questions. What to turn in: The code for your assignment should be in your account on talon, in a subdirectory entitled "JavaRMI" or something equally obvious. I will grade your assignment by executing your code from cohn. Turn in the answers to the questions on paper or by e-mail. STEP 1: Read the introduction and background reading material To start, read the following: Class lecture notes on RPC and RMI at http://www.cs.kent.edu/~farrelll/grid06/lectures/grid02.pdf RPC is a technique for building distributed, client-server based applications. It extends the notion of conventional, or local procedure calling. With RPC the called procedure does not need to be in the same address space as the calling procedure. The two processes can be executing on the same computer or on different computers. Programmers using RPC do not need to understand the details of the interface with the network. Because RPC is a layer over the transport layer of the network, it separates the application from the physical and logical elements of the data communcations mechanisms. RPC is the predecessor to RMI. RMI makes object function calls between Java Virtual Machines (JVMs) possible, even when the JVMs are located on separate computers. Put another way, one JVM can call methods that belong to an object that is stored in another JVM. While many RPC and similar systems only allow simple parameters, RMI allows any Java object type to be passed as a parameter. RMI even allows both client and server to dynamically load new object types and pass them as parameters! RMI abstracts the problem so that the program/client machine does not know or care whether the requested object is executed locally or on another JVM. RMI also provides security and cross-platform portability that requires a large amount of overhead using RPC, but is limited since it can only call methods written in Java. Read the article by Waldo Waldo, J., "Remote Procedure Calls and Java Remote Method Invocation," IEEE Concurrency, vol. 6, no. 3, pp. 5-7, July 1998. Available at http://www.cs.kent.edu/~farrell/grid06/reference/waldo98.pdf, for a detailed comparison of RPC and RMI. STEP 2: Following the instructions in the Java RMI tutorial Read the steps of the Java Tutorial on RMI, available at Intro to RMI and Java RMI Tutotial at Sun to create a client/server program using RMI. The corresponding commands for use on cohn and its nodes are in the do.node1.server and do.node2.client files in http://www.cs.kent.edu/~farrell/RMI/CO Note! These commands will be different on cohn than specified in the tutorial: The -classpath option can be used on the command line to replace the setenv command used in the tutorial OR you can set and unset the CLASSPATH on cohn by using the env command as follows: env CLASSPATH /home/username/directory env --unset CLASSPATH Since there are multiple versions of Java on some of the nodes, you need to prefix the command names with /opt/IBMJava2-142/bin/ or modify your default path in order to ensure that you use the IBM version of Java consistently. If the following error occurs, you may need to restart the ComputeEngine before trying the client again. myCalculator exception: Connection refused to host: If you restart the server and things don't work, you may have to kill it and the rmiregistry program, and restart them both. STEP 3: Extend the Java RMI application Using the above information, your own programming skills, and the web as a reference, complete the following. Use cohn.cs.kent.edu for the assignment. Modify the PowerServer interface to also allow addition of two big integers subtraction of two big integers multiplication of two big integers integer division of two big integers which returns the floor of the integers and the remainder the greatest common divisor (GCD) of two big integers using the Euclidean Algorithm. The greatest common divisor is the largest number which divides both a and b without remainder. the least common multiple (LCM) of two big integers. The least common multiple is the smallest integer which both a and b can divide without remainder, and is given by a*b/gcd(a,b). Documentation on the biginteger class and constructors is at http://java.sun.com/j2se/1.4.2/docs/api/java/math/BigInteger.html. It may help to look through the available constructors!! The modified server, client etc should be named ExtPowerServer Modify the server and client accordingly to permit invoking these additional methods. Compile the files using javac and run them as in the original example. NOTE: javac may return errors if you use it to compile the files separately because it cannot resolve their dependencies. You can also use the classpath command line option to specify where to look for dependencies. STEP 4: Answer the post-exercise questions What is the environment variable CLASSPATH used for? What needs to be in the directory pointed to by it in the case of this assignment? All the Java server classes, including the stub and skeleton, were made available to the server in /home/user/RMI/PSS/. Were they all required for the programs to compile, and function correctly? Verify your answer. All the Java server classes, including the stub and skeleton, were made available to the client both in /home/farrell/RMI/PSClass/server.jar and via the -Djava.rmi.server.codebase=http://www.cs.kent.edu/~farrell/classes/ flag on the command line. Where are they obtained from? Verify your answer. The one client can call PowerService on any accessible computer by modifying the last argument on the command line. Can the client be made to call different services e.g. PowerService or ExtPowerservice on the same machine? If so explaoin how and any problems or disadvantages that arise. Describe at least four things that are different between a local method invocation (or procedure call) and what happens with RPC or RMI. Describe the assumptions of the Java RMI system and compare them to the assumptions of RPC or RMI as implemented in CORBA. Why does Waldo think that Java RMI is better than earlier systems? Do you think Java RMI is better than earlier systems? Explain your answers. How would Java RMI behave or respond in the presence of a network failure? Explain your answer. It may help in understanding the material and in answering the questions above to first answer the quiz questions at http://java.sun.com/developer/Quizzes/rmi/index.html. You will be shown the correct answers. You don't need to turn this in. Also answer the following questions, which will help to improve this assignment. Turn these answers in on a separate piece of paper without your name on it. How many hours did you spend on this assignment? Rate each of the following on a scale of 1-10 where 1 is "almost none" and 10 is "a whole lot" Rate your Java skills before the RMI programming assignment. Rate your Java skills now. Rate your prior experience with Java RMI. The assignment was reasonable, given your starting Java programming skills. The preliminary reading material was sufficient. If it was not, can you describe what was missing? The assignment was comprehensible. What would you change about this assignment? Enjoy! Last modified: Wed Aug 25 21:47:18 Central Daylight Time 2004