changeset 50:459b50f1a6ee

add ChildLogCheckCodeSegment.
author one
date Fri, 12 Jul 2013 20:39:02 +0900
parents a89c3539bff2
children 9e782b4eb06e
files src/alice/jungle/codesegment/LogUpdateCodeSegment.java src/jungle/test/bbs/NetworkJungleBulletinBoard.java src/jungle/test/bbs/codesegment/ChildLogCheckCodeSegment.java src/jungle/test/bbs/codesegment/StartBBSCodeSegment.java
diffstat 4 files changed, 61 insertions(+), 27 deletions(-) [+]
line wrap: on
line diff
--- a/src/alice/jungle/codesegment/LogUpdateCodeSegment.java	Fri Jul 12 19:56:12 2013 +0900
+++ b/src/alice/jungle/codesegment/LogUpdateCodeSegment.java	Fri Jul 12 20:39:02 2013 +0900
@@ -18,15 +18,15 @@
 	
 	public Receiver arg1 = ids.create(CommandType.PEEK);
 	public Receiver host = ids.create(CommandType.PEEK);
-	public String location = "local";
 	
 	public LogUpdateCodeSegment() {
-		host.setKey("host",0);
+		arg1.setKey("parent", "log");
+		host.setKey("host");
 	}
 	
-	public LogUpdateCodeSegment(String _location) {
-		location = _location;
-		host.setKey("local","host",0);
+	public LogUpdateCodeSegment(int index) {
+		arg1.setKey("parent", "log", index);
+		host.setKey("host");
 	}
 	
 	public void run() {
@@ -34,11 +34,7 @@
 		String h = host.asString();
 		DefaultTreeOperationLogContainer container = arg1.asClass(DefaultTreeOperationLogContainer.class);
 		if(updaterIsMe(h, container)) {
-			LogUpdateCodeSegment updateCS = new LogUpdateCodeSegment();
-			updateCS.arg1.setKey(location, "log", index+1);
-			if(location.equals("local") && !iAmRootNode(h)) {
-				ods.put("parent", "log", container);
-			}
+			new LogUpdateCodeSegment(index+1);
 			return;
 		}
 		DefaultTreeOperationLog log = null;
@@ -58,24 +54,11 @@
 		if(either.isA()) {
 			throw new IllegalStateException();			
 		}
-		if(location.equals("local")) {
-			NetworkDefaultJungleTreeEditor nEditor = (NetworkDefaultJungleTreeEditor) editor;
-			container.setRevision(Long.parseLong(nEditor.getRevision()));
-			container.setUpdaterName(nEditor.getUpdaterName());
-		}
 		ods.put("log", container);
-		LogUpdateCodeSegment updateCS = new LogUpdateCodeSegment();
-		updateCS.arg1.setKey(location, "log", index+1);
+		new LogUpdateCodeSegment(index+1);
 	}
 	
 	private boolean updaterIsMe(String host, DefaultTreeOperationLogContainer container) {
 		return host.equals(container.getServerName());
 	}
-	
-	private boolean iAmRootNode(String h) {
-		return h.equals("node0");
-	}
-	
-	
-	
 }
--- a/src/jungle/test/bbs/NetworkJungleBulletinBoard.java	Fri Jul 12 19:56:12 2013 +0900
+++ b/src/jungle/test/bbs/NetworkJungleBulletinBoard.java	Fri Jul 12 20:39:02 2013 +0900
@@ -236,6 +236,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 */
+		if(!_updaterName.equals("node0")) {
+			cs.ods.put("parent", "childLog");
+		}
 	}
 
 	
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/jungle/test/bbs/codesegment/ChildLogCheckCodeSegment.java	Fri Jul 12 20:39:02 2013 +0900
@@ -0,0 +1,48 @@
+package jungle.test.bbs.codesegment;
+
+import java.io.IOException;
+
+import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.JungleTree;
+import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.JungleTreeEditor;
+import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.logger.DefaultTreeOperationLog;
+import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Either;
+import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Error;
+import jungle.test.bbs.JungleManager;
+import alice.codesegment.CodeSegment;
+import alice.datasegment.CommandType;
+import alice.datasegment.Receiver;
+import alice.jungle.datasegment.store.operations.DefaultTreeOperationLogContainer;
+
+public class ChildLogCheckCodeSegment extends CodeSegment {
+	
+	Receiver childLog = ids.create(CommandType.TAKE);
+	
+	public ChildLogCheckCodeSegment() {
+		childLog.setKey("childLog");
+	}
+	
+	public void run() {
+		DefaultTreeOperationLogContainer container = childLog.asClass(DefaultTreeOperationLogContainer.class);		
+		DefaultTreeOperationLog log = null;
+		try {
+			log = container.convert();
+		} catch (IOException e) {
+			e.printStackTrace();
+		}
+		JungleTree tree = JungleManager.getJungle().getTreeByName("boards");
+		JungleTreeEditor editor = tree.getTreeEditor();
+		Either<Error, JungleTreeEditor> either = JungleManager.edit(editor, log);
+		if(either.isA()) {
+			throw new IllegalStateException();
+		}
+		editor = either.b();
+		either = editor.success();
+		if(either.isA()) {
+			throw new IllegalStateException();			
+		}		
+		ods.put("log", container);
+		new ChildLogCheckCodeSegment();
+	}
+	
+
+}
--- a/src/jungle/test/bbs/codesegment/StartBBSCodeSegment.java	Fri Jul 12 19:56:12 2013 +0900
+++ b/src/jungle/test/bbs/codesegment/StartBBSCodeSegment.java	Fri Jul 12 20:39:02 2013 +0900
@@ -72,12 +72,11 @@
 			e.printStackTrace();
 		}
     	
-		LogUpdateCodeSegment cs = new LogUpdateCodeSegment();
-
+    	new ChildLogCheckCodeSegment();
 		int num = new Integer(matcher.group(2));
 		if (num != 0) {
 //			try {Thread.sleep(100);} catch(Exception e)  { e.printStackTrace(); }
-			LogUpdateCodeSegment cs2 = new LogUpdateCodeSegment("parent");
+			new LogUpdateCodeSegment();
 		}