Mercurial > hg > Members > nobuyasu > jungle-network
comparison src/jungle/test/codesegment/practice/TestCodeSegment.java @ 9:49c0eaa4dce2
add StartCodeSegment.java
author | one |
---|---|
date | Tue, 11 Jun 2013 14:09:42 +0900 |
parents | 20498c88a70d |
children | 5376ac62ac08 |
comparison
equal
deleted
inserted
replaced
8:ee93e16d5a3f | 9:49c0eaa4dce2 |
---|---|
1 package jungle.test.codesegment.practice; | 1 package jungle.test.codesegment.practice; |
2 | 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.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; | |
3 import alice.codesegment.CodeSegment; | 12 import alice.codesegment.CodeSegment; |
4 import alice.datasegment.CommandType; | 13 import alice.datasegment.CommandType; |
5 import alice.datasegment.Receiver; | 14 import alice.datasegment.Receiver; |
15 | |
16 import org.msgpack.MessagePack; | |
6 import org.msgpack.type.Value; | 17 import org.msgpack.type.Value; |
7 | 18 |
8 public class TestCodeSegment extends CodeSegment { | 19 public class TestCodeSegment extends CodeSegment { |
9 | 20 |
10 // create input datasegment arg1 | 21 // create input datasegment arg1 |
15 System.out.println("type = " + arg1.type); | 26 System.out.println("type = " + arg1.type); |
16 System.out.println("index = " + arg1.index); | 27 System.out.println("index = " + arg1.index); |
17 System.out.println("data = " + arg1.getVal()); | 28 System.out.println("data = " + arg1.getVal()); |
18 System.out.println(((Value)arg1.getVal()).getType()); | 29 System.out.println(((Value)arg1.getVal()).getType()); |
19 | 30 |
20 if (arg1.index == 10) { | 31 MessagePack msgpack = new MessagePack(); |
21 System.exit(0); | 32 Value logContainerValue = (Value) arg1.getVal(); |
22 return; | 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(); | |
23 } | 40 } |
24 | 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 /* | |
25 TestCodeSegment cs = new TestCodeSegment(); | 79 TestCodeSegment cs = new TestCodeSegment(); |
26 cs.arg1.setKey("key1", arg1.index); | 80 cs.arg1.setKey("key1", arg1.index); |
27 | 81 |
28 // DataSegment.get("local").update | 82 // DataSegment.get("local").update |
29 ods.update("local", "key1", "String data"); | 83 ods.update("local", "key1", "String data"); |
84 */ | |
30 } | 85 } |
31 | 86 |
32 } | 87 } |