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