Mercurial > hg > Members > nobuyasu > jungle-network
diff src/jungle/test/codesegment/persistence/AliceJournal.java @ 17:c767e7af4d88
add TestPutAttributeCodeSegmnet and StartJungleCodeSegment
author | one |
---|---|
date | Fri, 28 Jun 2013 12:36:07 +0900 |
parents | |
children | e968224ad0ce |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/jungle/test/codesegment/persistence/AliceJournal.java Fri Jun 28 12:36:07 2013 +0900 @@ -0,0 +1,97 @@ +package jungle.test.codesegment.persistence; + +import java.nio.ByteBuffer; + +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.persistent.ChangeList; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.persistent.ChangeListReader; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.persistent.ChangeListWriter; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.persistent.Journal; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.persistent.Result; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.Command; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.NodePath; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.NodeOperation; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.TreeOperation; +import jungle.test.datasegment.store.operations.DefaultNodeOperationContainer; +import jungle.test.datasegment.store.operations.DefaultTreeOperationContainer; + +public class AliceJournal implements Journal { + + private static final AliceChangeListWriter ALICE_WRITER = new AliceChangeListWriter(); + private static final AliceChangeListReader ALICE_READER = new AliceChangeListReader(); + @Override + public ChangeListReader getReader() { + return ALICE_READER; + } + @Override + public ChangeListWriter getWriter() { + return ALICE_WRITER; + } + + private static class AliceChangeListWriter implements ChangeListWriter + { + @Override + public Result write(ChangeList _operations) + { + + /* + for(TreeOperation op : _operations){ + DefaultTreeOperationContainer container = new DefaultTreeOperationContainer(); + container.unconvert(op); + + cs.ods.update("local", "op", op); + + } + +*/ + + + + + for(TreeOperation op : _operations){ + NodePath p = op.getNodePath(); + NodeOperation nodeOp = op.getNodeOperation(); + Command c = nodeOp.getCommand(); + String args = ""; + switch(c){ + case PUT_ATTRIBUTE: + String key = nodeOp.getKey(); + ByteBuffer value = nodeOp.getValue(); + if(value.limit() < 100){ + args = String.format("key:%s,value:%s",key,new String(value.array())); + }else{ + args = String.format("key:%s,value:%d",key,value.limit()); + } + break; + case DELETE_ATTRIBUTE: + args = String.format("key:%s",nodeOp.getKey()); + break; + case APPEND_CHILD: + args = String.format("pos:%d",nodeOp.getPosition()); + break; + case DELETE_CHILD: + args = String.format("pos:%d",nodeOp.getPosition()); + break; + } + System.out.println(String.format("[%s:%s:%s]",c,p,args)); + } + return Result.SUCCESS; + } + } + + private static class AliceChangeListReader implements ChangeListReader + { + @Override + public ChangeListReader newReader() + { + return this; + } + + @Override + public ChangeList read() + { + return null; + } + } + + +}