comparison src/alice/jungle/datasegment/store/container/DefaultTreeOperationContainer.java @ 75:87ec5dd0dc27

Rename from alice.jungle.datasegment.store.operation to alice.jungle.datasegment.store.container
author one
date Tue, 15 Oct 2013 14:43:29 +0900
parents src/alice/jungle/datasegment/store/operations/DefaultTreeOperationContainer.java@85bc7416ae02
children
comparison
equal deleted inserted replaced
74:19e278488b42 75:87ec5dd0dc27
1 package alice.jungle.datasegment.store.container;
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 import alice.codesegment.SingletonMessage;
19
20 @Message
21 public class DefaultTreeOperationContainer {
22
23 Value pathValue;
24 Value opValue;
25
26 public static void main(String[] args) throws IOException {
27 String key = "hoge";
28 ByteBuffer b = ByteBuffer.wrap("messagepack value".getBytes());
29 PutAttributeOperation op = new PutAttributeOperation(key, b);
30
31 DefaultNodePath p = new DefaultNodePath();
32 p = p.add(1).add(2).add(3);
33 DefaultTreeOperation treeOp = new DefaultTreeOperation(p, op);
34
35 DefaultTreeOperationContainer treeOperationContainer = new DefaultTreeOperationContainer();
36 treeOperationContainer.unconvert(treeOp);
37
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));
65 for (int i: nodePath ) {
66 System.out.println(i);
67 }
68 }
69
70 public DefaultTreeOperationContainer() {
71
72 }
73
74 public void unconvert(DefaultTreeOperation _op) throws IOException {
75 NodeOperation nodeOp = _op.getNodeOperation();
76 NodePath nodePath = _op.getNodePath();
77 DefaultNodeOperationContainer opContainer = new DefaultNodeOperationContainer();
78 opContainer.unconvert(nodeOp);
79 DefaultNodePathContainer pathContainer = new DefaultNodePathContainer();
80 pathContainer.unconvert(nodePath);
81 unconvert(opContainer, pathContainer);
82 }
83
84 public void unconvert(DefaultNodeOperationContainer _op,
85 DefaultNodePathContainer _path) throws IOException {
86 // MessagePack msgpack = new MessagePack();
87 MessagePack msgpack = SingletonMessage.getInstance();
88 pathValue = msgpack.unconvert(_path);
89 opValue = msgpack.unconvert(_op);
90 }
91
92 public TreeOperation convert() throws IOException {
93 // MessagePack msgpack = new MessagePack();
94 MessagePack msgpack = SingletonMessage.getInstance();
95 DefaultNodePathContainer pathContainer = msgpack.convert(pathValue, DefaultNodePathContainer.class);
96 DefaultNodeOperationContainer opContainer = msgpack.convert(opValue, DefaultNodeOperationContainer.class);
97 return new DefaultTreeOperation(pathContainer.convert(), opContainer.convert());
98 }
99
100 }