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 DefaultNodeOperationContainer opContainer = new DefaultNodeOperationContainer();
|
|
29 opContainer.unconvert(op);
|
|
30
|
|
31 DefaultNodePath p = new DefaultNodePath();
|
|
32 p = p.add(1).add(2).add(3);
|
|
33 DefaultNodePathContainer pathContainer = new DefaultNodePathContainer();
|
|
34 pathContainer.unconvert(p);
|
|
35
|
|
36 DefaultTreeOperationContainer treeOperationContainer = new DefaultTreeOperationContainer();
|
|
37 treeOperationContainer.unconvert(opContainer, pathContainer);
|
|
38 TreeOperation treeOperation = treeOperationContainer.convert();
|
|
39 NodePath nodePath = treeOperation.getNodePath();
|
|
40 NodeOperation nodeOp = treeOperation.getNodeOperation();
|
|
41 Command c = nodeOp.getCommand();
|
|
42 String str = "";
|
|
43 switch (c) {
|
|
44 case PUT_ATTRIBUTE:
|
|
45 String k = nodeOp.getKey();
|
|
46 ByteBuffer value = nodeOp.getValue();
|
|
47 if (value.limit() < 100) {
|
|
48 str = String.format("key:%s,value:%s", k,
|
|
49 new String(value.array()));
|
|
50 } else {
|
|
51 str = String.format("key:%s,value:%d", k, value.limit());
|
|
52 }
|
|
53 break;
|
|
54 case DELETE_ATTRIBUTE:
|
|
55 str = String.format("key:%s", nodeOp.getKey());
|
|
56 break;
|
|
57 case APPEND_CHILD:
|
|
58 str = String.format("pos:%d", nodeOp.getPosition());
|
|
59 break;
|
|
60 case DELETE_CHILD:
|
|
61 str = String.format("pos:%d", nodeOp.getPosition());
|
|
62 break;
|
|
63 }
|
|
64 System.out.println(String.format("[%s:%s:%s]", c, nodePath, str));
|
5
|
65 for (int i: nodePath ) {
|
|
66 System.out.println(i);
|
|
67 }
|
4
|
68 }
|
|
69
|
|
70 public DefaultTreeOperationContainer() {
|
|
71
|
|
72 }
|
|
73
|
|
74 public void unconvert(DefaultNodeOperationContainer _op,
|
|
75 DefaultNodePathContainer _path) throws IOException {
|
|
76 MessagePack msgpack = new MessagePack();
|
|
77 pathValue = msgpack.unconvert(_path);
|
|
78 opValue = msgpack.unconvert(_op);
|
|
79 }
|
|
80
|
|
81 public TreeOperation convert() throws IOException {
|
|
82 MessagePack msgpack = new MessagePack();
|
|
83 DefaultNodePathContainer pathContainer = msgpack.convert(pathValue, DefaultNodePathContainer.class);
|
|
84 DefaultNodeOperationContainer opContainer = msgpack.convert(opValue, DefaultNodeOperationContainer.class);
|
|
85 return new DefaultTreeOperation(pathContainer.convert(), opContainer.convert());
|
|
86 }
|
|
87
|
|
88 }
|