From: adash Date: Sat, 7 Mar 2009 01:16:42 +0000 (+0000) Subject: changes and some bug fixes X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=f8020cfd808611f1715c8275bde38a41a5be84a1;p=IRC.git changes and some bug fixes --- diff --git a/Robust/src/Benchmarks/Distributed/RainForest/java/RainForestClient.java b/Robust/src/Benchmarks/Distributed/RainForest/java/RainForestClient.java index fb219864..c35038f1 100644 --- a/Robust/src/Benchmarks/Distributed/RainForest/java/RainForestClient.java +++ b/Robust/src/Benchmarks/Distributed/RainForest/java/RainForestClient.java @@ -1,5 +1,5 @@ -#define ROW 100 /* columns in the map */ -#define COLUMN 100 /* rows of in the map */ +#define ROW 200 /* columns in the map */ +#define COLUMN 200 /* rows of in the map */ #define ROUNDS 200 /* Number of moves by each player */ #define PLAYERS 20 /* Number of Players when num Players != num of client machines */ #define RATI0 0.5 /* Number of lumberjacks to number of planters */ @@ -31,11 +31,8 @@ public class RainForestClient { /* Read player type from Server */ byte b[] = new byte[1]; //read planter or lumber jack - int numbytes; - while((numbytes = sock.read(b)) < 1) { - ; - } - String str = (new String(b)).subString(0, numbytes); + String str1 = rfc.readFromSock(sock, b, 1); + String str = str1.subString(0, 1); int person; if(str.equalsIgnoreCase("L")) { person = LUMBERJACK; @@ -44,6 +41,10 @@ public class RainForestClient { person = PLANTER; } + // Barriers for syncronization + Barrier barr; + barr = new Barrier("128.195.175.79"); + //Generate a random x and y coordinate to start with int maxValue = ROW - 1; int minValue = 1; @@ -64,9 +65,6 @@ public class RainForestClient { } } byte buf[] = new byte[9]; - String temp; - Barrier barr; - barr = new Barrier("128.195.175.79"); for(int i = 0; i= ROW && posY >= COLUMN) { + System.println("b[0] = "+(char)b[0]+" b[1]= "+(char)b[1]+" b[2]= "+(char)b[2]+" b[3]= "+(char)b[3]+" b[4]= "+(char)b[4]+" b[5]= "+(char)b[5]+" b[6]= "+(char)b[6]+" b[7]= "+(char)b[7]+ " b[8]= " +(char)b[8]); + } if(b[0] == (byte) 'T') { land[posX][posY].putTree(new TreeType()); @@ -168,8 +182,8 @@ public class RainForestClient { // //Debug + //printLand(land, ROW, COLUMN); // - /* printLand(land, ROW, COLUMN); */ // 2. Get type of player (lumberjack or planter) int type = gamer.kind(); @@ -203,9 +217,9 @@ public class RainForestClient { /* Reset state if there in no path from start to goal */ if(newpath == null) { // - //Debug + // Debug + // System.println("Path from ("+currx+","+curry+") to ("+gamer.getGoalX()+","+gamer.getGoalY()+") is null"); // - /* System.println("Path from ("+currx+","+curry+") to ("+gamer.getGoalX()+","+gamer.getGoalY()+") is null"); */ gamer.reset(land, ROW, COLUMN, BLOCK); gamer.setState(INIT); @@ -347,4 +361,15 @@ public class RainForestClient { return b; } + + String readFromSock(Socket sock, byte[] buf, int maxBytes) { + int numbytes = 0; + String rstr = new String(""); + while(numbytes < maxBytes) { + int nread = sock.read(buf); + numbytes += nread; + rstr = rstr.concat((new String(buf)).subString(0,nread)); + } + return rstr; + } } diff --git a/Robust/src/Benchmarks/Distributed/RainForest/java/RainForestServerExample.java b/Robust/src/Benchmarks/Distributed/RainForest/java/RainForestServerExample.java index 6dde612d..094852d7 100644 --- a/Robust/src/Benchmarks/Distributed/RainForest/java/RainForestServerExample.java +++ b/Robust/src/Benchmarks/Distributed/RainForest/java/RainForestServerExample.java @@ -1,5 +1,5 @@ -#define ROW 100 /* columns in the map */ -#define COLUMN 100 /* rows of in the map */ +#define ROW 200 /* columns in the map */ +#define COLUMN 200 /* rows of in the map */ public class RainForestServerExample { private int numThreads; @@ -70,6 +70,7 @@ public class RainForestServerExample { } System.printString("Finished\n"); + //System.exit(0); } /** diff --git a/Robust/src/Benchmarks/Distributed/RainForest/java/RainForestServerThread.java b/Robust/src/Benchmarks/Distributed/RainForest/java/RainForestServerThread.java index ebd370a9..a6096609 100644 --- a/Robust/src/Benchmarks/Distributed/RainForest/java/RainForestServerThread.java +++ b/Robust/src/Benchmarks/Distributed/RainForest/java/RainForestServerThread.java @@ -31,62 +31,51 @@ public class RainForestServerThread extends Thread { // //Debugging + //printLand(land, rows, cols); // - /* printLand(land, rows, cols); */ byte[] buf = new byte[5]; //1 byte to decide if terminate or continue + 4 bytes for getting the round index - int numbytes; byte[] buffer = new byte[9]; //1 byte presence of tree/rocks + 8 bytes for their x and y coordinates while(true) { - /* Check for termination character */ - while((numbytes = sock.read(buf)) < 5) { - //System.println("Looping in 2"); - ; - } - - String str1 = (new String(buf)).subString(0, 1); + String readStr = readFromSock(sock, buf, 5); + String str1 = readStr.subString(0, 1); /* terminate if opcode sent is "t" */ if(str1.equalsIgnoreCase("T")) { break; } else if(str1.equalsIgnoreCase("U")) { + buf = readStr.getBytes(); int roundIndex = getX(buf); //Get the index from client - System.println("round id = " + roundIndex); + + /* Update age of all trees in a Map */ if((roundIndex % AGEUPDATETHRESHOLD) == 0 && (id == 0)) { - /* Update age of all trees in a Map */ updateAge(land, MAXAGE, rows, cols); } - /* Data representing presence/absence of trees */ + /* Send data representing presence/absence of trees */ for(int i=0 ; i> offset) & 0xFF); + } + for(int i = 5; i<9; i++) { + int offset = (3-(i-5)) * 8; + b[i] = (byte) ((y >> offset) & 0xFF); + } + return b; + } + /** ** Only for Debugging **/ @@ -233,4 +233,18 @@ public class RainForestServerThread extends Thread { //System.println("Tree count= "+countTrees); // } + + /** + ** Repeated read until you get all bytes + **/ + String readFromSock(Socket sock, byte[] buf, int maxBytes) { + int numbytes = 0; + String rstr = new String(""); + while(numbytes < maxBytes) { + int nread = sock.read(buf); + numbytes += nread; + rstr = rstr.concat((new String(buf)).subString(0,nread)); + } + return rstr; + } } diff --git a/Robust/src/Benchmarks/Distributed/RainForest/java/makefile b/Robust/src/Benchmarks/Distributed/RainForest/java/makefile index 12910860..cbe1ecaf 100644 --- a/Robust/src/Benchmarks/Distributed/RainForest/java/makefile +++ b/Robust/src/Benchmarks/Distributed/RainForest/java/makefile @@ -8,28 +8,27 @@ SRC=tmp${MAINCLASS1}.java \ Player.java \ BarrierNonDSM.java -SRC1 =tmp${MAINCLASS2}.java \ - GameMap.java \ - TreeType.java \ - RockType.java \ - Goal.java \ - Path.java \ - Node.java \ - Player.java \ - AStarPathFinder.java \ - BarrierNonDSM.java +SRC1=tmp${MAINCLASS2}.java \ + GameMap.java \ + TreeType.java \ + RockType.java \ + Goal.java \ + Path.java \ + Node.java \ + Player.java \ + AStarPathFinder.java \ + BarrierNonDSM.java - FLAGS1= -thread -nooptimize -debug -mainclass ${MAINCLASS1} FLAGS2= -thread -nooptimize -debug -mainclass ${MAINCLASS2} default: - cpp RainForestServerExample.java > tmp1RainForestServerExample.java - cpp RainForestServerThread.java > tmp1RainForestServerThread.java - cpp RainForestClient.java > tmp1RainForestClient.java - ./extractLines - ../../../../buildscript ${FLAGS1} -o Server ${SRC} - ../../../../buildscript ${FLAGS2} -o Client ${SRC1} + cpp RainForestServerExample.java > tmp1RainForestServerExample.java + cpp RainForestServerThread.java > tmp1RainForestServerThread.java + cpp RainForestClient.java > tmp1RainForestClient.java + ./extractLines + ../../../../buildscript ${FLAGS1} -o Server ${SRC} + ../../../../buildscript ${FLAGS2} -o Client ${SRC1} clean: rm -rf tmpbuilddirectory