Mercurial > hg > Database > jungle-network
changeset 87:f142dd4abc74
Implemented getTreeName and uuid method in some classes
author | one |
---|---|
date | Tue, 05 Nov 2013 08:41:12 +0900 |
parents | bcaf28f8244d |
children | 0c98717f186e |
files | src/alice/jungle/core/NetworkDefaultJungle.java src/alice/jungle/persistence/NetworkJournal.java src/alice/jungle/persistence/PersistentChangeList.java src/alice/jungle/persistence/PersistentChangeListWriter.java src/alice/jungle/persistence/PersistentChangeSet.java src/alice/jungle/persistence/PersistentJungle.java src/alice/jungle/persistence/PersistentTransactionManager.java src/alice/jungle/transaction/NetworkTransactionManager.java src/test/alice/jungle/PersistenJournalTest.java |
diffstat | 9 files changed, 90 insertions(+), 66 deletions(-) [+] |
line wrap: on
line diff
--- a/src/alice/jungle/core/NetworkDefaultJungle.java Tue Oct 29 16:52:12 2013 +0900 +++ b/src/alice/jungle/core/NetworkDefaultJungle.java Tue Nov 05 08:41:12 2013 +0900 @@ -3,7 +3,6 @@ import java.util.Iterator; import java.util.concurrent.ConcurrentHashMap; -import alice.jungle.persistence.AliceJournal; import alice.jungle.transaction.NetworkDefaultJungleTree; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.Jungle; @@ -41,7 +40,7 @@ } @Override - public JungleTree createNewTree(String _name) + public JungleTree createNewTree(final String _name) { ChangeList list = new ChangeList(){ @Override @@ -49,9 +48,18 @@ List<TreeOperation> nil = List.nil(); return nil.iterator(); } + @Override + public String uuid() { + return uuid; + } + @Override + public String getTreeName() { + return _name; + } + }; DefaultTreeNode root = new DefaultTreeNode(); - ChangeSet set = new DefaultChangeSet(root.getAsNode(),null,list,uuid,0); + ChangeSet set = new DefaultChangeSet(root.getAsNode(),null,list,uuid,_name, 0); DefaultTreeContext<DefaultTreeNode> tc = new DefaultTreeContext<DefaultTreeNode>(root,set); JungleTree newTree = new NetworkDefaultJungleTree<DefaultTreeNode>(_name, tc,uuid,journal.getWriter(),editor, serverName); if(trees.putIfAbsent(_name,newTree) != null){
--- a/src/alice/jungle/persistence/NetworkJournal.java Tue Oct 29 16:52:12 2013 +0900 +++ b/src/alice/jungle/persistence/NetworkJournal.java Tue Nov 05 08:41:12 2013 +0900 @@ -114,6 +114,14 @@ public Iterator<TreeOperation> iterator() { return readLog.iterator(); } + @Override + public String uuid() { + return readLog.getUUID(); + } + @Override + public String getTreeName() { + return readLog.getTreeName(); + } }; return cl; } catch (EOFException e){
--- a/src/alice/jungle/persistence/PersistentChangeList.java Tue Oct 29 16:52:12 2013 +0900 +++ b/src/alice/jungle/persistence/PersistentChangeList.java Tue Nov 05 08:41:12 2013 +0900 @@ -5,6 +5,7 @@ import alice.jungle.operations.NetworkTreeOperationLog; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.persistent.ChangeList; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.logger.TreeOperationLog; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.TreeOperation; public class PersistentChangeList implements ChangeList { @@ -13,6 +14,12 @@ public String treeName; public String uuid; + public PersistentChangeList(String _uuid, String _treeName, TreeOperationLog _log) { + uuid = _uuid; + treeName = _treeName; + log = new NetworkTreeOperationLog(_log); + } + public PersistentChangeList(NetworkTreeOperationLog _log) { log = _log; treeName = _log.getTreeName(); @@ -38,7 +45,7 @@ return treeName; } - public String getUUID() { + public String uuid() { return uuid; }
--- a/src/alice/jungle/persistence/PersistentChangeListWriter.java Tue Oct 29 16:52:12 2013 +0900 +++ b/src/alice/jungle/persistence/PersistentChangeListWriter.java Tue Nov 05 08:41:12 2013 +0900 @@ -22,26 +22,14 @@ @Override public Result write(ChangeList _operations) { - NetworkTreeOperationLog log = new NetworkTreeOperationLog(_operations); + PersistentChangeList plist = (PersistentChangeList) _operations; + NetworkTreeOperationLog log = new NetworkTreeOperationLog(plist.uuid(), plist.getTreeName(), plist.getTreeOperationLog()); try { msgpack.write(out, log); out.flush(); + return Result.SUCCESS; } catch (IOException e) { - return null; } - return Result.SUCCESS; + return null; } - - public Result write(PersistentChangeSet cs) - { - NetworkTreeOperationLog log = new NetworkTreeOperationLog(cs.uuid(), cs.getTreeName(),cs.getChangeList()); - try { - msgpack.write(out, log); - out.flush(); - } catch (IOException e) { - return null; - } - return Result.SUCCESS; - } - }
--- a/src/alice/jungle/persistence/PersistentChangeSet.java Tue Oct 29 16:52:12 2013 +0900 +++ b/src/alice/jungle/persistence/PersistentChangeSet.java Tue Nov 05 08:41:12 2013 +0900 @@ -14,7 +14,7 @@ private final long revision; private final String treeName; - public PersistentChangeSet(Node _node,ChangeSet _prev,ChangeList _log,String _uuid,long _revision, String _treeName) + public PersistentChangeSet(Node _node,ChangeSet _prev,ChangeList _log,String _uuid, String _treeName, long _revision) { root = _node; previous = _prev;
--- a/src/alice/jungle/persistence/PersistentJungle.java Tue Oct 29 16:52:12 2013 +0900 +++ b/src/alice/jungle/persistence/PersistentJungle.java Tue Nov 05 08:41:12 2013 +0900 @@ -17,7 +17,7 @@ public class PersistentJungle implements Jungle { private PersistentJournal journal; private ConcurrentHashMap<String,JungleTree> trees; - private String uuid; + final private String uuid; private TreeEditor editor; public PersistentJungle(PersistentJournal _journal,String _uuid,TreeEditor _editor) @@ -35,7 +35,7 @@ } @Override - public JungleTree createNewTree(String _name) + public JungleTree createNewTree(final String _name) { ChangeList list = new ChangeList(){ @Override @@ -43,9 +43,17 @@ List<TreeOperation> nil = List.nil(); return nil.iterator(); } + @Override + public String uuid() { + return uuid; + } + @Override + public String getTreeName() { + return _name; + } }; DefaultTreeNode root = new DefaultTreeNode(); - ChangeSet set = new PersistentChangeSet(root.getAsNode(),null,list,uuid,0, _name); + ChangeSet set = new PersistentChangeSet(root.getAsNode(),null,list,uuid,_name,0); DefaultTreeContext<DefaultTreeNode> tc = new DefaultTreeContext<DefaultTreeNode>(root,set); JungleTree newTree = new PersistentJungleTree<DefaultTreeNode>(_name, tc,uuid, (PersistentChangeListWriter)journal.getWriter(),editor); if(trees.putIfAbsent(_name,newTree) != null){
--- a/src/alice/jungle/persistence/PersistentTransactionManager.java Tue Oct 29 16:52:12 2013 +0900 +++ b/src/alice/jungle/persistence/PersistentTransactionManager.java Tue Nov 05 08:41:12 2013 +0900 @@ -42,15 +42,9 @@ long currentRevision = cs.revision(); long nextRevision = currentRevision + 1; - ChangeList list = new ChangeList() { - @Override - public Iterator<TreeOperation> iterator(){ - return _log.iterator(); - } - }; - + PersistentChangeList list = new PersistentChangeList(uuid, treeName, _log); Node root = _newRoot.getAsNode(); - PersistentChangeSet newCs = new PersistentChangeSet(root, cs, list, uuid, nextRevision, treeName); + PersistentChangeSet newCs = new PersistentChangeSet(root, cs, list, uuid, treeName, nextRevision); DefaultTreeContext<T> newContext = new DefaultTreeContext<T>(_newRoot,newCs); @SuppressWarnings("rawtypes") @@ -58,8 +52,7 @@ if(reservation == null) { return DefaultEither.newA((Error)new DefaultError()); } -// Result r = writer.write(list); - Result r = writer.write(newCs); + Result r = writer.write(list); if(r != Result.SUCCESS) { return DefaultEither.newA((Error)new DefaultError()); }
--- a/src/alice/jungle/transaction/NetworkTransactionManager.java Tue Oct 29 16:52:12 2013 +0900 +++ b/src/alice/jungle/transaction/NetworkTransactionManager.java Tue Nov 05 08:41:12 2013 +0900 @@ -53,10 +53,18 @@ public Iterator<TreeOperation> iterator(){ return _log.iterator(); } + @Override + public String uuid() { + return uuid; + } + @Override + public String getTreeName() { + return treeName; + } }; Node root = _newRoot.getAsNode(); - DefaultChangeSet newCs = new DefaultChangeSet(root, cs, list, uuid, nextRevision); + DefaultChangeSet newCs = new DefaultChangeSet(root, cs, list, uuid, treeName, nextRevision); DefaultTreeContext<T> newContext = new DefaultTreeContext<T>(_newRoot,newCs); @SuppressWarnings("rawtypes")
--- a/src/test/alice/jungle/PersistenJournalTest.java Tue Oct 29 16:52:12 2013 +0900 +++ b/src/test/alice/jungle/PersistenJournalTest.java Tue Nov 05 08:41:12 2013 +0900 @@ -8,6 +8,7 @@ import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.JungleTree; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.JungleTreeEditor; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.core.Node; +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.store.Command; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.NodePath; @@ -43,7 +44,6 @@ } editor = either.b(); either = editor.putAttribute(path, key, value); - JungleTreeEditor e = either.b(); e.success(); journal.close(); @@ -68,36 +68,7 @@ } editor2 = either2.b(); editor2.success(); - - for (TreeOperation op : chList) { - NodePath p = op.getNodePath(); - NodeOperation nodeOp = op.getNodeOperation(); - Command c = nodeOp.getCommand(); - String str = ""; - switch (c) { - case PUT_ATTRIBUTE: - String opKey = nodeOp.getKey(); - ByteBuffer opValue = nodeOp.getValue(); - if (value.limit() < 100) { - str = String.format("key:%s,value:%s", opKey, - new String(opValue.array())); - } else { - str = String.format("key:%s,value:%d", opKey, - opValue.limit()); - } - break; - case DELETE_ATTRIBUTE: - str = String.format("key:%s", nodeOp.getKey()); - break; - case APPEND_CHILD: - str = String.format("pos:%d", nodeOp.getPosition()); - break; - case DELETE_CHILD: - str = String.format("pos:%d", nodeOp.getPosition()); - break; - } - System.out.println(String.format("[%s:%s:%s]", c, p, str)); - } + printChangeList(chList); System.out.println(); } JungleTree tree2 = jungle2.getTreeByName("hoge"); @@ -108,4 +79,37 @@ } + public static void printChangeList(ChangeList chList) { + for (TreeOperation op : chList) { + NodePath p = op.getNodePath(); + NodeOperation nodeOp = op.getNodeOperation(); + Command c = nodeOp.getCommand(); + String str = ""; + switch (c) { + case PUT_ATTRIBUTE: + String opKey = nodeOp.getKey(); + ByteBuffer opValue = nodeOp.getValue(); + if (opValue.limit() < 100) { + str = String.format("key:%s,value:%s", opKey, + new String(opValue.array())); + } else { + str = String.format("key:%s,value:%d", opKey, + opValue.limit()); + } + break; + case DELETE_ATTRIBUTE: + str = String.format("key:%s", nodeOp.getKey()); + break; + case APPEND_CHILD: + str = String.format("pos:%d", nodeOp.getPosition()); + break; + case DELETE_CHILD: + str = String.format("pos:%d", nodeOp.getPosition()); + break; + } + System.out.println(String.format("[%s:%s:%s]", c, p, str)); + } + + } + }