Mercurial > hg > Members > nobuyasu > jungle-network
view src/alice/jungle/transaction/NetworkTransactionManager.java @ 66:29127ac788a6
move some files
author | one |
---|---|
date | Tue, 20 Aug 2013 17:38:09 +0900 |
parents | 8a532ca5df80 |
children | 89e39301ccaa |
line wrap: on
line source
package alice.jungle.transaction; import java.io.IOException; import java.util.Iterator; import alice.jungle.datasegment.store.operations.DefaultTreeOperationLogContainer; 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; import jungle.app.bbs.codesegment.LogUpdateCodeSegment; import jungle.app.bbs.codesegment.NullCodeSegmentForUpdate; 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; private final String serverName; public NetworkTransactionManager(String _treeName, ChangeListWriter _writer,TreeContext<T> _tip, AtomicReservableReference<TreeContext<T>> _repository,String _uuid, String _serverName) { repository = _repository; tip = _tip; writer = _writer; uuid = _uuid; treeName = _treeName; serverName = _serverName; } @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(); } }; Node root = _newRoot.getAsNode(); DefaultChangeSet newCs = new DefaultChangeSet(root, cs, list, uuid, 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, serverName); return DefaultEither.newB(txManager); } @Override public long getRevision() { ChangeSet cs = tip.getChangeSet(); return cs.revision(); } @Override public String getUUID() { return uuid; } }