Mercurial > hg > Database > jungle-network
view src/alice/jungle/transaction/NetworkTransactionManager.java @ 91:2c7b3f2b2ee1
Removed serverName field
author | one |
---|---|
date | Mon, 11 Nov 2013 19:22:47 +0900 (2013-11-11) |
parents | f142dd4abc74 |
children |
line wrap: on
line source
package alice.jungle.transaction; import java.util.Iterator; 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.ChangeListWriter; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.persistent.Result; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.ChangeSet; 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; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.TreeOperation; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.transaction.AtomicReservableReference; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.transaction.AtomicReservableReference.Reservation; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.transaction.DefaultChangeSet; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.transaction.DefaultTreeContext; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.transaction.TransactionManager; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.transaction.TreeContext; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.DefaultEither; 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; public class NetworkTransactionManager<T extends TreeNode<T>> implements TransactionManager<T> { private final AtomicReservableReference<TreeContext<T>> repository; private final TreeContext<T> tip; private final ChangeListWriter writer; private final String uuid; private final String treeName; public NetworkTransactionManager(String _treeName, ChangeListWriter _writer,TreeContext<T> _tip, AtomicReservableReference<TreeContext<T>> _repository,String _uuid) { repository = _repository; tip = _tip; writer = _writer; uuid = _uuid; treeName = _treeName; } @Override public Either<Error, TransactionManager<T>> commit(T _newRoot,final TreeOperationLog _log) { ChangeSet cs = tip.getChangeSet(); long currentRevision = cs.revision(); long nextRevision = currentRevision + 1; ChangeList list = new ChangeList() { @Override 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, treeName, nextRevision); DefaultTreeContext<T> newContext = new DefaultTreeContext<T>(_newRoot,newCs); @SuppressWarnings("rawtypes") Reservation reservation = repository.makeReservation(tip, newContext); if(reservation == null) { return DefaultEither.newA((Error)new DefaultError()); } Result r = writer.write(list); if(r != Result.SUCCESS) { return DefaultEither.newA((Error)new DefaultError()); } reservation.confirm(); TransactionManager<T> txManager = new NetworkTransactionManager<T>(treeName, writer, newContext, repository, uuid); return DefaultEither.newB(txManager); } @Override public long getRevision() { ChangeSet cs = tip.getChangeSet(); return cs.revision(); } @Override public String getUUID() { return uuid; } }