Mercurial > hg > Members > nobuyasu > jungle-network
diff src/main/java/alice/jungle/datasegment/container/DefaultTreeOperationLogContainer.java @ 105:f9e29a52efd3
Move some files
author | one |
---|---|
date | Tue, 26 Nov 2013 06:43:10 +0900 |
parents | src/alice/jungle/datasegment/store/container/DefaultTreeOperationLogContainer.java@2c7b3f2b2ee1 |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/alice/jungle/datasegment/container/DefaultTreeOperationLogContainer.java Tue Nov 26 06:43:10 2013 +0900 @@ -0,0 +1,114 @@ +package alice.jungle.datasegment.container; + +import java.io.IOException; +import java.util.LinkedList; +import java.util.List; + +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.NodePath; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.logger.DefaultTreeOperationLog; +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.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; + +import alice.codesegment.SingletonMessage; + +@Message +public class DefaultTreeOperationLogContainer { + + Value logValue; + String treeName; + String uuid; + String updaterName; + String revision; + long timestamp; + + public DefaultTreeOperationLogContainer() { + logValue = null; + treeName = ""; + uuid = ""; + updaterName = ""; + revision = ""; + timestamp = Long.MAX_VALUE; + } + + public void setTreeName(String _treeName) { + treeName = _treeName; + } + + public String getTreeName() { + return treeName; + } + + public void setUUID(String _uuid) { + uuid = _uuid; + } + + public String getUUID() { + return uuid; + } + + public void setUpdaterName(String _updaterName) { + updaterName = _updaterName; + } + + public String getServerName() { + return updaterName; + } + + public void setRevision(String _revision) { + revision = _revision; + } + + public String getRevision() { + return revision; + } + + public void setTimeStamp(long t) { + timestamp = t; + } + + public long getTimeStamp() { + return timestamp; + } + + public void unconvert(Iterable<TreeOperation> _log) throws IOException { + MessagePack msgpack = SingletonMessage.getInstance(); + List<Value> list = new LinkedList<Value>(); + for(TreeOperation op : _log) { + NodeOperation nOp = op.getNodeOperation(); + NodePath nodePath = op.getNodePath(); + DefaultTreeOperation treeOp = new DefaultTreeOperation(nodePath, nOp); + DefaultTreeOperationContainer container = new DefaultTreeOperationContainer(); + container.unconvert(treeOp); + Value v = msgpack.unconvert(container); + list.add(v); + } + Value listValue = msgpack.unconvert(list); + logValue = listValue; + } + + public DefaultTreeOperationLog convert() throws IOException { + MessagePack msgpack = SingletonMessage.getInstance(); + 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; + } + + public String getHashLogString() { + return treeName + revision + updaterName; + } + + +}