7
|
1 package jungle.test.datasegment.store.operations;
|
|
2
|
|
3 import java.io.IOException;
|
|
4 import java.nio.ByteBuffer;
|
|
5 import java.util.LinkedList;
|
|
6 import java.util.List;
|
|
7
|
|
8 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.Command;
|
|
9 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.NodePath;
|
|
10 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.DefaultNodePath;
|
|
11 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.logger.DefaultTreeOperationLog;
|
|
12 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.logger.TreeOperationLog;
|
|
13 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.DefaultTreeOperation;
|
|
14 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.NodeOperation;
|
|
15 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.PutAttributeOperation;
|
|
16 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.TreeOperation;
|
|
17
|
|
18 import org.msgpack.MessagePack;
|
|
19 import org.msgpack.annotation.Message;
|
|
20 import org.msgpack.template.ListTemplate;
|
|
21 import org.msgpack.template.ValueTemplate;
|
|
22 import org.msgpack.type.Value;
|
|
23
|
|
24 @Message
|
|
25 public class DefaultTreeOperationLogContainer {
|
|
26
|
|
27 Value logValue;
|
|
28
|
|
29 public static void main(String[] args) throws IOException {
|
|
30 String key = "hoge";
|
|
31 ByteBuffer b = ByteBuffer.wrap("messagepack value".getBytes());
|
|
32 PutAttributeOperation putOp = new PutAttributeOperation(key, b);
|
|
33 DefaultNodePath nodePath = new DefaultNodePath();
|
|
34 nodePath = nodePath.add(1).add(2).add(3);
|
|
35
|
|
36 TreeOperation op = new DefaultTreeOperation(nodePath, putOp);
|
|
37
|
|
38
|
|
39
|
|
40 }
|
|
41
|
|
42 public DefaultTreeOperationLogContainer() {
|
|
43
|
|
44 }
|
|
45
|
|
46 public void unconvert(DefaultTreeOperationLog _log) throws IOException {
|
|
47 MessagePack msgpack = new MessagePack();
|
|
48 List<Value> list = new LinkedList<Value>();
|
|
49 for(TreeOperation op : _log) {
|
|
50 NodeOperation nOp = op.getNodeOperation();
|
|
51 NodePath nodePath = op.getNodePath();
|
|
52 DefaultNodeOperationContainer nodeOpContainer = new DefaultNodeOperationContainer();
|
|
53 nodeOpContainer.unconvert(nOp);
|
|
54 DefaultNodePathContainer nodePathContainer = new DefaultNodePathContainer();
|
|
55 nodePathContainer.unconvert(nodePath);
|
|
56 DefaultTreeOperationContainer container = new DefaultTreeOperationContainer();
|
|
57 container.unconvert(nodeOpContainer, nodePathContainer);
|
|
58 Value v = msgpack.unconvert(container);
|
|
59 list.add(v);
|
|
60 }
|
|
61 /* */
|
|
62 msgpack.register(List.class, new ListTemplate(ValueTemplate.getInstance()));
|
|
63 Value listValue = msgpack.unconvert(list);
|
|
64 logValue = listValue;
|
|
65 }
|
|
66
|
|
67 public DefaultTreeOperationLog convert() throws IOException {
|
|
68 MessagePack msgpack = new MessagePack();
|
|
69 msgpack.register(List.class, new ListTemplate(ValueTemplate.getInstance()));
|
|
70 List<Value> listValue = msgpack.convert(logValue, List.class);
|
|
71 List<TreeOperation> logList = new LinkedList<TreeOperation>();
|
|
72 for(Value v: listValue) {
|
|
73 DefaultTreeOperationContainer container = msgpack.convert(v, DefaultTreeOperationContainer.class);
|
|
74 logList.add(container.convert());
|
|
75 }
|
|
76 DefaultTreeOperationLog log = new DefaultTreeOperationLog(logList, logList.size());
|
|
77 return log;
|
|
78 }
|
|
79
|
|
80
|
|
81
|
|
82 }
|