# HG changeset patch # User one # Date 1370927382 -32400 # Node ID 49c0eaa4dce24e7fee32357b12c2e6cb3dd476d8 # Parent ee93e16d5a3faadd2ad49752a5dd7075709cde51 add StartCodeSegment.java diff -r ee93e16d5a3f -r 49c0eaa4dce2 src/jungle/test/codesegment/practice/StartCodeSegment.java --- a/src/jungle/test/codesegment/practice/StartCodeSegment.java Tue Jun 11 05:41:07 2013 +0900 +++ b/src/jungle/test/codesegment/practice/StartCodeSegment.java Tue Jun 11 14:09:42 2013 +0900 @@ -1,5 +1,19 @@ package jungle.test.codesegment.practice; +import java.io.IOException; +import java.nio.ByteBuffer; +import java.util.LinkedList; +import java.util.List; + +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.DefaultNodePath; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.logger.DefaultTreeOperationLog; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.AppendChildAtOperation; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.DefaultTreeOperation; +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.PutAttributeOperation; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.TreeOperation; +import jungle.test.datasegment.store.operations.DefaultTreeOperationLogContainer; import alice.codesegment.CodeSegment; public class StartCodeSegment extends CodeSegment { @@ -9,12 +23,33 @@ 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 + cs.arg1.setKey("log"); System.out.println("create TestCodeSegment"); + + String key = "hoge"; + ByteBuffer b = ByteBuffer.wrap("messagepack value".getBytes()); + DefaultNodePath nodePath1 = new DefaultNodePath(); + nodePath1 = nodePath1.add(1); + DefaultNodePath nodePath2 = nodePath1.add(2); + AppendChildAtOperation appendChildOp = new AppendChildAtOperation(1); + PutAttributeOperation putOp = new PutAttributeOperation(key, b); + DeleteAttributeOperation deleteOp = new DeleteAttributeOperation("hoge"); + DeleteChildAtOperation deleteChild = new DeleteChildAtOperation(2); + List list = new LinkedList(); + list.add(new DefaultTreeOperation(nodePath1, appendChildOp)); + list.add(new DefaultTreeOperation(nodePath2, appendChildOp)); + list.add(new DefaultTreeOperation(nodePath2, putOp)); + list.add(new DefaultTreeOperation(nodePath2, deleteOp)); + list.add(new DefaultTreeOperation(nodePath1, deleteChild)); + DefaultTreeOperationLog log = new DefaultTreeOperationLog(list, list.size()); - ods.update("local", "key1", "String data"); // bind string data to datasegment local.key1 - // this startup TestCodeSegment. + DefaultTreeOperationLogContainer logContainer = new DefaultTreeOperationLogContainer(); + try { + logContainer.unconvert(log); + ods.update("local", "log", logContainer); + } catch (IOException e) { + e.printStackTrace(); + } } } diff -r ee93e16d5a3f -r 49c0eaa4dce2 src/jungle/test/codesegment/practice/TestCodeSegment.java --- a/src/jungle/test/codesegment/practice/TestCodeSegment.java Tue Jun 11 05:41:07 2013 +0900 +++ b/src/jungle/test/codesegment/practice/TestCodeSegment.java Tue Jun 11 14:09:42 2013 +0900 @@ -1,8 +1,19 @@ package jungle.test.codesegment.practice; +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.NodePath; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.logger.TreeOperationLog; +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.datasegment.store.operations.DefaultTreeOperationLogContainer; import alice.codesegment.CodeSegment; import alice.datasegment.CommandType; import alice.datasegment.Receiver; + +import org.msgpack.MessagePack; import org.msgpack.type.Value; public class TestCodeSegment extends CodeSegment { @@ -17,16 +28,60 @@ System.out.println("data = " + arg1.getVal()); System.out.println(((Value)arg1.getVal()).getType()); - if (arg1.index == 10) { - System.exit(0); - return; + MessagePack msgpack = new MessagePack(); + Value logContainerValue = (Value) arg1.getVal(); + DefaultTreeOperationLogContainer convertedLogContainer; + TreeOperationLog convertedLog = null; + try { + convertedLogContainer = msgpack.convert(logContainerValue, DefaultTreeOperationLogContainer.class); + convertedLog = convertedLogContainer.convert(); + } catch (IOException e) { + e.printStackTrace(); } - + + for (TreeOperation treeOp : convertedLog) { + NodePath path = treeOp.getNodePath(); + NodeOperation nodeOp = treeOp.getNodeOperation(); + Command c = nodeOp.getCommand(); + String str = ""; + switch (c) { + case PUT_ATTRIBUTE: + String k = nodeOp.getKey(); + ByteBuffer value = nodeOp.getValue(); + if (value.limit() < 100) { + str = String.format("key:%s,value:%s", k, + new String(value.array())); + } else { + str = String.format("key:%s,value:%d", k, value.limit()); + } + break; + case DELETE_ATTRIBUTE: + str = String.format("key:%s", nodeOp.getKey()); + break; + case APPEND_CHILD: + str = String.format("pos:%d", nodeOp.getPosition()); + break; + case DELETE_CHILD: + str = String.format("pos:%d", nodeOp.getPosition()); + break; + } + System.out.println(String.format("[%s:%s]", c, str)); + System.out.println("path:"); + for (int i: path ) { + System.out.println(i); + } + + } + + System.exit(0); + +/* TestCodeSegment cs = new TestCodeSegment(); cs.arg1.setKey("key1", arg1.index); // DataSegment.get("local").update ods.update("local", "key1", "String data"); +*/ } } diff -r ee93e16d5a3f -r 49c0eaa4dce2 src/jungle/test/datasegment/store/operations/DefaultTreeOperationLogContainer.java --- a/src/jungle/test/datasegment/store/operations/DefaultTreeOperationLogContainer.java Tue Jun 11 05:41:07 2013 +0900 +++ b/src/jungle/test/datasegment/store/operations/DefaultTreeOperationLogContainer.java Tue Jun 11 14:09:42 2013 +0900 @@ -41,8 +41,13 @@ DefaultTreeOperationLogContainer logContainer = new DefaultTreeOperationLogContainer(); logContainer.unconvert(log); + + MessagePack msgpack = new MessagePack(); + Value logContainerValue = msgpack.unconvert(logContainer); + DefaultTreeOperationLogContainer convertedLogContainer = msgpack.convert(logContainerValue, + DefaultTreeOperationLogContainer.class); - TreeOperationLog convertedLog = logContainer.convert(); + TreeOperationLog convertedLog = convertedLogContainer.convert(); for (TreeOperation treeOp : convertedLog) { NodePath path = treeOp.getNodePath(); NodeOperation nodeOp = treeOp.getNodeOperation(); @@ -69,8 +74,8 @@ str = String.format("pos:%d", nodeOp.getPosition()); break; } - System.out.println(String.format("[%s:%s:%s]", c, nodePath, str)); - for (int i: nodePath ) { + System.out.println(String.format("[%s:%s:%s]", c, path, str)); + for (int i: path ) { System.out.println(i); }