2
|
1 package jungle.test.codesegment.practice;
|
|
2
|
9
|
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.logger.TreeOperationLog;
|
|
9 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.NodeOperation;
|
|
10 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.TreeOperation;
|
|
11 import jungle.test.datasegment.store.operations.DefaultTreeOperationLogContainer;
|
2
|
12 import alice.codesegment.CodeSegment;
|
|
13 import alice.datasegment.CommandType;
|
|
14 import alice.datasegment.Receiver;
|
9
|
15
|
|
16 import org.msgpack.MessagePack;
|
2
|
17 import org.msgpack.type.Value;
|
|
18
|
|
19 public class TestCodeSegment extends CodeSegment {
|
|
20
|
|
21 // create input datasegment arg1
|
|
22 Receiver arg1 = ids.create(CommandType.PEEK);
|
|
23
|
|
24 @Override
|
|
25 public void run() {
|
|
26 System.out.println("type = " + arg1.type);
|
|
27 System.out.println("index = " + arg1.index);
|
|
28 System.out.println("data = " + arg1.getVal());
|
|
29 System.out.println(((Value)arg1.getVal()).getType());
|
|
30
|
9
|
31 MessagePack msgpack = new MessagePack();
|
|
32 Value logContainerValue = (Value) arg1.getVal();
|
|
33 DefaultTreeOperationLogContainer convertedLogContainer;
|
|
34 TreeOperationLog convertedLog = null;
|
|
35 try {
|
|
36 convertedLogContainer = msgpack.convert(logContainerValue, DefaultTreeOperationLogContainer.class);
|
|
37 convertedLog = convertedLogContainer.convert();
|
|
38 } catch (IOException e) {
|
|
39 e.printStackTrace();
|
2
|
40 }
|
9
|
41
|
|
42 for (TreeOperation treeOp : convertedLog) {
|
|
43 NodePath path = treeOp.getNodePath();
|
|
44 NodeOperation nodeOp = treeOp.getNodeOperation();
|
|
45 Command c = nodeOp.getCommand();
|
|
46 String str = "";
|
|
47 switch (c) {
|
|
48 case PUT_ATTRIBUTE:
|
|
49 String k = nodeOp.getKey();
|
|
50 ByteBuffer value = nodeOp.getValue();
|
|
51 if (value.limit() < 100) {
|
|
52 str = String.format("key:%s,value:%s", k,
|
|
53 new String(value.array()));
|
|
54 } else {
|
|
55 str = String.format("key:%s,value:%d", k, value.limit());
|
|
56 }
|
|
57 break;
|
|
58 case DELETE_ATTRIBUTE:
|
|
59 str = String.format("key:%s", nodeOp.getKey());
|
|
60 break;
|
|
61 case APPEND_CHILD:
|
|
62 str = String.format("pos:%d", nodeOp.getPosition());
|
|
63 break;
|
|
64 case DELETE_CHILD:
|
|
65 str = String.format("pos:%d", nodeOp.getPosition());
|
|
66 break;
|
|
67 }
|
|
68 System.out.println(String.format("[%s:%s]", c, str));
|
|
69 System.out.println("path:");
|
|
70 for (int i: path ) {
|
|
71 System.out.println(i);
|
|
72 }
|
|
73
|
|
74 }
|
|
75
|
|
76 System.exit(0);
|
|
77
|
|
78 /*
|
2
|
79 TestCodeSegment cs = new TestCodeSegment();
|
|
80 cs.arg1.setKey("key1", arg1.index);
|
|
81
|
|
82 // DataSegment.get("local").update
|
|
83 ods.update("local", "key1", "String data");
|
9
|
84 */
|
2
|
85 }
|
|
86
|
|
87 }
|