Mercurial > hg > Members > shoshi > jungle > jungle-core
changeset 29:53090dc21231
added Commitment
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/impl/ChangeSetRepository.java Tue Jan 15 02:24:42 2013 +0900 @@ -0,0 +1,20 @@ +package jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl; + +import java.util.concurrent.atomic.AtomicReference; + +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.util.Commitment; + +public class ChangeSetRepository +{ + private final AtomicReference<Commitment.Value<DefaultChangeSet>> tip; + + public ChangeSetRepository() + { + tip = new AtomicReference<Commitment.Value<DefaultChangeSet>>(); + } + + public Commitment.Publisher<DefaultChangeSet> preCommit(DefaultChangeSet _changeSet) + { + + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/impl/DefaultModifiedTreeEditor.java Tue Jan 15 02:24:42 2013 +0900 @@ -0,0 +1,23 @@ +package jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl; + +import fj.data.List; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.persistent.ChangeListWriter; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.logger.Logger; + +public class DefaultModifiedTreeEditor extends DefaultTreeEditor +{ + private final List<Logger> logs; + + public DefaultModifiedTreeEditor(List<Logger> _logs,DefaultChangeSet _tip,ChangeListWriter _writer, TraverserProvider _tProvider) + { + super(_tip,_writer,_tProvider); + logs = _logs; + } + + @Override + public boolean success() + { + // commit to presistent provider + return false; + } +}
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/impl/DefaultTreeEditor.java Mon Jan 14 21:16:04 2013 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/impl/DefaultTreeEditor.java Tue Jan 15 02:24:42 2013 +0900 @@ -9,6 +9,8 @@ import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.TraversableTree; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.TreeEditor; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.TreeEditorError; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.logger.Logger; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.logger.LoggingNode; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.trasnformer.AppendChildAt; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.trasnformer.DeleteAttribute; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.trasnformer.DeleteChildAt; @@ -92,6 +94,8 @@ private Either<Error,TreeEditor> clone(Traversal<DefaultNode> _t,NodeEditor _editor) { + // copying nodes from bottom to root + List<Direction<DefaultNode>> path = List.nil(); for(Direction<DefaultNode> direction : _t){ path = path.cons(direction); @@ -99,8 +103,35 @@ // target Direction<DefaultNode> targetDirection = path.head(); - DefaultNode + LoggingNode loggingNode = (LoggingNode)_editor.edit(new LoggingNode(targetDirection.getTarget())); + Logger logger = loggingNode.getLogger(); + DefaultNode newNode = (DefaultNode)loggingNode.getWrapper(); - return null; + // top + int pos = targetDirection.getPosition(); + DefaultNode child = newNode; + for(Direction<DefaultNode> parentDirection : path.tail()){ + DefaultNode parent = parentDirection.getTarget(); + DefaultChildren chs = parent.getChildren(); + Either<Error,DefaultNode> either = chs.replaceNode(child,pos); + if(either.isA()){ + return DefaultEither.newA(either.a()); + } + + DefaultNode newParent = either.b(); + child = newParent; + pos = parentDirection.getPosition(); + } + + DefaultNode newRoot = child; + TreeEditor newEditor = new DefaultModifiedTreeEditor(logger); + return DefaultEither.newB(newEditor); + } + + protected Either<Error,TreeEditor> newEditor(Logger _logger,DefaultNode _newRoot) + { + List<Logger> logs = List.list(_logger); + TreeEditor newEditor = new DefaultModifiedTreeEditor(logs, + return DefaultEither.newB(_theB); } } \ No newline at end of file
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/impl/logger/LoggingNode.java Mon Jan 14 21:16:04 2013 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/impl/logger/LoggingNode.java Tue Jan 15 02:24:42 2013 +0900 @@ -36,4 +36,9 @@ { return log; } + + public EditableNode getWrapper() + { + return wrap; + } }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/impl/util/Commitment.java Tue Jan 15 02:24:42 2013 +0900 @@ -0,0 +1,94 @@ +package jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.util; + +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.concurrent.atomic.AtomicReference; + +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Pair; + +public final class Commitment +{ + private Commitment() + { + // + } + + public static <T> Pair<Publisher<T>,Value<T>> newInstance(T _draft,T _sub) + { + ValueWrapper<T> fail = new ValueWrapper<T>(_sub); + ValueWrapper<T> init = new ValueWrapper<T>(_sub); + ValueWrapper<T> draft = new ValueWrapper<T>(_draft); + AtomicReference<ValueWrapper<T>> value = new AtomicReference<ValueWrapper<T>>(init); + + Publisher<T> p = new Publisher<T>(value,draft,fail); + Value<T> v = new Value<T>(value,fail); + + return new Pair<Publisher<T>,Value<T>>(p,v); + } + + public static class Publisher<T> + { + private final AtomicReference<ValueWrapper<T>> value; + private final ValueWrapper<T> draft; + private final AtomicBoolean flag; + private final ValueWrapper<T> fail; + + Publisher(AtomicReference<ValueWrapper<T>> _value,ValueWrapper<T> _draft,ValueWrapper<T> _fail) + { + value = _value; + draft = _draft; + flag = new AtomicBoolean(false); + fail = _fail; + } + + public void commit() + { + if(flag.compareAndSet(true,false)){ + value.set(draft); + } + } + + public void fail() + { + if(flag.compareAndSet(true,false)){ + value.set(fail); + } + } + } + + public static class Value<T> + { + private final AtomicReference<ValueWrapper<T>> value; + private final ValueWrapper<T> fail; + + Value(AtomicReference<ValueWrapper<T>> _value,ValueWrapper<T> _fail) + { + value = _value; + fail = _fail; + } + + public T get() + { + return value.get().get(); + } + + public boolean isFail() + { + return (value.get() == fail); + } + } + + private static class ValueWrapper<T> + { + private final T object; + + public ValueWrapper(T _object) + { + object = _object; + } + + public T get() + { + return object; + } + } +}
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/trasnformer/AppendChildAt.java Mon Jan 14 21:16:04 2013 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/trasnformer/AppendChildAt.java Tue Jan 15 02:24:42 2013 +0900 @@ -4,7 +4,7 @@ import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Either; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Error; -public class AppendChildAt<T extends EditableNode> implements NodeEditor<T> +public class AppendChildAt implements NodeEditor { private final int pos; @@ -14,9 +14,9 @@ } @Override - public Either<Error,T> edit(T _e) + public Either<Error,EditableNode> edit(EditableNode _e) { - Either<Error,T> either = _e.getChildren().addNewChildAt(pos); + Either<Error,EditableNode> either = _e.getChildren().addNewChildAt(pos); if(either.isA()){ // error return either;
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/trasnformer/NodeEditor.java Mon Jan 14 21:16:04 2013 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/trasnformer/NodeEditor.java Tue Jan 15 02:24:42 2013 +0900 @@ -3,7 +3,7 @@ import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Either; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Error; -public interface NodeEditor<T extends EditableNode> +public interface NodeEditor { - public Either<Error,T> edit(T _e); + public Either<Error,EditableNode> edit(EditableNode _e); }