CSS 533 Program 2: Distributed Java Space Servers Professor: Munehiro Fukuda Due date: see the syllabus

Similar documents
CSS 533 Program 3: Mobile-Agent Execution Platform Professor: Munehiro Fukuda Due date: see the syllabus

CSS 543 Program 2: Multithreaded Schroedinger s Wave Simulation Professor: Munehiro Fukuda Due date: see the syllabus

Assignment 1. Due date February 6, 2007 at 11pm. It must be submitted using submit command.

Introduction IS

Input from Files. Buffered Reader

CSS 534 Program 2: Parallelizing Wave Diffusion with MPI and OpenMP Professor: Munehiro Fukuda Due date: see the syllabus

1. Download the JDK 6, from

I/O in Java I/O streams vs. Reader/Writer. HW#3 due today Reading Assignment: Java tutorial on Basic I/O

Basic I/O - Stream. Java.io (stream based IO) Java.nio(Buffer and channel-based IO)

09-1. CSE 143 Java GREAT IDEAS IN COMPUTER SCIENCE. Overview. Data Representation. Representation of Primitive Java Types. Input and Output.

Input, Output and Exceptions. COMS W1007 Introduction to Computer Science. Christopher Conway 24 June 2003

Internet Technology 2/7/2013

Darshan Institute of Engineering & Technology for Diploma Studies

Network Programming. Powered by Pentalog. by Vlad Costel Ungureanu for Learn Stuff

CSS 503 Program 1: Parallelizing a Convex-Hull Program with Multi-Processes Professor: Munehiro Fukuda Due date: see the syllabus

Basic Java Network Programming. CS211 July 30 th, 2001

Dining philosophers (cont)

Web Server Project. Tom Kelliher, CS points, due May 4, 2011

CSCI 136 Written Exam #1 Fundamentals of Computer Science II Spring 2014

1.00 Lecture 30. Sending information to a Java program

Programming Languages and Techniques (CIS120)

Java Input/Output. 11 April 2013 OSU CSE 1

Lab 1 : Java Sockets

Java Socket Workshop. July Purpose of this workshop:

Exceptions and Working with Files

Lab 5: Java IO 12:00 PM, Feb 21, 2018

File IO. Computer Science and Engineering College of Engineering The Ohio State University. Lecture 20

CS September 2017

Introduction to Programming Using Java (98-388)

Byte and Character Streams. Reading and Writing Console input and output

CN208 Introduction to Computer Programming

Multiplayer Game Programming 2/26

Java in 21 minutes. Hello world. hello world. exceptions. basic data types. constructors. classes & objects I/O. program structure.

CS1092: Tutorial Sheet: No 3 Exceptions and Files. Tutor s Guide

Software Practice 1 - Socket

Week 13 Lab - Exploring Connections & Remote Execution

Week 12. Streams and File I/O. Overview of Streams and File I/O Text File I/O

Example: Copying the contents of a file

Network. Dr. Jens Bennedsen, Aarhus University, School of Engineering Aarhus, Denmark

Java Networking (sockets)

Lab 10: Sockets 12:00 PM, Apr 4, 2018

Overview CSE 143. Data Representation GREAT IDEAS IN COMPUTER SCIENCE. Representation of Primitive Java Types. CSE143 Sp

Overview CSE 143. Data Representation GREAT IDEAS IN COMPUTER SCIENCE. Representation of Primitive Java Types. CSE143 Au

Overview CSE 143. Data Representation GREAT IDEAS IN COMPUTER SCIENCE

Java Support for developing TCP Network Based Programs

Options for User Input

Overview CSE 143. Input and Output. Streams. Other Possible Kinds of Stream Converters. Stream after Stream... CSE143 Wi

Interprocess Communication

Programming Languages and Techniques (CIS120)

Software Practice 1 - File I/O

Programming Problems 15th Annual Computer Science Programming Contest

CS 251 Intermediate Programming Java I/O Streams

Text User Interfaces. Keyboard IO plus

CS 2113 Software Engineering

Tirgul 1. Course Guidelines. Packages. Special requests. Inner classes. Inner classes - Example & Syntax

Java for Interfaces and Networks

Object-Oriented Programming Design. Topic : Streams and Files

Shell Interface Assignment

CS506 Web Design & Development Final Term Solved MCQs with Reference

Lab 2: File Input and Output

Java How to Program, 9/e. Copyright by Pearson Education, Inc. All Rights Reserved.

Performing input and output operations using a Byte Stream

Lecture 11.1 I/O Streams

Today. Book-keeping. File I/O. Subscribe to sipb-iap-java-students. Inner classes. Debugging tools

CSCD 330 Network Programming

Lecture 4: Exceptions. I/O

CSCD 330 Network Programming

Overview CSE 143. Data Representation GREAT IDEAS IN COMPUTER SCIENCE

Java Programming. Manuel Oriol, March 22nd, 2007

Exceptions and Libraries

Timing ListOperations

Virtualians.ning.pk. 2 - Java program code is compiled into form called 1. Machine code 2. native Code 3. Byte Code (From Lectuer # 2) 4.

Chapter 10. IO Streams

Lesson 3: Accepting User Input and Using Different Methods for Output

CSCD 330 Network Programming

תוכנה 1 תרגול 8 קלט/פלט רובי בוים ומתי שמרת

Networking Basics. network communication.

Object Oriented Design. Object-Oriented Design. Inheritance & Polymorphism. Class Hierarchy. Goals Robustness Adaptability Flexible code reuse

CS 231 Data Structures and Algorithms, Fall 2016

Streams and File I/O

Network Programming Benoît Garbinato

Project #1 Computer Science 2334 Fall 2008

I/O Streams. Object-oriented programming

COMP 213. Advanced Object-oriented Programming. Lecture 19. Input/Output

Pieter van den Hombergh Richard van den Ham. March 17, 2018

What is Serialization?

Getting Started in Java. Bill Pugh Dept. of Computer Science Univ. of Maryland, College Park

HST 952. Computing for Biomedical Scientists Lecture 8

Project #1 rev 2 Computer Science 2334 Fall 2013 This project is individual work. Each student must complete this assignment independently.

Object-Oriented Design. March 2005 Object Oriented Design 1

Java Coding style guide 1. Java. Coding Style Guide. (July 2015)

Principles, Models and Applications for Distributed Systems M

CIS 120 Final Exam May 3, Name (printed): Pennkey (login id):

Project 1 Computer Science 2334 Spring 2016 This project is individual work. Each student must complete this assignment independently.

PIC 20A Streams and I/O

Java for Interfaces and Networks (DT3029)

CS 101 Fall 2005 Midterm 2 Name: ID:

Exceptions vs. Errors Exceptions vs. RuntimeExceptions try...catch...finally throw and throws

Java Programming Language Advance Feature

Each command-line argument is placed in the args array that is passed to the static main method as below :

Transcription:

CSS 533 Program 2: Distributed Java Space Servers Professor: Munehiro Fukuda Due date: see the syllabus 1. Purpose This assignment implements a collection of distributed Java Space servers, which exercises how to launch remote processes through JSCH, how to multicast a UDP message, and how to implement distributed hash tables. 2. Concept of Distributed Java Space Servers As shown in the figure below, we assume that there are one server administrator and multiple client users. Our distributed Java Space servers, (simply called JSpace servers) run in the master-slave model. The server administrator starts the master JSpace server that launches a slave server at each of remote computing nodes, using the JSCH (secured ssh connection) library. java -cp jsch-0.1.44.jar:jspace.jar JSpace.Server config.txt Entry( int, var2, 20 ) Entry( int, var1, 10 ) Jspace.Server Jsch connection show and quit command Multicast an entry (write) Jspace.Client Client 1 uw1-320- 01 uw1-320- 10 Jspace.Server Jspace.Server Server admin uw1-320- 00 uw1-320- 01 Multicast an entry (read/take) Jspace.Client Jspace.Server A UDP response Client 2 Entry( double, var1, 10.0 ) uw1-320- 11 uw1-320- 01 Multicast Group 239.255.255.255:50763

Note that config.txt includes the administrator s account, multicast group IP, port, and all slave IP address information as seen in Lab 3. Upon a slave server initialization, the master should send the following information to the slave: (1) Multicast group IP (2) Port (3) # of servers (including the master), say N (4) Server ID (where the master receives 0 and slaves are identified with 1 through to N 1) Each server including the master creates a local hash table to maintain user data items, (each packetized in an Entry object). For simplicity, we focus on only eight data types for Entry objects: byte, char, short, int, long, float, double, and java.lang.string. The way to store which entry into which server is up to your implementation, however the same entry should not be duplicated over multiple servers. In the key answer, each server maintains entries with the same data type. For instance, server 0 takes care of bytes and saver 1 handles chars. Once all servers are booted up, the server administrator can type in show or quit from the keyboard, each then sent through JSCH connections to all the slaves. All the servers including the master must respond to each command as follows: (1) show: each slave server sends its local hash table contents back to the master, whereas the master server displays all these hash table contents including its own to the administrator s monitor. (2) quit: all slave servers acknowledge to the master, upon which they all terminate themselves. JSpace client users can send write, read, and take operations to distributed servers through UDP multicast whose group IP and port should be the same as what the servers are using. For example, a write request can be coded as follows: 1: public class Writer { 2: private final static String multicast_group = "239.255.255.255"; 3: private final static int port = 50763; 4: 5: public class Data extends JSpace.Entry { 6: public double variable = 1.7320508075; // a value to write 7: public void printval( ) { 8: System.out.println( variable ); 9: 10: 11: / 12: This constructor instantiates a JavaSpace client and a data entry, 13: thereafter access the space to write a double value, (i.e., 14: 1.7320508075) into the space. 15: / 16: public Writer( ) { 17: JSpace.Client client = new JSpace.Client( multicast_group, port ); 18: 19: Data data = new Data( ); 20: client.write( data ); 21: 22: 23: / 24: The actual program starts from the main( ) and instantiates a Writer 25: object. 26: 27: @param args nothing to pass 28: / 29: 30: public static void main( String[] args ) { 31: new Writer( ); 32: 33:

This user client joins the Java Space with a JSpace.Client instantiation (line 17), creates a JSpace.Entry object that is named data (line 19) and that includes a double-typed variable (= 1.7320508075) (line 6), and sends it to distributed servers through client.write(data) (line 20). Note that all the client-side programs has been already coded, so that you don t have to write anything except your own test program. Each JSpace server should be multithreaded so as to interact with the master server, to watch requests from clients, and to hand each request in parallel: (1) The main thread: always reads a show or quit message from the master server and performs the according action. (2) The persistent child thread (named SpaceThread in the key answer): always waits for a new UDP multicast message from a client, instantiates a new per-request thread (SessionThread), and passes the message to the new thread. (3) A per-request child thread (named SessionThread in the key answer): receives a message from SpaceThread, extracts an entry from it if SessionThread should respond to this message, (otherwise simply discards it), and performs a write, read, or take operation, each corresponding to Hashtable.put(key, value), get(key), and remove(key). If the operation is read or take, SessionThread sends back the corresponding entry to the client, using an ordinary UDP socket (but not a multicast). The JSpace.Entry class has been already implemented and you can examine a given entry s data type, variable name, its value, and operation through gettype( ), getname( ), getvalue( ) and getoperation( ): public class Entry implements Serializable { // Attributes private String vartype; // a key to send this entry to a JSpace server private String varname; // a key to store this entry into a server hash private int operation; // JavaSpace Op: 0 = read, 1 = write, 2 = take private Object value; // a user-define value public String gettype( ) { return vartype; // returns the variable type of this entry. public String getname( ) { return varname; // returns the variable name of this entry. public int getoperation( ) { return operation; //returns the operation type: read=0, write=1, take=2 public Object getvalue( ) { return value; // returns an object that contains the value 3. JSpace.jar: Java Space Programs This is a jar file that includes all class files to launch a collection of distributed Java Space servers. It is located at ~css533/programming/prog2, and the corresponding java source code and byte code are found at the ~css533/programming/prog2/jspace/ directory. Java programs Descriptions Server.java Is a framework of a distributed Java Space server that establishes a JSCH connection from the master to all slave servers and launches a slave server at each remote computing node. The actual implementation is JSpace.java. Connection.java Establishes a JSCH connection to a remote computing node. JSpace.java Implements all the JSpace server features listed above. This is what you have to implement. Client.java Is instantiated within a Java Space client user program and interacts with distributed Java Space servers. Entry.java Is a data unit exchanged between a Java Space client and distributed servers. All java files except JSpace.java are worldwide readable and need not to be modified at all. Server.java and Connection.java are exactly the same as Lab 3. In other words, Server.java has already implemented

the code that establishes a secured TCP connection to each remote computing node and launches Java JSpace.Server there. All you need is to design and implement JSpace.java: In the following Server.java code, you will instantiate a JSpace object both at the master and slaves. (See the shaded and underlined statements below.) package JSpace; import com.jcraft.jsch.; import java.io.; import java.net.; import java.util.; public class Server { / The main() function runs both at the user local and remote machines. @param args args[0] receives the configuration file name / public static void main( String[] args ) { if ( args.length == 1 ) new Server( args[0] ); // master server to run locally else if ( args.length == 0 ) new Server( ); // slave servers to run remotely else { // invalid arguments System.err.println( "usage: java -cp jsch-0.1.44.jar:. JSpace.Server config.txt" ); System.exit( -1 ); / This is the constructor executed at a user-local machine. @param configfile a configuration file name. It must include: user account (1st line); password (2nd line); and all remote host IP names (the rest). / public Server( String configfile ) { final int JschPort = 22; // Jsch IP port // Read configfile to initialize username, password, and hosts BufferedReader filereader = null; String username = null; String password = null; String multicast_group = null; int port = 0; ArrayList<String> hosts = new ArrayList<String>( ); try { // Open a configuration file filereader = new BufferedReader( new InputStreamReader ( new BufferedInputStream ( new FileInputStream ( new File( configfile ) ) ) ) ); // Read all the contents // 1st line: username username = filereader.readline( ); // Read the password from the console password = new String( System.console( ).readpassword( "Password: " ) ); // 2nd line: multicast group such as 239.255.255.255 multicast_group = filereader.readline( ); // 3rd line: IP port such as 50763 port = Integer.parseInt( filereader.readline( ) ); // the rest: remote host IPs while ( filereader.ready( ) ) hosts.add( filereader.readline( ) ); filereader.close( ); catch( Exception e ) { e.printstacktrace( ); System.exit( -1 ); // A command to launch remotely:

// java -cp./jsch-0.1.44.jar:. JSpace.Server String cur_dir = System.getProperty( "user.dir" ); String command = "java -cp " + cur_dir + "/jsch-0.1.44.jar:" + cur_dir + " JSpace.Server"; // establish an ssh2 connection to each remote machine and run // JSpace.Server there. Connection connections[] = new Connection[hosts.size( )]; for ( int i = 0; i < hosts.size( ); i++ ) { connections[i] = new Connection( username, password, hosts.get( i ), command ); // the main body of the master server new JSpace( connections, multicast_group, port ); // close the ssh2 connection with each remote machine for ( int i = 0; i < hosts.size( ); i++ ) { connections[i].close( ); / This is the constructor executed at each remote machine. / public Server( ) { // receive an ssh2 connection from a user-local master server. Connection connection = new Connection( ); // the main body of the slave server new JSpace( connection ); 4. Client-side User Programs: Writer.java, Reader.java and Taker.java These programs are Java Space user applications, each writing a Java Space data unit (named an entry) into, reading it from, and taking it out of a Java Space that is globally maintained by a collection of Java Space servers, (i.e., JSpace.Server). They are located at ~css533/programming/prog2. Java programs Writer.java Reader.java Taker.java Descriptions Is an example user program that behaves as a Java Space client and writes a doubletype value, (i.e., 1.7320508075) to the Java Space identified with 239.255.255.255:50763. To run your own Java Space environment, you need to change GroupAddress:Port. Is an example user program that behaves as a Java Space client and reads a doubletype variable from the Java Space identified with 239.255.255.255:50763. To urn your own Java Space environment, you need to change GroupAddress:port. Is an example user program that behaves as a Java Space client and takes a doubletype variable out of the Java Space identified with 239.255.255.255:50763. To run your own Java Space environment, you need to change GroupAddress:port. 5. Compilation Let us assume that you have created a new working directory prog2/. You need to make sure: (1) You must also create the JSpace/ directory under prog2/. (2) Client.java, Server.java, Conenction.java, Entry.java, and JSpace.java should be stored under prog2/jspace/. (3) Your JSpace.java must include package JSpace; at the top of their file. (4) Writer.java, Reader.java, and Taker.java are stored under prog2/. (5) ~css533/prog2/compile.sh, run.sh, and jsch-0.1.44.jar should be copied under prog2/

Thereafter, to compile them all, run compile.sh at prog2/ #!/bin/sh javac -cp./jsch-0.1.44.jar:. JSpace/.java jar cvf JSpace.jar JSpace/.class javac.java You will find JSpace.jar, Writer.class, Reader.class, and Taker.class, all under prog2/. 6. Execution First of all, you need to create config.txt under prog2/. The file format is: Line 1: your UnetID Line 2: group IP address Line 3: port Line 4: a remote host 1 s IP Line 5: a remote host 2 s IP For example, if you (with the mickey account) want to run the master server and three slave servers, you should write in config.txt as follows: mickey 239.255.255.255 12345 uw1-320-10 uw1-320-11 uw1-320-12 To launch servers, run run.sh at prog2/ #!/bin/sh java -cp jsch-0.1.44.jar:jspace.jar JSpace.Server config.txt Thereafter, you can start a client user program such as Writer.class,Reader.class, and Taker.class. To run each, type from prog2/: java cp JSpace.jar:. Writer java cp JSapce.jar:. Reader java cp JSpace.jar:. Taker 7. Statement of Work Requirement 1: Implement the following two programs: (a) JSpace.java: the actual implementation of your Java Space server (b) TestProgram.java: a client-side user program that conducts much more serious tests onto your Java Space servers than just Writer.java, Reader.java and Taker.java do.

Requirement 2: Develop your distributed hashing algorithm, different from the original JSpace.java (i.e., the key answer that has each server take care of entries with the same data type). For instance, you can have each server take care of entries with the same initial of their variable names. Requirement 3: Verify the correctness of your Java Space server implementation, using Writer.java, Reader.java, Taker.java, and your TestProgram.java. Your report must include execution outputs to demonstrate your code verification, as changing the number of servers from 1 through to 4. 8. What to Turn in This programming assignment is due at the beginning of class on the due date. Please turn in a PDFformatted report through CollectIt, which includes the following items: Criteria Grade Documentation of your implementation of the JSpace server in one or two pages. Insufficient 5pts or too much (i.e., less than 1 page or more than 2 pages) documentation receives 4pts. Source code that adheres good modularization, coding style, and an appropriate amount of 5pts commends. Multithreading 0.5pts: The main thread interacts with the master server. 0.5pts: JpaceThread watches a multicast UDP message from a client. 0.5pts: SessionThread analyzes a given entry and performs its write, read, or take operation. JSpace operations 0.5pts: write chooses one JSpace server to store a new entry. 0.5pts: read/take suspends a SessionThread until a requested entry is written in a local hash. 0.5pts: take removes a requested entry from a local hash. Master/slave interaction 0.5pts: show lists all hash table contents on the administrator s window. 0.5pts: quit terminates all distributed servers quietly. 1pt: Good modularization, coding, style, and an appropriate amount of comments Execution output that verifies the correctness of all your implementation. 1pt: An execution scenario of 1 st : Writer.java, 2 nd Reader.java, and 3 rd Taker.java 1pt: An execution scenario of 1 st : Reader.java, 2 nd Writer.java, and 3 rd Taker.java 1pt: Output(s) of your TestProgram.java execution 0.5pts: Output(s) of the show command 0.5pts: Output(s) of the quit command 1pt: Verification output(s) when using one through to four JSpace servers Discussions about your own distributed hashing algorithm, limitations, and possible improvements of your program in one or two pages (firm). 2pts: Discussions about your own distributed hashing algorithm rather than the key answer s original hashing that stores entries with the same data type into the same server. 3pts: Discussions about limitations and possible improvements. Lab Sessions 3 counts 1pt. Please turn in this lab exercise through CollectIt by Program 2 s due date. Total Note that program 2 (including Lab 3) takes 15% of your final grade. 5pts 5pts 1pts 21pts

9. Hints Since HW2 focuses on distributed hashing, you do not have to spend too much time for UDP multicast as well as one-to-one communication. You can reuse the code from ~css533/samples/java_sockets/. Java programs Descriptions MulticastServer.java Usage: java MulticastServer groupip:port Use a snippet of this program inside your JSpace.JSpace.java to receive a multicast UDP packet. TcpUdpClient.java Usage: java Client udp tcp server port message. Use its udp( ) function inside your JSpace.JSpace.java to send a UDP packet to the corresponding JSpace.Client. Assuming that your JSpace server receive a multicast packet in packet, you can identify its client IP address by: InetAddress srcaddress = packet.getaddress( ) Your JSpace server needs to deserialize a byte array into an entry when receiving a DatagramPacket from a client as well as to serialize an entry into a byte array when sending it as a DatagramPacket to the client. Use the following two methods of JSpace.Entry class. / serialize() serializes a given entry into a byte array so that the array can be passed to a UDP socket. @param entry an entry to be serialized into a byte array. @return a byte array that serialized a given entry. / public static byte[] serialize( Entry entry ) throws IOException / deserialize() reconstruct a new entry from a given byte array. @param buf a byte array to be deserialized back to a new entry @return a new entry that was deseralized from a gvien array, i.e. buf[]. / public static Entry deserialize( byte[] buf ) throws IOException, ClassNotFoundException Please note that all JSpace slave servers communicate with the master through System.in and System.out. Therefore, you cannot print out any debugging information through System.out in each slave. To see such information, your JSpace.JSpace.java should open a file and write such debugging information onto it. Be sure that the file name must be different for each slave server. Otherwise all slaves will end up with overwriting their messages onto the same file.