17
|
1 package jungle.test.codesegment.persistence;
|
|
2
|
|
3 import java.nio.ByteBuffer;
|
|
4
|
|
5 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.persistent.ChangeList;
|
|
6 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.persistent.ChangeListReader;
|
|
7 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.persistent.ChangeListWriter;
|
|
8 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.persistent.Journal;
|
|
9 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.persistent.Result;
|
|
10 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.Command;
|
|
11 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.NodePath;
|
|
12 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.NodeOperation;
|
|
13 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.TreeOperation;
|
|
14 import jungle.test.datasegment.store.operations.DefaultNodeOperationContainer;
|
|
15 import jungle.test.datasegment.store.operations.DefaultTreeOperationContainer;
|
|
16
|
|
17 public class AliceJournal implements Journal {
|
|
18
|
|
19 private static final AliceChangeListWriter ALICE_WRITER = new AliceChangeListWriter();
|
|
20 private static final AliceChangeListReader ALICE_READER = new AliceChangeListReader();
|
|
21 @Override
|
|
22 public ChangeListReader getReader() {
|
|
23 return ALICE_READER;
|
|
24 }
|
|
25 @Override
|
|
26 public ChangeListWriter getWriter() {
|
|
27 return ALICE_WRITER;
|
|
28 }
|
|
29
|
|
30 private static class AliceChangeListWriter implements ChangeListWriter
|
|
31 {
|
|
32 @Override
|
|
33 public Result write(ChangeList _operations)
|
|
34 {
|
30
|
35 /*
|
17
|
36 for(TreeOperation op : _operations){
|
|
37 DefaultTreeOperationContainer container = new DefaultTreeOperationContainer();
|
|
38 container.unconvert(op);
|
|
39 cs.ods.update("local", "op", op);
|
|
40 }
|
|
41
|
28
|
42 */
|
17
|
43 for(TreeOperation op : _operations){
|
|
44 NodePath p = op.getNodePath();
|
|
45 NodeOperation nodeOp = op.getNodeOperation();
|
|
46 Command c = nodeOp.getCommand();
|
|
47 String args = "";
|
|
48 switch(c){
|
|
49 case PUT_ATTRIBUTE:
|
|
50 String key = nodeOp.getKey();
|
|
51 ByteBuffer value = nodeOp.getValue();
|
|
52 if(value.limit() < 100){
|
|
53 args = String.format("key:%s,value:%s",key,new String(value.array()));
|
|
54 }else{
|
|
55 args = String.format("key:%s,value:%d",key,value.limit());
|
|
56 }
|
|
57 break;
|
|
58 case DELETE_ATTRIBUTE:
|
|
59 args = String.format("key:%s",nodeOp.getKey());
|
|
60 break;
|
|
61 case APPEND_CHILD:
|
|
62 args = String.format("pos:%d",nodeOp.getPosition());
|
|
63 break;
|
|
64 case DELETE_CHILD:
|
|
65 args = String.format("pos:%d",nodeOp.getPosition());
|
|
66 break;
|
|
67 }
|
|
68 System.out.println(String.format("[%s:%s:%s]",c,p,args));
|
|
69 }
|
|
70 return Result.SUCCESS;
|
|
71 }
|
|
72 }
|
|
73
|
|
74 private static class AliceChangeListReader implements ChangeListReader
|
|
75 {
|
|
76 @Override
|
|
77 public ChangeListReader newReader()
|
|
78 {
|
|
79 return this;
|
|
80 }
|
|
81
|
|
82 @Override
|
|
83 public ChangeList read()
|
|
84 {
|
|
85 return null;
|
|
86 }
|
|
87 }
|
|
88
|
|
89
|
|
90 }
|