char command;\r
String key;\r
String val;\r
- boolean isDir;\r
-\r
GlobalString gkey;\r
GlobalString gval;\r
+ boolean isDir;\r
\r
int index;\r
String file;\r
command = t.getCommand();\r
key = t.getKey();\r
\r
+ atomic {\r
+ gkey = global new GlobalString(key);\r
+ }\r
+\r
index = key.lastindexOf('/');\r
if (index+1 == key.length()) \r
isDir = true;\r
else \r
isDir = false;\r
\r
- atomic {\r
- gkey = global new GlobalString(key);\r
- }\r
-\r
if (command == 'r') {\r
- System.out.println("["+command+"] ["+key+"]");\r
- atomic {\r
- if (isDir == true) {\r
- readDirectory(gkey);\r
- }\r
- else {\r
+ System.out.println("["+command+"] ["+key+"]");\r
+ if (isDir == true) {\r
+ atomic {\r
+ readDirectory(gkey);\r
+ }\r
+ }\r
+ else {\r
+ atomic {\r
readFile(gkey);\r
- }\r
+ }\r
}\r
- }\r
+ }\r
else if (command == 'c') {\r
- System.out.println("["+command+"] ["+key+"]");\r
- atomic {\r
- if (isDir == true) {\r
- createDirectory(gkey);\r
- }\r
- else {\r
- val = t.getValue();\r
+ System.out.println("["+command+"] ["+key+"]");\r
+ if (isDir == true) {\r
+ atomic {\r
+ createDirectory(gkey);\r
+ }\r
+ }\r
+ else {\r
+ val = t.getValue();\r
+ atomic {\r
gval = global new GlobalString(val);\r
createFile(gkey, gval);\r
- }\r
- }\r
+ }\r
+ }\r
}\r
}\r
\r
\r
public void readFile(GlobalString gkey) {\r
GlobalString gval;\r
+ String val;\r
\r
- gval = (GlobalString)(fs.get(gkey));\r
- if (gval != null) {\r
-// System.out.println("<"+gval.toLocalString()+">");\r
+ atomic {\r
+ gval = (GlobalString)(fs.get(gkey));\r
+ val = gval.toLocalString();\r
+ }\r
+ if (val != null) {\r
+// System.out.println("<"+val+">");\r
}\r
else {\r
System.out.println("No such file or directory");\r
}\r
\r
public void createFile(GlobalString gkey, GlobalString gval) {\r
- GlobalString path;\r
- GlobalString target;\r
+ String path;\r
+ String target;\r
+ GlobalString gpath;\r
+ GlobalString gtarget;\r
int index;\r
DistributedLinkedList list;\r
\r
index = gkey.lastindexOf('/');\r
- path = gkey.subString(0, index+1);\r
- target = gkey.subString(index+1);\r
+ gpath = gkey.subString(0, index+1);\r
+ gtarget = gkey.subString(index+1);\r
\r
- if (dir.containsKey(path)) {\r
- list = (DistributedLinkedList)(dir.get(path));\r
- list.push(target);\r
- dir.put(path, list);\r
+ if (dir.containsKey(gpath)) {\r
+ list = (DistributedLinkedList)(dir.get(gpath));\r
+ list.push(gtarget);\r
+ dir.put(gpath, list);\r
fs.put(gkey, gval);\r
}\r
else {\r
\r
public void createDirectory(GlobalString gkey) {\r
int index;\r
- GlobalString path;\r
- GlobalString target;\r
+ GlobalString gpath;\r
+ GlobalString gtarget;\r
DistributedLinkedList list;\r
\r
index = gkey.lastindexOf('/', gkey.length()-2);\r
\r
if (index != -1) {\r
- path = gkey.subString(0, index+1);\r
- target = gkey.subString(index+1);\r
+ gpath = gkey.subString(0, index+1);\r
+ gtarget = gkey.subString(index+1);\r
\r
- if (dir.containsKey(path)) {\r
- list = (DistributedLinkedList)(dir.get(path));\r
- list.push(target);\r
- dir.put(path, list);\r
+ if (dir.containsKey(gpath)) {\r
+ list = (DistributedLinkedList)(dir.get(gpath));\r
+ list.push(gtarget);\r
+ dir.put(gpath, list);\r
\r
list = global new DistributedLinkedList();\r
dir.put(gkey, list);\r
System.out.println("Cannot create directory");\r
}\r
}\r
+ else {\r
+ System.out.println("Cannot create directory");\r
+ }\r
}\r
\r
public Object read(DistributedHashMap mydhmap, GlobalString key) {\r
\r
public static void main(String[] args) {\r
int NUM_THREADS = 3;\r
- String filename;\r
+ String filename = new String();\r
\r
- NUM_THREADS = Integer.parseInt(args[0]);\r
- filename = args[1];\r
+ if (args.length == 2) {\r
+ NUM_THREADS = Integer.parseInt(args[0]);\r
+ filename = args[1];\r
+ }\r
+ else {\r
+ System.out.println("./FileSystem.bin master <num_thread> <data>");\r
+ System.exit(0);\r
+ }\r
\r
int[] mid = new int[8];\r
mid[0] = (128<<24)|(195<<16)|(180<<8)|21;//dw-2\r