changeset 2:20498c88a70d

add Container
author one
date Sun, 09 Jun 2013 13:53:16 +0900
parents 8ee02d1a2b12
children 3770d2be3e73
files src/jungle/test/codesegment/practice/StartCodeSegment.java src/jungle/test/codesegment/practice/TestCodeSegment.java src/jungle/test/codesegment/practice/TestLocalAlice.java src/jungle/test/datasegment/store/operations/DefaultNodeOperationContainer.java src/jungle/test/datasegment/store/operations/DefaultNodePathContainer.java src/jungle/test/operations/NetworkTreeOperation.java src/jungle/test/operations/NetworkTreeOperationLog.java src/jungle/test/operations/messagepack/PackOperationLog.java
diffstat 8 files changed, 195 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/jungle/test/codesegment/practice/StartCodeSegment.java	Sun Jun 09 13:53:16 2013 +0900
@@ -0,0 +1,20 @@
+package jungle.test.codesegment.practice;
+
+import alice.codesegment.CodeSegment;
+
+public class StartCodeSegment extends CodeSegment {
+
+	@Override
+	public void run() {
+		System.out.println("run StartCodeSegment");
+		
+		TestCodeSegment cs = new TestCodeSegment();
+		cs.arg1.setKey("key1"); // unbound datasegment key1 is created and connect to cs.
+								// cs is waiting for local.key1
+		System.out.println("create TestCodeSegment");
+		
+		ods.update("local", "key1", "String data"); // bind string data to datasegment local.key1
+													// this startup TestCodeSegment.
+ 	}
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/jungle/test/codesegment/practice/TestCodeSegment.java	Sun Jun 09 13:53:16 2013 +0900
@@ -0,0 +1,32 @@
+package jungle.test.codesegment.practice;
+
+import alice.codesegment.CodeSegment;
+import alice.datasegment.CommandType;
+import alice.datasegment.Receiver;
+import org.msgpack.type.Value;
+
+public class TestCodeSegment extends CodeSegment {
+	
+	// create input datasegment arg1
+	Receiver arg1 = ids.create(CommandType.PEEK);
+	
+	@Override
+	public void run() {
+		System.out.println("type = " + arg1.type);
+		System.out.println("index = " + arg1.index);
+		System.out.println("data = " + arg1.getVal());
+		System.out.println(((Value)arg1.getVal()).getType());
+		
+		if (arg1.index == 10) {
+			System.exit(0);
+			return;
+		}
+ 		
+		TestCodeSegment cs = new TestCodeSegment();
+		cs.arg1.setKey("key1", arg1.index);
+		
+		// DataSegment.get("local").update
+		ods.update("local", "key1", "String data");
+	}
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/jungle/test/codesegment/practice/TestLocalAlice.java	Sun Jun 09 13:53:16 2013 +0900
@@ -0,0 +1,12 @@
+package jungle.test.codesegment.practice;
+
+import alice.daemon.AliceDaemon;
+import alice.daemon.Config;
+
+public class TestLocalAlice {
+	public static void main(String args[]) {
+		new AliceDaemon(new Config(args)).listen(); // logger off
+		new StartCodeSegment().execute();
+	}
+	
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/jungle/test/datasegment/store/operations/DefaultNodeOperationContainer.java	Sun Jun 09 13:53:16 2013 +0900
@@ -0,0 +1,68 @@
+package jungle.test.datasegment.store.operations;
+
+import java.io.IOException;
+import java.nio.ByteBuffer;
+
+import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.Command;
+import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.AppendChildAtOperation;
+import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.DeleteAttributeOperation;
+import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.DeleteChildAtOperation;
+import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.NodeOperation;
+import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.PutAttributeOperation;
+
+import org.msgpack.MessagePack;
+import org.msgpack.annotation.Message;
+import org.msgpack.template.OrdinalEnumTemplate;
+import org.msgpack.template.Template;
+import org.msgpack.type.Value;
+
+@Message
+public class DefaultNodeOperationContainer {
+
+	public int pos;
+	public String key;
+	public Value value;
+	public Value commandValue;
+	
+	
+	public DefaultNodeOperationContainer() {
+		
+	}
+
+	public void unconvert(NodeOperation op) throws IOException {
+		MessagePack msgpack = new MessagePack();
+		pos = op.getPosition();
+		key = op.getKey();
+		value = null;
+		if (op.getValue() != null) {
+			ByteBuffer b = op.getValue();
+			Value v = msgpack.unconvert(b);
+			value = v;
+		}
+		Command c = op.getCommand();
+		msgpack.register(c.getClass(), new OrdinalEnumTemplate(c.getClass()));
+		Value cValue = msgpack.unconvert(c);
+		commandValue = cValue;
+	}
+	
+	public NodeOperation convert() throws IOException{
+		MessagePack msgpack = new MessagePack();
+		Command c = msgpack.convert(commandValue, Command.class);
+		ByteBuffer b = null;
+		if (value != null) {
+			b = msgpack.convert(value, ByteBuffer.class);
+		}
+		if (c == Command.PUT_ATTRIBUTE) {
+			return new PutAttributeOperation(key, b);
+		} else if (c == Command.APPEND_CHILD) {
+			return new AppendChildAtOperation(pos);
+		} else if (c == Command.DELETE_CHILD) {
+			return new DeleteChildAtOperation(pos);
+		} else if (c == Command.DELETE_ATTRIBUTE){
+			return new DeleteAttributeOperation(key);
+		}
+		return null;
+	}
+	
+	
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/jungle/test/datasegment/store/operations/DefaultNodePathContainer.java	Sun Jun 09 13:53:16 2013 +0900
@@ -0,0 +1,38 @@
+package jungle.test.datasegment.store.operations;
+
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.List;
+
+import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.DefaultNodePath;
+
+import org.msgpack.MessagePack;
+import org.msgpack.annotation.Message;
+import org.msgpack.type.Value;
+
+@Message
+public class DefaultNodePathContainer {
+
+	public Value pathValue;
+	
+	public DefaultNodePathContainer() {
+		
+	}
+	
+	public void unconvert(DefaultNodePath path) throws IOException {
+		MessagePack msgpack = new MessagePack();
+		List<Integer> list = Arrays.asList();
+		for(Integer i : path) {
+			list.add(i);
+		}
+		Value v = msgpack.unconvert(list);
+		pathValue = v;
+	}
+	
+	public DefaultNodePath convert() throws IOException {
+		MessagePack msgpack = new MessagePack();
+		return msgpack.convert(pathValue, DefaultNodePath.class);
+	}
+	
+	
+}
--- a/src/jungle/test/operations/NetworkTreeOperation.java	Fri Jun 07 19:26:08 2013 +0900
+++ b/src/jungle/test/operations/NetworkTreeOperation.java	Sun Jun 09 13:53:16 2013 +0900
@@ -9,8 +9,8 @@
 @Message
 public class NetworkTreeOperation implements TreeOperation {
 
-	private NodePath path;
-	private NodeOperation operation;
+	public NodePath path;
+	public NodeOperation operation;
 	
 	public NetworkTreeOperation() {
 		path = null;
--- a/src/jungle/test/operations/NetworkTreeOperationLog.java	Fri Jun 07 19:26:08 2013 +0900
+++ b/src/jungle/test/operations/NetworkTreeOperationLog.java	Sun Jun 09 13:53:16 2013 +0900
@@ -13,8 +13,8 @@
 @Message
 public class NetworkTreeOperationLog implements TreeOperationLog
 {
-	private Iterable<TreeOperation> list;
-	private int size;
+	public Iterable<TreeOperation> list;
+	public int size;
 	
 	public NetworkTreeOperationLog() {
 		list = new LinkedList<TreeOperation>();
@@ -41,21 +41,26 @@
 	{
 		TreeOperation op = new NetworkTreeOperation(_p, _op);
 		LinkedList<TreeOperation> newList = new LinkedList<TreeOperation>();
-		for(TreeOperation o : this) {
+		for (Iterator<TreeOperation> iter = list.iterator(); iter.hasNext();) {
+			TreeOperation o = iter.next();
 			newList.add(o);
 		}
 		newList.add(op);
-		return new NetworkTreeOperationLog(newList, size+1); 
+		return new NetworkTreeOperationLog(newList, size+1);
 	}
 
 	@Override
 	public NetworkTreeOperationLog append(TreeOperationLog _log) 
 	{
-		LinkedList<TreeOperation> l = new LinkedList<TreeOperation>();
-		for (TreeOperation t : _log) {
-			l.add(t);
+		LinkedList<TreeOperation> newList = new LinkedList<TreeOperation>();
+		for (Iterator<TreeOperation> iter = list.iterator(); iter.hasNext();) {
+			TreeOperation o = iter.next();
+			newList.add(o);
 		}
-		return new NetworkTreeOperationLog(l, size+_log.length());
+		for (TreeOperation o : _log) {
+			newList.add(o);
+		}
+		return new NetworkTreeOperationLog(newList, size+_log.length());
 	}
 
 	@Override
--- a/src/jungle/test/operations/messagepack/PackOperationLog.java	Fri Jun 07 19:26:08 2013 +0900
+++ b/src/jungle/test/operations/messagepack/PackOperationLog.java	Sun Jun 09 13:53:16 2013 +0900
@@ -8,6 +8,7 @@
 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.NodePath;
 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.NodeOperation;
 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.TreeOperation;
+import jungle.test.operations.NetworkNodeOperation;
 import jungle.test.operations.NetworkNodePath;
 import jungle.test.operations.NetworkTreeOperationLog;
 
@@ -18,17 +19,19 @@
 
 	public static void main(String[] args) throws IOException {
 		MessagePack msgpack = new MessagePack();
-		NetworkTreeOperationLog n = new NetworkTreeOperationLog();
+		final NetworkTreeOperationLog n = new NetworkTreeOperationLog();
 		NetworkNodePath p = new NetworkNodePath();
 		p = p.add(1).add(2).add(3);
 		System.out.println(p.toString());
-		n = n.add(null, null);
+		NetworkTreeOperationLog n2 = n.add(p, new NetworkNodeOperation());
 		System.out.println("n.length() = "+n.length());
 
-		Value v = msgpack.unconvert(n);
+		NetworkTreeOperationLog n3 = n2.append(new NetworkTreeOperationLog());
+		
+		Value v = msgpack.unconvert(n2);
 		final NetworkTreeOperationLog log = msgpack.convert(v, NetworkTreeOperationLog.class);
+
 		System.out.println("nn.lenght() = " + log.length());
-		
 		ChangeList list = new ChangeList(){
 			@Override
 			public Iterator<TreeOperation> iterator(){
@@ -40,10 +43,10 @@
 			NodeOperation nodeOp = op.getNodeOperation();
 			Command c = nodeOp.getCommand();
 			System.out.println(nPath.toString());
-			
 		}
-		
-		
 	}
 	
+	
+	
+	
 }