# HG changeset patch # User one # Date 1370896383 -32400 # Node ID b7396f848d7838773b88282b2cc56135b8bc9c7a # Parent 02bdf23edf5a9c6e4bfc4fe785e87c7f8c113f94 add DefaultTreeOperationLogContainer.java diff -r 02bdf23edf5a -r b7396f848d78 src/jungle/test/datasegment/store/operations/DefaultTreeOperationLogContainer.java --- /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 list = new LinkedList(); + 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 listValue = msgpack.convert(logValue, List.class); + List logList = new LinkedList(); + for(Value v: listValue) { + DefaultTreeOperationContainer container = msgpack.convert(v, DefaultTreeOperationContainer.class); + logList.add(container.convert()); + } + DefaultTreeOperationLog log = new DefaultTreeOperationLog(logList, logList.size()); + return log; + } + + + +}