Mercurial > hg > Members > nobuyasu > jungle-network
changeset 194:fd4064e110bd fjTreeMap
change TreeContext
author | tatsuki |
---|---|
date | Mon, 23 Mar 2015 16:18:47 +0900 |
parents | 89c15aa2bc6d |
children | 82698be06c6c |
files | src/main/java/alice/jungle/core/NetworkDefaultJungle.java src/main/java/alice/jungle/persistent/PersistentJungle.java src/main/java/alice/jungle/persistent/PersistentJungleTree.java src/main/java/alice/jungle/persistent/PersistentTransactionManager.java src/main/java/alice/jungle/persistent/PersistentTreeContext.java src/main/java/alice/jungle/transaction/NetworkDefaultJungleTree.java src/main/java/alice/jungle/transaction/NetworkTransactionManager.java |
diffstat | 7 files changed, 111 insertions(+), 124 deletions(-) [+] |
line wrap: on
line diff
--- a/src/main/java/alice/jungle/core/NetworkDefaultJungle.java Fri Mar 20 16:18:42 2015 +0900 +++ b/src/main/java/alice/jungle/core/NetworkDefaultJungle.java Mon Mar 23 16:18:47 2015 +0900 @@ -14,6 +14,7 @@ import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.TreeOperation; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.transaction.DefaultTreeContext; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.transaction.DefaultTreeNode; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.traverser.InterfaceTraverser; import jp.ac.u_ryukyu.ie.cr.tatsuki.jungle.store.index.ParentIndex; import fj.Ord; import fj.data.List; @@ -57,9 +58,8 @@ } }; TreeNode root = new DefaultTreeNode(); - TreeMap<String, TreeMap<String, TreeMap<TreeNode, TreeNode>>> indexList = TreeMap.empty(Ord.stringOrd); - TreeMap<TreeNode, TreeNode> parentIndex = new ParentIndex().getParentIndex(); - TreeContext tc = new DefaultTreeContext(root, null, list, uuid, name, 0, indexList, parentIndex); + InterfaceTraverser traverser = new InterfaceTraverser(root,true); + TreeContext tc = new DefaultTreeContext(root, null, list, uuid, name, 0, traverser); JungleTree newTree = new NetworkDefaultJungleTree(name, tc, uuid, journal.getWriter(), editor); if (trees.putIfAbsent(name, newTree) != null) { return null;
--- a/src/main/java/alice/jungle/persistent/PersistentJungle.java Fri Mar 20 16:18:42 2015 +0900 +++ b/src/main/java/alice/jungle/persistent/PersistentJungle.java Mon Mar 23 16:18:47 2015 +0900 @@ -14,6 +14,7 @@ import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.TreeNode; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.TreeOperation; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.transaction.DefaultTreeNode; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.traverser.InterfaceTraverser; import jp.ac.u_ryukyu.ie.cr.tatsuki.jungle.store.index.ParentIndex; public class PersistentJungle implements Jungle { @@ -54,9 +55,8 @@ } }; TreeNode root = new DefaultTreeNode(); - TreeMap<String, TreeMap<String, TreeMap<TreeNode, TreeNode>>> indexList = TreeMap.empty(Ord.stringOrd); - TreeMap<TreeNode, TreeNode> parentIndex = new ParentIndex().getParentIndex(); - TreeContext tc = new PersistentTreeContext(root, null, list, uuid, name, 0, indexList, parentIndex); + InterfaceTraverser traverser = new InterfaceTraverser(root,true); + TreeContext tc = new PersistentTreeContext(root, null, list, uuid, name, 0, traverser); JungleTree newTree = new PersistentJungleTree(name, tc, uuid, journal.getWriter(), editor); if (trees.putIfAbsent(name, newTree) != null) { return null;
--- a/src/main/java/alice/jungle/persistent/PersistentJungleTree.java Fri Mar 20 16:18:42 2015 +0900 +++ b/src/main/java/alice/jungle/persistent/PersistentJungleTree.java Mon Mar 23 16:18:47 2015 +0900 @@ -1,5 +1,6 @@ package alice.jungle.persistent; +import fj.data.List; import fj.data.TreeMap; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.DefaultJungleTree; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.JungleTree; @@ -85,14 +86,14 @@ } @Override - public TreeMap<String, TreeMap<String, TreeMap<TreeNode, TreeNode>>> getIndex() { + public TreeMap<String, TreeMap<String,List<TreeNode>>> getIndex() { TreeContext tc = repository.get(); return tc.getIndex(); } @Override public InterfaceTraverser getTraverser(boolean useIndex) { - TreeMap<String, TreeMap<String, TreeMap<TreeNode, TreeNode>>> index = getIndex(); + TreeMap<String, TreeMap<String, List<TreeNode>>> index = getIndex(); ParentIndex parentIndex = getParentIndex(); return new InterfaceTraverser(getRootNode(), index, parentIndex, useIndex); }
--- a/src/main/java/alice/jungle/persistent/PersistentTransactionManager.java Fri Mar 20 16:18:42 2015 +0900 +++ b/src/main/java/alice/jungle/persistent/PersistentTransactionManager.java Mon Mar 23 16:18:47 2015 +0900 @@ -1,6 +1,7 @@ package alice.jungle.persistent; +import fj.data.List; import fj.data.TreeMap; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.persistent.ChangeListWriter; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.TreeContext; @@ -16,55 +17,50 @@ import java.util.concurrent.atomic.AtomicReference; -public class PersistentTransactionManager implements TransactionManager { - private final AtomicReference<TreeContext> repository; - private final TreeContext tip; - private final ChangeListWriter writer; - private final String uuid; - private final String treeName; +public class PersistentTransactionManager implements TransactionManager { + private final AtomicReference<TreeContext> repository; + private final TreeContext tip; + private final ChangeListWriter writer; + private final String uuid; + private final String treeName; - public PersistentTransactionManager(String _treeName, ChangeListWriter _writer,TreeContext _tip, - AtomicReference<TreeContext> _repository,String _uuid) - { - repository = _repository; - tip = _tip; - writer = _writer; - uuid = _uuid; - treeName = _treeName; - } - - @Override - public Either<Error, TransactionManager> commit(TreeNode _newRoot,final TreeOperationLog _log) { - long currentRevision = tip.revision(); - long nextRevision = currentRevision + 1; + public PersistentTransactionManager(String _treeName, ChangeListWriter _writer, TreeContext _tip, + AtomicReference<TreeContext> _repository, String _uuid) { + repository = _repository; + tip = _tip; + writer = _writer; + uuid = _uuid; + treeName = _treeName; + } - PersistentChangeList list = new PersistentChangeList(uuid, treeName, _log); - InterfaceTraverser traverser = new InterfaceTraverser(_newRoot,false); - traverser.createIndex(); - TreeMap<String, TreeMap<String, TreeMap<TreeNode, TreeNode>>> index = traverser.getIndex(); - ParentIndex parentIndex = traverser.getParentIndex(); - PersistentTreeContext newContext = new PersistentTreeContext(_newRoot, tip, list, uuid, treeName, nextRevision, index, parentIndex.getParentIndex()); + @Override + public Either<Error, TransactionManager> commit(TreeNode _newRoot, final TreeOperationLog _log) { + long currentRevision = tip.revision(); + long nextRevision = currentRevision + 1; - if (repository.compareAndSet(newContext.prev(),newContext)) { + PersistentChangeList list = new PersistentChangeList(uuid, treeName, _log); + InterfaceTraverser traverser = new InterfaceTraverser(_newRoot, false); + traverser.createIndex(); + PersistentTreeContext newContext = new PersistentTreeContext(_newRoot, tip, list, uuid, treeName, nextRevision, traverser); + + if (repository.compareAndSet(newContext.prev(), newContext)) { TransactionManager txManager = new PersistentTransactionManager(treeName, writer, newContext, repository, uuid); return DefaultEither.newB(txManager); } return DefaultEither.newA((Error) new DefaultError()); - } + } - @Override - public long getRevision() - { - return tip.revision(); - } + @Override + public long getRevision() { + return tip.revision(); + } - @Override - public String getUUID() { - return uuid; - } - - - + @Override + public String getUUID() { + return uuid; + } + + }
--- a/src/main/java/alice/jungle/persistent/PersistentTreeContext.java Fri Mar 20 16:18:42 2015 +0900 +++ b/src/main/java/alice/jungle/persistent/PersistentTreeContext.java Mon Mar 23 16:18:47 2015 +0900 @@ -1,87 +1,82 @@ package alice.jungle.persistent; import fj.Ord; +import fj.data.List; import fj.data.TreeMap; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.persistent.ChangeList; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.TreeContext; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.TreeNode; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.TreeOperation; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.traverser.InterfaceTraverser; import jp.ac.u_ryukyu.ie.cr.tatsuki.jungle.store.index.ParentIndex; public class PersistentTreeContext implements TreeContext { - private final TreeNode root; - private final TreeContext previous; - private final ChangeList changeList; - private final String uuid; - private final long revision; - private final String treeName; - private TreeMap<String, TreeMap<String, TreeMap<TreeNode, TreeNode>>> indexList; - private TreeMap<TreeNode, TreeNode> parentIndex; - - public PersistentTreeContext(TreeNode _node, TreeContext _prev, ChangeList _log, String _uuid, String _treeName, - long _revision, TreeMap<String, TreeMap<String, TreeMap<TreeNode, TreeNode>>> indexList, - TreeMap<TreeNode, TreeNode> parentIndex) { - root = _node; - previous = _prev; - changeList = _log; - uuid = _uuid; - revision = _revision; - treeName = _treeName; - this.indexList = indexList; - this.parentIndex = parentIndex; - } - - @Override - public TreeNode getRoot() { - return root; - } - - @Override - public TreeContext prev() { - return previous; - } + private final TreeNode root; + private final TreeContext previous; + private final ChangeList changeList; + private final String uuid; + private final long revision; + private final String treeName; + private InterfaceTraverser traverser; - @Override - public ChangeList getChangeList() { - return changeList; - } - - @Override - public String uuid() { - return uuid; - } - - @Override - public long revision() { - return revision; - } - - @Override - public Iterable<TreeOperation> getOperations() { - return changeList; - } - - public String getTreeName() { - return treeName; - } - @Override - public TreeMap<String, TreeMap<String, TreeMap<TreeNode, TreeNode>>> getIndex() { - return indexList; - } - - @Override - public ParentIndex getParentIndex() { - return new ParentIndex(parentIndex); - } + public PersistentTreeContext(TreeNode _node, TreeContext _prev, ChangeList _log, String _uuid, String _treeName, + long _revision, InterfaceTraverser traverser) { + this.root = _node; + this.previous = _prev; + this.changeList = _log; + this.uuid = _uuid; + this.revision = _revision; + this.treeName = _treeName; + this.traverser = traverser; + } @Override - public void setIndex(TreeMap<String, TreeMap<String, TreeMap<TreeNode, TreeNode>>> indexList) { - this.indexList = indexList; + public TreeNode getRoot() { + return root; + } + + @Override + public TreeContext prev() { + return previous; + } + + @Override + public ChangeList getChangeList() { + return changeList; } @Override - public void setParentIndex(ParentIndex parentIndex) { - this.parentIndex = parentIndex.getParentIndex(); + public String uuid() { + return uuid; + } + + @Override + public long revision() { + return revision; + } + + @Override + public Iterable<TreeOperation> getOperations() { + return changeList; + } + + public String getTreeName() { + return treeName; + } + + @Override + public TreeMap<String, TreeMap<String, List<TreeNode>>> getIndex() { + return traverser.getIndex(); + } + + @Override + public ParentIndex getParentIndex() { + return traverser.getParentIndex(); + } + + @Override + public InterfaceTraverser getTraverser() { + return traverser; } }
--- a/src/main/java/alice/jungle/transaction/NetworkDefaultJungleTree.java Fri Mar 20 16:18:42 2015 +0900 +++ b/src/main/java/alice/jungle/transaction/NetworkDefaultJungleTree.java Mon Mar 23 16:18:47 2015 +0900 @@ -1,6 +1,7 @@ package alice.jungle.transaction; +import fj.data.List; import fj.data.TreeMap; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.DefaultJungleTree; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.JungleTree; @@ -90,15 +91,14 @@ } @Override - public TreeMap<String, TreeMap<String, TreeMap<TreeNode, TreeNode>>> getIndex() { + public TreeMap<String, TreeMap<String, List<TreeNode>>> getIndex() { TreeContext tc = repository.get(); return tc.getIndex(); } - @Override public InterfaceTraverser getTraverser(boolean useIndex) { - TreeMap<String, TreeMap<String, TreeMap<TreeNode, TreeNode>>> index = getIndex(); + TreeMap<String, TreeMap<String, List<TreeNode>>> index = getIndex(); ParentIndex parentIndex = getParentIndex(); return new InterfaceTraverser(getRootNode(), index, parentIndex, useIndex); }
--- a/src/main/java/alice/jungle/transaction/NetworkTransactionManager.java Fri Mar 20 16:18:42 2015 +0900 +++ b/src/main/java/alice/jungle/transaction/NetworkTransactionManager.java Mon Mar 23 16:18:47 2015 +0900 @@ -3,10 +3,8 @@ import java.util.Iterator; import java.util.concurrent.atomic.AtomicReference; -import fj.data.TreeMap; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.persistent.ChangeList; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.persistent.ChangeListWriter; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.persistent.Result; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.TreeContext; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.TreeNode; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.logger.TreeOperationLog; @@ -18,7 +16,6 @@ import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.DefaultError; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Either; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Error; -import jp.ac.u_ryukyu.ie.cr.tatsuki.jungle.store.index.ParentIndex; public class NetworkTransactionManager implements TransactionManager { private final AtomicReference<TreeContext> repository; @@ -60,9 +57,7 @@ InterfaceTraverser traverser = new InterfaceTraverser(newRoot, true); traverser.createIndex(); - TreeMap<String, TreeMap<String, TreeMap<TreeNode, TreeNode>>> index = traverser.getIndex(); - ParentIndex parentIndex = traverser.getParentIndex(); - TreeContext newTreeContext = new DefaultTreeContext(newRoot , tip, list, uuid, treeName, nextRevision,index,parentIndex.getParentIndex()); + TreeContext newTreeContext = new DefaultTreeContext(newRoot , tip, list, uuid, treeName, nextRevision,traverser); if (repository.compareAndSet(newTreeContext.prev(),newTreeContext)) {