view src/main/csharp/jp.ac.u-ryukyu.ie.cr/jungle-network/transaction/NetworkTransactionManager.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 source

using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class NetworkTransactionManager : TransactionManager {

	private readonly AtomicReference<TreeContext> Repository;
	private readonly TreeContext TContext;
	private readonly ChangeListWriter Writer;
	private readonly string Uuid;
	private readonly string TreeName;

	public NetworkTransactionManager (string name, ChangeListWriter writer, TreeContext tcon, AtomicReference<TreeContext> repo, string uid) {
		this.Repository = repo;
		this.TContext = tcon;
		this.Writer = writer;
		this.Uuid = uid;
		this.TreeName = name;
	}

	public Either<Error, TransactionManager> commit (TreeNode newRoot, TreeOperationLog log) {
		long currentRevision = this.TContext.getRevision();
		long nextRevision = currentRevision + 1;

		ChangeList list = new InnerChangeList(this.Uuid, this.TreeName);

		InterfaceTraverser traverser = new InterfaceTraverser(newRoot, true);
		// not create index.
		TreeContext newTreeContext = new DefaultTreeContext(newRoot, this.TContext, list, this.Uuid, this.TreeName, nextRevision, traverser);
		if (this.Repository.CompareAndSet(newTreeContext.prev(), newTreeContext)) {
			TransactionManager txmanager = new NetworkTransactionManager(this.TreeName, this.Writer, newTreeContext, this.Repository, this.Uuid);
			return DefaultEither<Error, TransactionManager>.newB(txmanager);
		}

		return DefaultEither<Error, TransactionManager>.newA((Error) new DefaultError());
	}

	public long getRevision () {
		return this.TContext.getRevision();
	}

	public string getUUID () {
		return this.Uuid;
	}

	public Either<Error, TransactionManager> firstcommit(TreeNode _newRoot, TreeOperationLog _log) {
		return null;
	}

	public class InnerChangeList : ChangeList {
		string uuid;
		string name;


		IEnumerator IEnumerable.GetEnumerator()
		{
			return this.GetEnumerator();
		}

		public IEnumerator<TreeOperation> GetEnumerator()
		{
			return iterator ();
		}

		// construct
		public InnerChangeList(string _uuid, string _name) {
			this.uuid = _uuid;
			this.name = _name;
		}

		public IEnumerator<TreeOperation> iterator() {
			List<TreeOperation> nil = new List<TreeOperation>();
			return nil.iterator();
		}

		public string uuids() {
			return uuid;
		}

		public string getTreeName() {
			return name;
		}

		public TreeOperationLog getLog() {
			return new DefaultTreeOperationLog();
		}
	}
}