public class LookUpService extends Task {\r
DistributedHashMap dir;\r
DistributedHashMap fs;\r
+ GlobalString error[]; // String for incorrect path, etc.\r
\r
public LookUpService(Queue todoList, DistributedHashMap dir, DistributedHashMap fs) {\r
this.todoList = todoList;\r
}\r
\r
public void init() {\r
+ makeErrorStatement();\r
fillHashTable();\r
fillTodoList();\r
}\r
+\r
+ public void makeErrorStatement() {\r
+ int num = 4;\r
+ int i = 0;\r
+\r
+ atomic {\r
+ error = global new GlobalString[num];\r
+\r
+ error[i++] = global new GlobalString("/hkhang/error/"); // w: no root (hkhang), r: non existed path\r
+ error[i++] = global new GlobalString("/home/abc/def/ghi/"); // w: create multiple directories, r: non existed path\r
+ error[i++] = global new GlobalString("/home/hkhang/abc"); // w: create directory and file together\r
+ error[i++] = global new GlobalString("/home/hkhang/abc/def"); // w: create directory and file together\r
+ }\r
+ }\r
\r
public void fillHashTable() {\r
GlobalString path;\r
DistributedLinkedList list; \r
\r
atomic {\r
- path = global new GlobalString("/home/");\r
+ path = global new GlobalString("/home/"); // root is home\r
list = global new DistributedLinkedList();\r
\r
dir.put(path, list);\r
}\r
}\r
\r
- int rdprob = 95;\r
+ int rdprob = 93;\r
+ int wrtprob = 98;\r
int dirprob = 90;\r
int rdwr;\r
int isdir;\r
isdir = rand.nextInt(100);\r
findex = rand.nextInt(1000);\r
\r
- if (rdwr < rdprob) {\r
+ if (rdwr < rdprob) { // read\r
c = 'r';\r
if (isdir < dirprob) { // file\r
file = global new GlobalString(str+"file_"+findex);\r
t = global new Transaction(c, directory);\r
}\r
}\r
- else {\r
+ else if (rdwr >= rdprob && rdwr < wrtprob) { // write\r
c = 'w';\r
if (isdir < dirprob) { // file\r
file = global new GlobalString(str+"file_"+findex);\r
t = global new Transaction(c, directory);\r
}\r
}\r
+ else { // error\r
+ int err = rand.nextInt(4);\r
+ file = error[err];\r
+ val = global new GlobalString("It is error path!!");\r
+ t = global new Transaction(c, file, val);\r
+ }\r
todoList.push(t);\r
}\r
}\r