4
|
1 package jungle.test.datasegment.store.operations;
|
|
2
|
|
3 import java.io.IOException;
|
|
4 import java.nio.ByteBuffer;
|
|
5
|
|
6 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.Command;
|
|
7 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.NodePath;
|
|
8 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.DefaultNodePath;
|
|
9 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.DefaultTreeOperation;
|
|
10 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.NodeOperation;
|
|
11 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.PutAttributeOperation;
|
|
12 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.TreeOperation;
|
|
13
|
|
14 import org.msgpack.MessagePack;
|
|
15 import org.msgpack.annotation.Message;
|
|
16 import org.msgpack.type.Value;
|
|
17
|
|
18 @Message
|
|
19 public class DefaultTreeOperationContainer {
|
|
20
|
|
21 Value pathValue;
|
|
22 Value opValue;
|
|
23
|
|
24 public static void main(String[] args) throws IOException {
|
|
25 String key = "hoge";
|
|
26 ByteBuffer b = ByteBuffer.wrap("messagepack value".getBytes());
|
|
27 PutAttributeOperation op = new PutAttributeOperation(key, b);
|
|
28
|
|
29 DefaultNodePath p = new DefaultNodePath();
|
|
30 p = p.add(1).add(2).add(3);
|
6
|
31 DefaultTreeOperation treeOp = new DefaultTreeOperation(p, op);
|
|
32
|
|
33 DefaultTreeOperationContainer treeOperationContainer = new DefaultTreeOperationContainer();
|
|
34 treeOperationContainer.unconvert(treeOp);
|
4
|
35
|
|
36 TreeOperation treeOperation = treeOperationContainer.convert();
|
|
37 NodePath nodePath = treeOperation.getNodePath();
|
|
38 NodeOperation nodeOp = treeOperation.getNodeOperation();
|
|
39 Command c = nodeOp.getCommand();
|
|
40 String str = "";
|
|
41 switch (c) {
|
|
42 case PUT_ATTRIBUTE:
|
|
43 String k = nodeOp.getKey();
|
|
44 ByteBuffer value = nodeOp.getValue();
|
|
45 if (value.limit() < 100) {
|
|
46 str = String.format("key:%s,value:%s", k,
|
|
47 new String(value.array()));
|
|
48 } else {
|
|
49 str = String.format("key:%s,value:%d", k, value.limit());
|
|
50 }
|
|
51 break;
|
|
52 case DELETE_ATTRIBUTE:
|
|
53 str = String.format("key:%s", nodeOp.getKey());
|
|
54 break;
|
|
55 case APPEND_CHILD:
|
|
56 str = String.format("pos:%d", nodeOp.getPosition());
|
|
57 break;
|
|
58 case DELETE_CHILD:
|
|
59 str = String.format("pos:%d", nodeOp.getPosition());
|
|
60 break;
|
|
61 }
|
|
62 System.out.println(String.format("[%s:%s:%s]", c, nodePath, str));
|
5
|
63 for (int i: nodePath ) {
|
|
64 System.out.println(i);
|
|
65 }
|
4
|
66 }
|
|
67
|
|
68 public DefaultTreeOperationContainer() {
|
|
69
|
|
70 }
|
6
|
71
|
|
72 public void unconvert(DefaultTreeOperation _op) throws IOException {
|
|
73 NodeOperation nodeOp = _op.getNodeOperation();
|
|
74 NodePath nodePath = _op.getNodePath();
|
|
75 DefaultNodeOperationContainer opContainer = new DefaultNodeOperationContainer();
|
|
76 opContainer.unconvert(nodeOp);
|
|
77 DefaultNodePathContainer pathContainer = new DefaultNodePathContainer();
|
|
78 pathContainer.unconvert(nodePath);
|
|
79 unconvert(opContainer, pathContainer);
|
|
80 }
|
4
|
81
|
|
82 public void unconvert(DefaultNodeOperationContainer _op,
|
|
83 DefaultNodePathContainer _path) throws IOException {
|
|
84 MessagePack msgpack = new MessagePack();
|
|
85 pathValue = msgpack.unconvert(_path);
|
|
86 opValue = msgpack.unconvert(_op);
|
|
87 }
|
|
88
|
|
89 public TreeOperation convert() throws IOException {
|
|
90 MessagePack msgpack = new MessagePack();
|
|
91 DefaultNodePathContainer pathContainer = msgpack.convert(pathValue, DefaultNodePathContainer.class);
|
|
92 DefaultNodeOperationContainer opContainer = msgpack.convert(opValue, DefaultNodeOperationContainer.class);
|
|
93 return new DefaultTreeOperation(pathContainer.convert(), opContainer.convert());
|
|
94 }
|
|
95
|
|
96 }
|