Mercurial > hg > Database > jungle-sharp
diff src/main/csharp/jp.ac.u-ryukyu.ie.cr/jungle-main/transaction/DefaultTransactionManager.cs @ 10:abe0c247f5a5
Add Network module. but, unComplete NetworkDefaultJungleTreeEditor.cs
author | Kazuma Takeda <kazuma-arashi@hotmail.co.jp> |
---|---|
date | Sun, 23 Oct 2016 07:40:50 +0900 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/csharp/jp.ac.u-ryukyu.ie.cr/jungle-main/transaction/DefaultTransactionManager.cs Sun Oct 23 07:40:50 2016 +0900 @@ -0,0 +1,94 @@ +using System.Collections.Generic; +using System.Collections; +using System; + +public class DefaultTransactionManager : TransactionManager { + private AtomicReference<TreeContext> repository; + private TreeContext tip; + private ChangeListWriter writer; + private string uuid; + + + public DefaultTransactionManager(ChangeListWriter _writer, TreeContext _tip, AtomicReference<TreeContext> _repository, string _uuid) { + repository = _repository; + tip = _tip; + writer = _writer; + uuid = _uuid; + } + + public Either<Error, TransactionManager> commit(TreeNode newRoot, TreeOperationLog _log) { + long currentRevision = tip.getRevision(); + long nextRevision = currentRevision + 1; + + string _treeName = tip.getTreeName(); + // 通信時に必要? + ChangeList list = new InnerChangeList(_log, _treeName, uuid); + + InterfaceTraverser traverser = new InterfaceTraverser(newRoot, true); + // traverser.createIndex(); + TreeContext newTreeContext = new DefaultTreeContext(newRoot , tip, list, uuid, _treeName, nextRevision,traverser); + // compare and setがどういう役割か?Javaで + if (repository.CompareAndSet(newTreeContext, newTreeContext.prev())) { // CompareAndSetが成功した場合に処理を実行 + TransactionManager txManager = new DefaultTransactionManager(writer, newTreeContext, repository, uuid); + return DefaultEither<Error, TransactionManager>.newB(txManager); + } + + return DefaultEither<Error, TransactionManager>.newA((Error) new DefaultError()); + } + + public Either<Error, TransactionManager> firstcommit(TreeNode _newRoot, TreeOperationLog _log) { + return commit(_newRoot,_log); + } + + public string getUUID() { + return uuid; + } + + public long getRevision() { + return tip.getRevision(); + } + + public class InnerChangeList : ChangeList{ + + TreeOperationLog log; + string treeName; + string uuid; + + + IEnumerator IEnumerable.GetEnumerator() + { + // call the generic version of the method + return this.GetEnumerator(); + } + + public IEnumerator<TreeOperation> GetEnumerator() + { + return iterator (); + } + + + public InnerChangeList(TreeOperationLog _log, string _treeName, string _uuid){ + this.log = _log; + this.treeName = _treeName; + this.uuid = _uuid; + } + + public IEnumerator<TreeOperation> iterator() { + return log.GetEnumerator(); + } + + public string getTreeName() { + return treeName; + } + + public TreeOperationLog getLog() { + return log; + } + + public string uuids() { + return uuid; + } + } + +} + \ No newline at end of file