changeset 52:61b2de3f7730

add HashSetDataSegment and HashLogUpdateCodeSegment. fix bugs
author one
date Sat, 13 Jul 2013 17:10:14 +0900
parents 9e782b4eb06e
children f47a02368099
files src/alice/jungle/codesegment/HashLogUpdateCodeSegment.java src/alice/jungle/codesegment/LogUpdateCodeSegment.java src/alice/jungle/datasegment/HashSetDataSegment.java src/alice/jungle/datasegment/store/operations/DefaultTreeOperationLogContainer.java src/jungle/test/bbs/NetworkJungleBulletinBoard.java src/jungle/test/bbs/codesegment/ChildLogCheckCodeSegment.java src/jungle/test/bbs/codesegment/StartBBSCodeSegment.java
diffstat 7 files changed, 88 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/alice/jungle/codesegment/HashLogUpdateCodeSegment.java	Sat Jul 13 17:10:14 2013 +0900
@@ -0,0 +1,27 @@
+package alice.jungle.codesegment;
+
+import alice.codesegment.CodeSegment;
+import alice.datasegment.CommandType;
+import alice.datasegment.Receiver;
+import alice.jungle.datasegment.HashSetDataSegment;
+
+public class HashLogUpdateCodeSegment extends CodeSegment {
+	
+	Receiver hashLog = ids.create(CommandType.PEEK);
+	
+	String str;
+	
+	public HashLogUpdateCodeSegment(String _str) {
+		hashLog.setKey("hashLog");
+		str = _str;
+	}
+	
+	public void run() {
+		System.out.println("HashLogUpdateCodeSegment");
+		System.out.println("str : "+str);
+		HashSetDataSegment ds = hashLog.asClass(HashSetDataSegment.class);
+		ds.hash.add(str);
+		ods.put("hashLog", ds);
+	}
+
+}
--- a/src/alice/jungle/codesegment/LogUpdateCodeSegment.java	Sat Jul 13 15:59:47 2013 +0900
+++ b/src/alice/jungle/codesegment/LogUpdateCodeSegment.java	Sat Jul 13 17:10:14 2013 +0900
@@ -11,30 +11,37 @@
 import alice.codesegment.CodeSegment;
 import alice.datasegment.CommandType;
 import alice.datasegment.Receiver;
+import alice.jungle.datasegment.HashSetDataSegment;
 import alice.jungle.datasegment.store.operations.DefaultTreeOperationLogContainer;
 import alice.jungle.transaction.NetworkDefaultJungleTreeEditor;
 
 public class LogUpdateCodeSegment extends CodeSegment {
 	
-	public Receiver arg1 = ids.create(CommandType.PEEK);
-	public Receiver host = ids.create(CommandType.PEEK);
+	Receiver parentLog = ids.create(CommandType.PEEK);
+	Receiver host = ids.create(CommandType.PEEK);
+	Receiver hashLog = ids.create(CommandType.PEEK);
 	
 	public LogUpdateCodeSegment() {
-		arg1.setKey("parent", "log");
+		parentLog.setKey("parent", "log");
 		host.setKey("host");
+		hashLog.setKey("hashLog");
 	}
 	
 	public LogUpdateCodeSegment(int index) {
-		arg1.setKey("parent", "log", index);
+		parentLog.setKey("parent", "log", index);
 		host.setKey("host");
+		hashLog.setKey("hashLog");		
 	}
 	
 	public void run() {
 		System.out.println("--LogUpdateCodeSegment--");
-		int index = arg1.index;
+		int index = parentLog.index;
 		String h = host.asString();
-		DefaultTreeOperationLogContainer container = arg1.asClass(DefaultTreeOperationLogContainer.class);
-		if(updaterIsMe(h, container)) {
+		DefaultTreeOperationLogContainer container = parentLog.asClass(DefaultTreeOperationLogContainer.class);
+		HashSetDataSegment ds = hashLog.asClass(HashSetDataSegment.class);
+		System.out.println(container.getHashLogString());
+		if(ds.hash.contains(container.getHashLogString())) {
+			ods.update("hashLog", ds);		
 			new LogUpdateCodeSegment(index);
 			return;
 		}
@@ -61,6 +68,9 @@
 		if(either.isA()) {
 			throw new IllegalStateException();			
 		}
+		ds.hash.add(container.getHashLogString());
+		ods.update("hashLog", ds);		
+		System.out.println("ods.put log container");
 		ods.put("log", container);
 		new LogUpdateCodeSegment(index);
 	}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/alice/jungle/datasegment/HashSetDataSegment.java	Sat Jul 13 17:10:14 2013 +0900
@@ -0,0 +1,11 @@
+package alice.jungle.datasegment;
+
+import java.util.HashSet;
+
+import org.msgpack.annotation.Message;
+
+@Message
+public class HashSetDataSegment {
+	public HashSet<String> hash = new HashSet<String>();			
+	public HashSetDataSegment() {}
+}
--- a/src/alice/jungle/datasegment/store/operations/DefaultTreeOperationLogContainer.java	Sat Jul 13 15:59:47 2013 +0900
+++ b/src/alice/jungle/datasegment/store/operations/DefaultTreeOperationLogContainer.java	Sat Jul 13 17:10:14 2013 +0900
@@ -25,10 +25,10 @@
 public class DefaultTreeOperationLogContainer {
 
 	Value logValue;
-	String treeName;
-	String uuid;
-	String updaterName;
-	long revision;
+	String treeName = "";
+	String uuid = "";
+	String updaterName = "";
+	String revision = "";
 	
 	public static void main(String[] args) throws IOException {
 		String key = "hoge";
@@ -120,11 +120,11 @@
 		return updaterName;
 	}
 	
-	public void setRevision(long _revision) {
+	public void setRevision(String _revision) {
 		revision = _revision;
 	}
 	
-	public long getRevision() {
+	public String getRevision() {
 		return revision;
 	}
 	
@@ -157,6 +157,9 @@
 		return log;
 	}
 	
-	
+	public String getHashLogString() {
+		return updaterName + revision;
+	}
+
 	
 }
--- a/src/jungle/test/bbs/NetworkJungleBulletinBoard.java	Sat Jul 13 15:59:47 2013 +0900
+++ b/src/jungle/test/bbs/NetworkJungleBulletinBoard.java	Sat Jul 13 17:10:14 2013 +0900
@@ -4,6 +4,7 @@
 import java.nio.ByteBuffer;
 import java.util.concurrent.atomic.AtomicInteger;
 
+import alice.jungle.codesegment.HashLogUpdateCodeSegment;
 import alice.jungle.core.NetworkDefaultJungle;
 import alice.jungle.datasegment.store.operations.DefaultTreeOperationLogContainer;
 import alice.jungle.transaction.NetworkDefaultJungleTreeEditor;
@@ -216,12 +217,12 @@
 		String uuid = editor.getID();
 		String treeName = editor.getTreeName();
 		String updaterName = editor.getUpdaterName();
-		long revision = Long.parseLong(editor.getRevision());
+		String revision = editor.getRevision();
 		Iterable<TreeOperation> log = editor.getTreeOperationLog();
 		putDataSegment(uuid, treeName, updaterName, log, revision);
 	}
 	
-	private void putDataSegment(String _uuid, String _treeName, String _updaterName, Iterable<TreeOperation> _log, long nextRevision) throws IOException {
+	private void putDataSegment(String _uuid, String _treeName, String _updaterName, Iterable<TreeOperation> _log, String nextRevision) throws IOException {
 		DefaultTreeOperationLogContainer container = new DefaultTreeOperationLogContainer();
 		container.setTreeName(_treeName);
 		container.setUUID(_uuid);
@@ -230,7 +231,10 @@
 		container.unconvert(_log);
 		NullCodeSegmentForUpdate cs = new NullCodeSegmentForUpdate();
 		cs.ods.put("log", container);
-		/* If this node isn't Root node, push log to parent node's DS */
+		new HashLogUpdateCodeSegment(container.getHashLogString());
+		System.out.println("putDataSegment");
+		System.out.println(container.getHashLogString());
+		/* If this node is not Root node, push log to parent node's DS */
 		if(!_updaterName.equals("node0")) {
 			cs.ods.put("parent", "childLog", container);
 		}
--- a/src/jungle/test/bbs/codesegment/ChildLogCheckCodeSegment.java	Sat Jul 13 15:59:47 2013 +0900
+++ b/src/jungle/test/bbs/codesegment/ChildLogCheckCodeSegment.java	Sat Jul 13 17:10:14 2013 +0900
@@ -11,16 +11,20 @@
 import alice.codesegment.CodeSegment;
 import alice.datasegment.CommandType;
 import alice.datasegment.Receiver;
+import alice.jungle.codesegment.HashLogUpdateCodeSegment;
+import alice.jungle.datasegment.HashSetDataSegment;
 import alice.jungle.datasegment.store.operations.DefaultTreeOperationLogContainer;
 
 public class ChildLogCheckCodeSegment extends CodeSegment {
 	
+	Receiver host = ids.create(CommandType.PEEK);
 	Receiver childLog = ids.create(CommandType.TAKE);
-	Receiver host = ids.create(CommandType.PEEK);
+	Receiver hashLog = ids.create(CommandType.PEEK);	
 	
 	public ChildLogCheckCodeSegment() {
 		host.setKey("host");
 		childLog.setKey("local","childLog");
+		hashLog.setKey("hashLog");
 	}
 	
 	public void run() {
@@ -49,11 +53,14 @@
 		either = editor.success();
 		if(either.isA()) {
 			throw new IllegalStateException();			
-		}		
+		}
+		HashSetDataSegment ds = hashLog.asClass(HashSetDataSegment.class);
+		ds.hash.add(container.getHashLogString());
+		ods.update("hashLog", ds);
+		System.out.println("ods.put log container");
 		ods.put("log", container);
 		new ChildLogCheckCodeSegment();
 		if(!hostName.equals("node0")) {
-			
 			ods.put("parent", "childLog", container);
 		}
 	}
--- a/src/jungle/test/bbs/codesegment/StartBBSCodeSegment.java	Sat Jul 13 15:59:47 2013 +0900
+++ b/src/jungle/test/bbs/codesegment/StartBBSCodeSegment.java	Sat Jul 13 17:10:14 2013 +0900
@@ -22,6 +22,7 @@
 import alice.datasegment.CommandType;
 import alice.datasegment.Receiver;
 import alice.jungle.codesegment.LogUpdateCodeSegment;
+import alice.jungle.datasegment.HashSetDataSegment;
 
 public class StartBBSCodeSegment extends CodeSegment {
 	
@@ -45,7 +46,8 @@
 		Matcher matcher = pattern.matcher(name);
 		matcher.find();
 		String type = matcher.group(1);
-
+		
+		
 		BulletinBoard cassaBBS = new NetworkJungleBulletinBoard(name);
     	String createBoardMessagePath = "/createBoardMessage";
     	String createBoardPath = "/createBoard";
@@ -73,6 +75,9 @@
 		}
     	
     	new ChildLogCheckCodeSegment();
+		HashSetDataSegment hashLog = new HashSetDataSegment();
+		ods.put("hashLog", hashLog);
+
 		int num = new Integer(matcher.group(2));
 		if (num != 0) {
 //			try {Thread.sleep(100);} catch(Exception e)  { e.printStackTrace(); }