changeset 7:b7396f848d78

add DefaultTreeOperationLogContainer.java
author one
date Tue, 11 Jun 2013 05:33:03 +0900
parents 02bdf23edf5a
children ee93e16d5a3f
files src/jungle/test/datasegment/store/operations/DefaultTreeOperationLogContainer.java
diffstat 1 files changed, 82 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/jungle/test/datasegment/store/operations/DefaultTreeOperationLogContainer.java	Tue Jun 11 05:33:03 2013 +0900
@@ -0,0 +1,82 @@
+package jungle.test.datasegment.store.operations;
+
+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.Command;
+import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.NodePath;
+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.impl.logger.TreeOperationLog;
+import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.DefaultTreeOperation;
+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 jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.TreeOperation;
+
+import org.msgpack.MessagePack;
+import org.msgpack.annotation.Message;
+import org.msgpack.template.ListTemplate;
+import org.msgpack.template.ValueTemplate;
+import org.msgpack.type.Value;
+
+@Message
+public class DefaultTreeOperationLogContainer {
+
+	Value logValue;
+	
+	public static void main(String[] args) throws IOException {
+		String key = "hoge";
+		ByteBuffer b = ByteBuffer.wrap("messagepack value".getBytes());
+		PutAttributeOperation putOp = new PutAttributeOperation(key, b);
+		DefaultNodePath nodePath = new DefaultNodePath();
+		nodePath = nodePath.add(1).add(2).add(3);
+
+		TreeOperation op = new DefaultTreeOperation(nodePath, putOp);
+		
+		
+		
+	}
+	
+	public DefaultTreeOperationLogContainer() {
+		
+	}
+	
+	public void unconvert(DefaultTreeOperationLog _log) throws IOException {
+		MessagePack msgpack = new MessagePack();
+		List<Value> list = new LinkedList<Value>();
+		for(TreeOperation op : _log) {
+			NodeOperation nOp = op.getNodeOperation();
+			NodePath nodePath = op.getNodePath();
+			DefaultNodeOperationContainer nodeOpContainer = new DefaultNodeOperationContainer();
+			nodeOpContainer.unconvert(nOp);
+			DefaultNodePathContainer nodePathContainer = new DefaultNodePathContainer();
+			nodePathContainer.unconvert(nodePath);
+			DefaultTreeOperationContainer container = new DefaultTreeOperationContainer();
+			container.unconvert(nodeOpContainer, nodePathContainer);
+			Value v = msgpack.unconvert(container);
+			list.add(v);
+		}
+		/* */
+		msgpack.register(List.class, new ListTemplate(ValueTemplate.getInstance()));
+		Value listValue = msgpack.unconvert(list);
+		logValue = listValue;
+	}
+	
+	public DefaultTreeOperationLog convert() throws IOException {
+		MessagePack msgpack = new MessagePack();
+		msgpack.register(List.class, new ListTemplate(ValueTemplate.getInstance()));
+		List<Value> listValue = msgpack.convert(logValue, List.class);
+		List<TreeOperation> logList = new LinkedList<TreeOperation>();
+		for(Value v: listValue) {
+			DefaultTreeOperationContainer container = msgpack.convert(v, DefaultTreeOperationContainer.class);
+			logList.add(container.convert());
+		}
+		DefaultTreeOperationLog log = new DefaultTreeOperationLog(logList, logList.size());
+		return log;
+	}
+	
+	
+	
+}