Mercurial > hg > Members > shoshi > jungle > bbs
changeset 9:d9a9154a075e
JungleTransaction
author | suruga |
---|---|
date | Wed, 19 Jul 2017 17:15:37 +0900 |
parents | 4a66328f0141 |
children | 6e91ad317eb0 |
files | src/main/java/jp/ac/u_ryukyu/ie/cr/bbs/network/JungleTransaction.java src/main/java/jp/ac/u_ryukyu/ie/cr/bbs/network/NetworkJungleBulletinBoard.java |
diffstat | 2 files changed, 29 insertions(+), 29 deletions(-) [+] |
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/bbs/network/JungleTransaction.java Wed Jul 19 17:15:37 2017 +0900 @@ -0,0 +1,10 @@ +package jp.ac.u_ryukyu.ie.cr.bbs.network; + +import jp.ac.u_ryukyu.ie.cr.jungle.store.logger.LoggingNode; + +/** + * Created by one on 2017/07/19. + */ +public interface JungleTransaction { + LoggingNode transaction(LoggingNode logNode); +}
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/bbs/network/NetworkJungleBulletinBoard.java Wed Jul 19 16:16:17 2017 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/bbs/network/NetworkJungleBulletinBoard.java Wed Jul 19 17:15:37 2017 +0900 @@ -180,31 +180,38 @@ } editor = either.b(); + jungleTransaction(editor, root,0, timestamp, logNode -> { + logNode = logNode.getAttributes().put("author", ByteBuffer.wrap(_author.getBytes())).b(); + logNode = logNode.getAttributes().put("mes", ByteBuffer.wrap(_initMessage.getBytes())).b(); + logNode = logNode.getAttributes().put("key", ByteBuffer.wrap(_editKey.getBytes())).b(); + return logNode; + }); + } + + private Either<Error, JungleTreeEditor> jungleTransaction(JungleTreeEditor editor, DefaultNodePath path, int size, final long timestamp, JungleTransaction getLoggingNode) { + Either<Error, JungleTreeEditor> either; NodeEditor e = new NodeEditor() { - ByteBuffer tBuffer2 = ByteBuffer.allocate(16); public Either<Error, LoggingNode> edit(TreeNode node) { LoggingNode logNode = wrap(node,null, new DefaultOperationLog()); - logNode = logNode.getAttributes().put("author", ByteBuffer.wrap(_author.getBytes())).b(); - logNode = logNode.getAttributes().put("mes", ByteBuffer.wrap(_initMessage.getBytes())).b(); - logNode = logNode.getAttributes().put("key", ByteBuffer.wrap(_editKey.getBytes())).b(); + ByteBuffer tBuffer2 = ByteBuffer.allocate(16); + logNode = getLoggingNode.transaction(logNode); tBuffer2.putLong(timestamp); logNode = logNode.getAttributes().put("timestamp", tBuffer2).b(); return DefaultEither.newB(logNode); } - @Override public LoggingNode wrap(TreeNode treeNode, TreeNode treeNode1, OperationLog operationLog) { return new LoggingNode(treeNode, operationLog); } }; - either = editor.edit(root.add(0), e); + either = editor.edit(path.add(size), e); if (either.isA()) { throw new IllegalStateException(); } either.b().success(); - + return either; } public void createFolder(final String _board, final String _author, final String _message, final String _editKey, @@ -246,28 +253,11 @@ } editor = either.b(); - NodeEditor e = new NodeEditor() { - - public Either<Error, LoggingNode> edit(TreeNode node) { - LoggingNode logNode = wrap(node,null, new DefaultOperationLog()); - logNode = logNode.getAttributes().put("mes", ByteBuffer.wrap(_message.getBytes())).b(); - logNode = logNode.getAttributes().put("timestamp", tBuffer).b(); - return DefaultEither.newB(logNode); - } - - @Override - public LoggingNode wrap(TreeNode node, TreeNode node1, OperationLog op) { - return new LoggingNode(node, op); - } - - }; - path = path.add(size); - either = editor.edit(path, e); - if (either.isA()) { - throw new IllegalStateException(); - } - editor = either.b(); - either = editor.success(); + either = jungleTransaction(editor, path,size, timestamp, logNode -> { + logNode = logNode.getAttributes().put("mes", ByteBuffer.wrap(_message.getBytes())).b(); + logNode = logNode.getAttributes().put("timestamp", tBuffer).b(); + return logNode; + }); } while (either.isA()); }