# HG changeset patch
# User tatsuki
# Date 1486055811 -32400
# Node ID 2890ae6b1aef91d11569ecc574c53eec18e4f4b4
# Parent 766f7668521f99ce1bfc6374d9874b6b94403393
network browsing
diff -r 766f7668521f -r 2890ae6b1aef src/main/java/jp/ac/u_ryukyu/ie/cr/bbs/local/browsing/App.java
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/bbs/local/browsing/App.java Thu Feb 02 23:05:59 2017 +0900
+++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/bbs/local/browsing/App.java Fri Feb 03 02:16:51 2017 +0900
@@ -1,5 +1,6 @@
package jp.ac.u_ryukyu.ie.cr.bbs.local.browsing;
+import jp.ac.u_ryukyu.ie.cr.bbs.local.bbs.FindNodeServlet;
import jp.ac.u_ryukyu.ie.cr.jungle.DefaultJungle;
import jp.ac.u_ryukyu.ie.cr.jungle.Jungle;
import org.eclipse.jetty.server.Server;
diff -r 766f7668521f -r 2890ae6b1aef src/main/java/jp/ac/u_ryukyu/ie/cr/bbs/local/browsing/BoardMessage.java
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/bbs/local/browsing/BoardMessage.java Thu Feb 02 23:05:59 2017 +0900
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,8 +0,0 @@
-package jp.ac.u_ryukyu.ie.cr.bbs.local.browsing;
-
-public interface BoardMessage
-{
- public String getUUID();
- public String getAuthor();
- public String getMessage();
-}
diff -r 766f7668521f -r 2890ae6b1aef src/main/java/jp/ac/u_ryukyu/ie/cr/bbs/local/browsing/JungleBrowsingBulletinBoard.java
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/bbs/local/browsing/JungleBrowsingBulletinBoard.java Thu Feb 02 23:05:59 2017 +0900
+++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/bbs/local/browsing/JungleBrowsingBulletinBoard.java Fri Feb 03 02:16:51 2017 +0900
@@ -19,8 +19,7 @@
import java.nio.ByteBuffer;
import java.util.Iterator;
-public class JungleBrowsingBulletinBoard implements
- BrowsingBulletinBoard {
+public class JungleBrowsingBulletinBoard implements BrowsingBulletinBoard {
private final Jungle jungle;
public JungleBrowsingBulletinBoard() {
@@ -52,7 +51,9 @@
public void createBoards(final String _name) {
createBoards(_name, new DefaultTreeNode());
}
- public void createBoards(final String _name, TreeNode rootNode) {
+
+ public void createBoards(final String _name, TreeNode rootNode) {
+ System.out.println("create board");
if (null == jungle.createNewTree(_name, rootNode)) {
throw new IllegalStateException();
}
@@ -85,10 +86,9 @@
editor.success();
}
- public void createBoardMessage(final String boardName, final String key,
- final String attribute, final String pathStr) {
+ public void createBoardMessage(final String boardName, final String key, final String attribute, final String pathStr) {
if (key.equals("") | attribute.equals(""))
- return ;
+ return;
NodePath path = createNodePath(pathStr);
JungleTree tree = jungle.getTreeByName(boardName);
if (tree == null) {
@@ -113,22 +113,22 @@
if (tree == null) {
throw new IllegalStateException();
}
- Either getNodeEither = tree.getNodeOfPath(path);
+ Either getNodeEither = tree.getNodeOfPath(path);
if (getNodeEither.isA())
- return ;
+ return;
TreeNode currentNode = getNodeEither.b();
int childCount = currentNode.getChildren().size();
JungleTreeEditor editor;
do {
editor = tree.getJungleTreeEditor();
- Either either = editor.addNewChildAt(path, childCount);
+ Either either = editor.addNewChildAt(path, childCount);
if (either.isA()) {
throw new IllegalStateException();
}
editor = either.b();
- either = editor.putAttribute(path.add(childCount),"NodeName",ByteBuffer.wrap(nodeName.getBytes()));
+ either = editor.putAttribute(path.add(childCount), "NodeName", ByteBuffer.wrap(nodeName.getBytes()));
if (either.isA()) {
throw new IllegalStateException();
}
@@ -137,8 +137,7 @@
} while (editor.success().isA());
}
- public void editMessage(String bname, String key, final String attribute,
- final String pathStr) {
+ public void editMessage(String bname, String key, final String attribute, final String pathStr) {
NodePath path = createNodePath(pathStr);
JungleTreeEditor editor = null;
@@ -197,7 +196,7 @@
InterfaceTraverser traverser = tree.getTraverser(true);
return traverser.find((TreeNode node) -> {
return true;
- },key,value);
+ }, key, value);
}
@Override
@@ -213,7 +212,7 @@
JungleTree tree = jungle.getTreeByName(bname);
DefaultNodePath path = createNodePath(pathString);
JungleTreeEditor editor = tree.getJungleTreeEditor();
- editor = editor.moveChild(path,childNum,move).b();
+ editor = editor.moveChild(path, childNum, move).b();
return editor.success().isB();
}
diff -r 766f7668521f -r 2890ae6b1aef src/main/java/jp/ac/u_ryukyu/ie/cr/bbs/network/bbs/BulletinBoardJungleManager.java
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/bbs/network/bbs/BulletinBoardJungleManager.java Thu Feb 02 23:05:59 2017 +0900
+++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/bbs/network/bbs/BulletinBoardJungleManager.java Fri Feb 03 02:16:51 2017 +0900
@@ -69,8 +69,10 @@
tBuffer.putLong(timestamp);
do {
JungleTreeEditor editor = tree.getJungleTreeEditor();
- /*
- * Merge.
+ /*
+ * Merge.
+ * posが使われていない
+ * calculatePositionは何をしているのだろうか?
*/
int pos = calculatePosition(tree.getRootNode(), netLog.getTimeStamp());
either = JungleUpdater.edit(editor, netLog, pos);
diff -r 766f7668521f -r 2890ae6b1aef src/main/java/jp/ac/u_ryukyu/ie/cr/bbs/network/bbs/NetworkBulletinBoard.java
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/bbs/network/bbs/NetworkBulletinBoard.java Thu Feb 02 23:05:59 2017 +0900
+++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/bbs/network/bbs/NetworkBulletinBoard.java Fri Feb 03 02:16:51 2017 +0900
@@ -1,16 +1,10 @@
package jp.ac.u_ryukyu.ie.cr.bbs.network.bbs;
-import jp.ac.u_ryukyu.ie.cr.bbs.local.bbs.BulletinBoard;
+import jp.ac.u_ryukyu.ie.cr.bbs.local.browsing.BrowsingBulletinBoard;
-public interface NetworkBulletinBoard extends BulletinBoard {
+public interface NetworkBulletinBoard extends BrowsingBulletinBoard {
public void init();
public int getRequestNum();
public long getRenewTime(String boardName);
- public void createFolder(String boardName, String author, String msg, String key, String _nodeNum);
- public void createAttribute(String boardName, String uuid, String author, String msg, String key);
- public void editAttribute(String boardName, String path, String id, String message);
- public void deleteAttribute(String _board, String _path, String id);
- public void deleteNode(String _board, String _path, String id);
-
}
diff -r 766f7668521f -r 2890ae6b1aef src/main/java/jp/ac/u_ryukyu/ie/cr/bbs/network/bbs/NetworkJungleBulletinBoard.java
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/bbs/network/bbs/NetworkJungleBulletinBoard.java Thu Feb 02 23:05:59 2017 +0900
+++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/bbs/network/bbs/NetworkJungleBulletinBoard.java Fri Feb 03 02:16:51 2017 +0900
@@ -1,26 +1,12 @@
package jp.ac.u_ryukyu.ie.cr.bbs.network.bbs;
-import jp.ac.u_ryukyu.ie.cr.bbs.local.bbs.BoardMessage;
-import jp.ac.u_ryukyu.ie.cr.bbs.local.bbs.GetAttributeImp;
-import jp.ac.u_ryukyu.ie.cr.bbs.local.bbs.IterableConverter;
+import jp.ac.u_ryukyu.ie.cr.bbs.local.browsing.JungleBrowsingBulletinBoard;
import jp.ac.u_ryukyu.ie.cr.jungle.Jungle;
-import jp.ac.u_ryukyu.ie.cr.jungle.core.Children;
import jp.ac.u_ryukyu.ie.cr.jungle.persistent.ChangeList;
import jp.ac.u_ryukyu.ie.cr.jungle.persistent.ChangeListReader;
-import jp.ac.u_ryukyu.ie.cr.jungle.store.logger.LoggingNode;
-import jp.ac.u_ryukyu.ie.cr.jungle.store.logger.OperationLog;
-import jp.ac.u_ryukyu.ie.cr.jungle.store.nodepath.DefaultNodePath;
-import jp.ac.u_ryukyu.ie.cr.jungle.store.nodepath.NodePath;
-import jp.ac.u_ryukyu.ie.cr.jungle.store.trasnformer.NodeEditor;
import jp.ac.u_ryukyu.ie.cr.jungle.transaction.editor.jungleTreeEditor.JungleTreeEditor;
-import jp.ac.u_ryukyu.ie.cr.jungle.transaction.node.Default.DefaultTreeNode;
-import jp.ac.u_ryukyu.ie.cr.jungle.transaction.node.TreeNode;
-import jp.ac.u_ryukyu.ie.cr.jungle.traverser.DefaultEvaluator;
-import jp.ac.u_ryukyu.ie.cr.jungle.traverser.DefaultTraverser;
-import jp.ac.u_ryukyu.ie.cr.jungle.traverser.Traversal;
import jp.ac.u_ryukyu.ie.cr.jungle.tree.JungleTree;
-import jp.ac.u_ryukyu.ie.cr.jungle.util.DefaultEither;
import jp.ac.u_ryukyu.ie.cr.jungle.util.Either;
import jp.ac.u_ryukyu.ie.cr.jungle.util.Error.Error;
import jp.ac.u_ryukyu.ie.cr.jungleNetwork.core.NetworkDefaultJungle;
@@ -28,34 +14,37 @@
import jp.ac.u_ryukyu.ie.cr.jungleNetwork.persistent.NetworkJournal;
import jp.ac.u_ryukyu.ie.cr.jungleNetwork.persistent.PersistentJournal;
import jp.ac.u_ryukyu.ie.cr.jungleNetwork.transaction.JungleUpdater;
-import junit.framework.Assert;
import java.io.File;
import java.io.IOException;
-import java.nio.ByteBuffer;
import java.util.concurrent.atomic.AtomicInteger;
-public class NetworkJungleBulletinBoard implements NetworkBulletinBoard {
- protected final Jungle jungle;
+public class NetworkJungleBulletinBoard extends JungleBrowsingBulletinBoard implements NetworkBulletinBoard {
+ private final Jungle jungle;
private final NetworkJournal journal;
private final String LOG_DIR;
private Boolean persistentFlag;
- private AtomicInteger requestCounter;
+ private AtomicInteger requestCounter; //使われてない?
private long renewTime;
- private NetworkJungleBulletinBoard(String _uuid, NetworkJournal _journal) {
- journal = _journal;
- jungle = new NetworkDefaultJungle(journal, _uuid);
+ private NetworkJungleBulletinBoard(String _uuid, NetworkJournal journal) {
+ this(new NetworkDefaultJungle(journal, _uuid), journal);
+ }
+
+ private NetworkJungleBulletinBoard(Jungle jungle, NetworkJournal journal) {
+ super(jungle);
+ this.jungle = jungle;
+ this.journal = journal;
BulletinBoardJungleManager.setJungle(jungle);
- persistentFlag = false;
- requestCounter = BulletinBoardJungleManager.getRequestCounter();
- LOG_DIR = "./log";
- renewTime = 0;
+ this.persistentFlag = false;
+ this.requestCounter = BulletinBoardJungleManager.getRequestCounter();
+ this.LOG_DIR = "./log";
+ this.renewTime = 0;
}
public NetworkJungleBulletinBoard(String _uuid) {
this(_uuid, new AliceJournal());
- jungle.createNewTree("boards");
+ this.jungle.createNewTree("boards");
}
public static NetworkBulletinBoard NewPersistentJungle(String _uuid) {
@@ -120,632 +109,13 @@
}
}
- public Iterable getBoards() {
- JungleTree tree = jungle.getTreeByName("boards");
- TreeNode node = tree.getRootNode();
- Children chs = node.getChildren();
-
- IterableConverter.Converter converter = new IterableConverter.Converter() {
- public String conv(TreeNode _b) {
- ByteBuffer e = _b.getAttributes().get("name");
- System.out.println(new String(e.array()));
- return new String(e.array());
- }
- };
-
- return new IterableConverter(chs, converter);
- }
-
public long getRenewTime(String _boardName) {
return renewTime;
}
- public void createBoards(final String _name, final String _author, final String _initMessage, final String _editKey) {
- requestCounter.incrementAndGet();
- if (null == jungle.createNewTree(_name)) {
- throw new IllegalStateException();
- }
-
- JungleTree tree = jungle.getTreeByName("boards");
- JungleTreeEditor editor = tree.getJungleTreeEditor();
- NodePath root = new DefaultNodePath();
- Either either = editor.addNewChildAt(root, 0);
- if (either.isA()) {
- throw new IllegalStateException();
- }
- editor = either.b();
-
- either = editor.putAttribute(root.add(0), "name", ByteBuffer.wrap(_name.getBytes()));
- if (either.isA()) {
- throw new IllegalStateException();
- }
- editor = either.b();
- final long timestamp = System.currentTimeMillis();
- ByteBuffer tBuffer = ByteBuffer.allocate(16);
- tBuffer.putLong(timestamp);
- either = editor.putAttribute(root.add(0), "timestamp", tBuffer);
- if (either.isA()) {
- throw new IllegalStateException();
- }
- either = either.b().success();
- if (either.isA()) {
- throw new IllegalStateException();
- }
-
- tree = jungle.getTreeByName(_name);
- editor = tree.getJungleTreeEditor();
- either = editor.addNewChildAt(root, 0);
- if (either.isA()) {
- throw new IllegalStateException();
- }
- editor = either.b();
-
- NodeEditor e = new NodeEditor() {
- ByteBuffer tBuffer2 = ByteBuffer.allocate(16);
-
- Either _edit(LoggingNode 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();
- tBuffer2.putLong(timestamp);
- logNode = logNode.getAttributes().put("timestamp", tBuffer2).b();
- return DefaultEither.newB(logNode);
- }
-
- @Override
- public Either edit(TreeNode _e) {
- LoggingNode logNode = wrap(_e);
- return _edit(logNode);
- }
-
- private LoggingNode wrap(TreeNode node) {
- return new LoggingNode(node);
- }
-
- @Override
- public LoggingNode wrap(TreeNode newRoot, TreeNode editedNode, OperationLog operationLog) {
- return new LoggingNode(newRoot, editedNode, operationLog);
- }
-
- };
-
- either = editor.edit(root.add(0), e);
- if (either.isA()) {
- throw new IllegalStateException();
- }
- either.b().success();
-
- }
-
- public void createFolder(final String _board, final String _author, final String _message, final String _editKey, String _path) {
- JungleTree tree = jungle.getTreeByName(_board);
- if (tree == null) {
- throw new IllegalStateException();
- }
-
- DefaultNodePath path = new DefaultNodePath();
- String[] nums = _path.split(",");
- for (String num : nums) {
- if (!num.equals("-1"))
- path = path.add(Integer.parseInt(num));
- }
-
- requestCounter.incrementAndGet();
- Either either;
- final long timestamp = System.currentTimeMillis();
- final ByteBuffer tBuffer = ByteBuffer.allocate(16);
- tBuffer.putLong(timestamp);
-
- do {
- TreeNode node = tree.getRootNode();
- DefaultTraverser traverser = new DefaultTraverser();
- DefaultEvaluator evaluator = new DefaultEvaluator(path);
- Either ret = traverser.traverse(node, evaluator);
- if (ret.isA()) {
- Assert.fail();
- }
-
- Traversal traversal = ret.b();
- TreeNode target = traversal.destination();
- int size = target.getChildren().size();
- JungleTreeEditor editor = tree.getJungleTreeEditor();
- either = editor.addNewChildAt(path, size);
- if (either.isA()) {
- throw new IllegalStateException();
- }
- editor = either.b();
-
- NodeEditor e = new NodeEditor() {
-
- Either _edit(LoggingNode logNode) {
- logNode = logNode.getAttributes().put("mes", ByteBuffer.wrap(_message.getBytes())).b();
- logNode = logNode.getAttributes().put("timestamp", tBuffer).b();
- return DefaultEither.newB(logNode);
- }
-
- @Override
- public Either edit(TreeNode _e) {
- LoggingNode logNode = wrap(_e);
- return _edit(logNode);
- }
-
- private LoggingNode wrap(TreeNode node) {
- return new LoggingNode(node);
- }
-
- @Override
- public LoggingNode wrap(TreeNode newRoot, TreeNode editedNode, OperationLog operationLog) {
- return new LoggingNode(newRoot, editedNode, operationLog);
- }
-
- };
- path = path.add(size);
- either = editor.edit(path, e);
- if (either.isA()) {
- throw new IllegalStateException();
- }
- editor = either.b();
- either = editor.success();
- } while (either.isA());
-
- }
-
- public void createBoardMessage(final String _board, final String _author, final String _message, final String _editKey) {
- requestCounter.incrementAndGet();
- JungleTree tree = jungle.getTreeByName(_board);
- if (tree == null) {
- throw new IllegalStateException();
- }
-
- Either either;
- final long timestamp = System.currentTimeMillis();
- final ByteBuffer tBuffer = ByteBuffer.allocate(16);
- tBuffer.putLong(timestamp);
- do {
-
- TreeNode node = tree.getRootNode();
- int size = node.getChildren().size();
- DefaultNodePath path = new DefaultNodePath();
-
- JungleTreeEditor editor = tree.getJungleTreeEditor();
- either = editor.addNewChildAt(path, size);
- if (either.isA()) {
- throw new IllegalStateException();
- }
- editor = either.b();
-
- NodeEditor e = new NodeEditor() {
- Either _edit(LoggingNode logNode) {
- logNode = logNode.getAttributes().put("author", ByteBuffer.wrap(_author.getBytes())).b();
- logNode = logNode.getAttributes().put("mes", ByteBuffer.wrap(_message.getBytes())).b();
- logNode = logNode.getAttributes().put("key", ByteBuffer.wrap(_editKey.getBytes())).b();
- logNode = logNode.getAttributes().put("timestamp", tBuffer).b();
- return DefaultEither.newB(logNode);
- }
-
- @Override
- public Either edit(TreeNode _e) {
- LoggingNode logNode = wrap(_e);
- return _edit(logNode);
- }
-
- private LoggingNode wrap(TreeNode node) {
- return new LoggingNode(node);
- }
-
- @Override
- public LoggingNode wrap(TreeNode newRoot, TreeNode editedNode, OperationLog operationLog) {
- return new LoggingNode(newRoot, editedNode, operationLog);
- }
- };
- path = path.add(size);
- either = editor.edit(path, e);
- if (either.isA()) {
- throw new IllegalStateException();
- }
- editor = either.b();
- either = editor.success();
- } while (either.isA());
-
- }
-
- public void editMessage(String _board, String _path, final String _author, final String _message, final String _editKey) {
- requestCounter.incrementAndGet();
- final long timestamp = System.currentTimeMillis();
- final ByteBuffer tBuffer = ByteBuffer.allocate(16);
- tBuffer.putLong(timestamp);
- JungleTree tree = jungle.getTreeByName(_board);
- Either either = null;
- DefaultNodePath path = new DefaultNodePath();
- String[] nums = _path.split(",");
- for (String num : nums) {
- if (!num.equals("-1"))
- path = path.add(Integer.parseInt(num));
- }
- do {
-
- JungleTreeEditor editor = tree.getJungleTreeEditor();
- NodeEditor e = new NodeEditor() {
- Either _edit(LoggingNode logNode) {
- logNode = logNode.getAttributes().put("author", ByteBuffer.wrap(_author.getBytes())).b();
- logNode = logNode.getAttributes().put("mes", ByteBuffer.wrap(_message.getBytes())).b();
- logNode = logNode.getAttributes().put("key", ByteBuffer.wrap(_editKey.getBytes())).b();
- logNode = logNode.getAttributes().put("timestamp", tBuffer).b();
- return DefaultEither.newB(logNode);
- }
-
- @Override
- public Either edit(TreeNode _e) {
- LoggingNode logNode = wrap(_e);
- return _edit(logNode);
- }
-
- private LoggingNode wrap(TreeNode node) {
- return new LoggingNode(node);
- }
-
- @Override
- public LoggingNode wrap(TreeNode newRoot, TreeNode editedNode, OperationLog operationLog) {
- return new LoggingNode(newRoot, editedNode, operationLog);
- }
-
- };
- either = editor.edit(path, e);
- if (either.isA()) {
- throw new IllegalStateException();
- }
- editor = either.b();
- either = editor.success();
- } while (either.isA());
- renewTime = timestamp;
- }
-
- public void createAttribute(String _board, String _path, final String _author, final String _message, final String _editKey) {
- requestCounter.incrementAndGet();
- final long timestamp = System.currentTimeMillis();
- final ByteBuffer tBuffer = ByteBuffer.allocate(16);
- tBuffer.putLong(timestamp);
- JungleTree tree = jungle.getTreeByName(_board);
- Either either = null;
- DefaultNodePath path = new DefaultNodePath();
- String[] nums = _path.split(",");
- for (String num : nums) {
- if (!num.equals("-1"))
- path = path.add(Integer.parseInt(num));
- }
-
- do {
- JungleTreeEditor editor = tree.getJungleTreeEditor();
- NodeEditor e = new NodeEditor() {
- String str;
-
- Either _edit(LoggingNode logNode) { str = "0";
- int count = 0;
- for (; logNode.getAttributes().get("mes" + String.valueOf(count)) != null; count++) {
- }
- str = String.valueOf(count);
- logNode = logNode.getAttributes().put("mes" + str, ByteBuffer.wrap(_message.getBytes())).b();
- logNode = logNode.getAttributes().put("timestamp" + str, tBuffer).b();
- return DefaultEither.newB(logNode);
- }
-
- @Override
- public Either edit(TreeNode _e) {
- LoggingNode logNode = wrap(_e);
- return _edit(logNode);
- }
-
- private LoggingNode wrap(TreeNode node) {
- return new LoggingNode(node);
- }
-
- @Override
- public LoggingNode wrap(TreeNode newRoot, TreeNode editedNode, OperationLog operationLog) {
- return new LoggingNode(newRoot, editedNode, operationLog);
- }
-
- };
- either = editor.edit(path, e);
- if (either.isA()) {
- throw new IllegalStateException();
- }
- editor = either.b();
- either = editor.success();
- } while (either.isA());
- }
-
- public void editAttribute(String _bname, String _path, final String id, final String _message) {
- requestCounter.incrementAndGet();
- final long timestamp = System.currentTimeMillis();
- final ByteBuffer tBuffer = ByteBuffer.allocate(16);
- tBuffer.putLong(timestamp);
- JungleTree tree = jungle.getTreeByName(_bname);
- Either either = null;
- DefaultNodePath path = new DefaultNodePath();
- String[] nums = _path.split(",");
- for (String num : nums) {
- if (!num.equals("-1"))
- path = path.add(Integer.parseInt(num));
- }
-
- do {
- JungleTreeEditor editor = tree.getJungleTreeEditor();
- NodeEditor e = new NodeEditor() {
- Either _edit(LoggingNode logNode) {
- logNode = logNode.getAttributes().put("mes" + id, ByteBuffer.wrap(_message.getBytes())).b();
- logNode = logNode.getAttributes().put("timestamp" + id, tBuffer).b();
- return DefaultEither.newB(logNode);
- }
-
- @Override
- public Either edit(TreeNode _e) {
- LoggingNode logNode = wrap(_e);
- return _edit(logNode);
- }
-
- private LoggingNode wrap(TreeNode node) {
- return new LoggingNode(node);
- }
-
- @Override
- public LoggingNode wrap(TreeNode newRoot, TreeNode editedNode, OperationLog operationLog) {
- return new LoggingNode(newRoot, editedNode, operationLog);
- }
-
- };
- either = editor.edit(path, e);
- if (either.isA()) {
- throw new IllegalStateException();
- }
- editor = either.b();
- either = editor.success();
- } while (either.isA());
- }
-
- public void deleteNode(String _board, String _path, String _id) {
- requestCounter.incrementAndGet();
- int id = Integer.parseInt(_id);
- final long timestamp = System.currentTimeMillis();
- final ByteBuffer tBuffer = ByteBuffer.allocate(16);
- tBuffer.putLong(timestamp);
- JungleTree tree = jungle.getTreeByName(_board);
- Either either = null;
- DefaultNodePath path = new DefaultNodePath();
- String[] nums = _path.split(",");
- for (String num : nums) {
- if (!num.equals("-1"))
- path = path.add(Integer.parseInt(num));
- }
-
- do {
- JungleTreeEditor editor = tree.getJungleTreeEditor();
-
- either = editor.deleteChildAt(path, id);
- if (either.isA()) {
- throw new IllegalStateException();
- }
- editor = either.b();
- either = editor.success();
- } while (either.isA());
-
- }
-
- public void deleteAttribute(String _board, String _path, final String id) {
- requestCounter.incrementAndGet();
- final long timestamp = System.currentTimeMillis();
- final ByteBuffer tBuffer = ByteBuffer.allocate(16);
- tBuffer.putLong(timestamp);
- JungleTree tree = jungle.getTreeByName(_board);
- Either either = null;
- DefaultNodePath path = new DefaultNodePath();
- String[] nums = _path.split(",");
- for (String num : nums) {
- if (!num.equals("-1"))
- path = path.add(Integer.parseInt(num));
- }
-
- do {
- JungleTreeEditor editor = tree.getJungleTreeEditor();
- NodeEditor e = new NodeEditor() {
- Either _edit(LoggingNode logNode) {
- TreeNode node = logNode.getWrap();
- logNode = logNode.getAttributes().delete("mes" + id).b();
- logNode = logNode.getAttributes().delete("timestamp" + id).b();
- int count = Integer.parseInt(id);
- for (; logNode.getAttributes().get("mes" + String.valueOf(count + 1)) != null; ) {
- logNode = logNode.getAttributes().put("mes" + count, node.getAttributes().get("mes" + String.valueOf(count + 1))).b();
- logNode = logNode.getAttributes().put("timestamp" + count, tBuffer).b();
- count++;
- }
- if (count != Integer.parseInt(id)) {
- logNode = logNode.getAttributes().delete("timestamp" + count).b();
- logNode = logNode.getAttributes().delete("mes" + count).b();
- }
-
- return DefaultEither.newB(logNode);
- }
-
- @Override
- public Either edit(TreeNode _e) {
- LoggingNode logNode = wrap(_e);
- return _edit(logNode);
- }
-
- private LoggingNode wrap(TreeNode node) {
- return new LoggingNode(node);
- }
-
- @Override
- public LoggingNode wrap(TreeNode newRoot, TreeNode editedNode, OperationLog operationLog) {
- return new LoggingNode(newRoot, editedNode, operationLog);
- }
-
- };
- either = editor.edit(path, e);
- if (either.isA()) {
- throw new IllegalStateException();
- }
- editor = either.b();
- either = editor.success();
- } while (either.isA());
- }
-
- public void editMatrixMessage(String _board, String _uuid, final String _author, final String _message, final String _editKey) {
- requestCounter.incrementAndGet();
- final long timestamp = System.currentTimeMillis();
- final ByteBuffer tBuffer = ByteBuffer.allocate(16);
- tBuffer.putLong(timestamp);
- JungleTree tree = jungle.getTreeByName(_board);
- Either either = null;
- do {
- DefaultNodePath path = new DefaultNodePath();
- path = path.add(Integer.parseInt(_uuid));
-
- JungleTreeEditor editor = tree.getJungleTreeEditor();
- NodeEditor e = new NodeEditor() {
- Either _edit(LoggingNode logNode) {
- logNode = logNode.getAttributes().put("author", ByteBuffer.wrap(_author.getBytes())).b();
- logNode = logNode.getAttributes().put("mes", ByteBuffer.wrap(_message.getBytes())).b();
- logNode = logNode.getAttributes().put("key", ByteBuffer.wrap(_editKey.getBytes())).b();
- logNode = logNode.getAttributes().put("timestamp", tBuffer).b();
- return DefaultEither.newB(logNode);
- }
-
- @Override
- public Either edit(TreeNode _e) {
- LoggingNode logNode = wrap(_e);
- return _edit(logNode);
- }
-
- private LoggingNode wrap(TreeNode node) {
- return new LoggingNode(node);
- }
-
- @Override
- public LoggingNode wrap(TreeNode newRoot, TreeNode editedNode, OperationLog operationLog) {
- return new LoggingNode(newRoot, editedNode, operationLog);
- }
-
- };
- either = editor.edit(path, e);
- if (either.isA()) {
- throw new IllegalStateException();
- }
- editor = either.b();
- either = editor.success();
- } while (either.isA());
- renewTime = timestamp;
- }
-
- public Iterable getFolder(String _boardName, String _nodeNum) {
- DefaultNodePath path = new DefaultNodePath();
- System.out.println(_nodeNum.substring(0, 1));
- String[] nums = _nodeNum.split(",");
- for (String num : nums) {
- if (!num.equals("-1"))
- path = path.add(Integer.parseInt(num));
- }
- JungleTree tree = jungle.getTreeByName(_boardName);
- TreeNode node = tree.getRootNode();
- requestCounter.incrementAndGet();
-
- DefaultTraverser traverser = new DefaultTraverser();
- DefaultEvaluator evaluator = new DefaultEvaluator(path);
- Either ret = traverser.traverse(node, evaluator);
- if (ret.isA()) {
- Assert.fail();
- }
-
- Traversal traversal = ret.b();
- TreeNode target = traversal.destination();
- Children chs = target.getChildren();
-
- final AtomicInteger counter = new AtomicInteger(0);
- IterableConverter.Converter converter = new IterableConverter.Converter() {
- public BoardMessage conv(TreeNode _b) {
- String uuid = Integer.toString(counter.get());
- String message = new String(_b.getAttributes().get("mes").array());
- counter.incrementAndGet();
- return new BoardMessageImpl(null, message, uuid);
- }
- };
- return new IterableConverter(chs, converter);
- }
-
- public boolean compare(TreeNode compareNode, String compareAttribute) {
- String labName = compareNode.getAttributes().getString("mes");
- if (labName.equals(compareAttribute))
- return true;
-
- for (int loopCount = 0; compareNode.getAttributes().getString("mes" + loopCount) != null; loopCount++) {
- labName = compareNode.getAttributes().getString("mes" + loopCount);
- if (labName.equals(compareAttribute))
- return true;
- }
-
- return false;
- }
-
public int getRequestNum() {
return requestCounter.get();
}
- private static class BoardMessageImpl implements BoardMessage {
- private final String author;
- private final String message;
- private final String uuid;
-
- public BoardMessageImpl(String _author, String _message, String _uuid) {
- author = _author;
- message = _message;
- uuid = _uuid;
- }
-
- public String getAuthor() {
- return author;
- }
-
- public String getMessage() {
- return message;
- }
-
- public String getUUID() {
- return uuid;
- }
-
- }
-
- public String sanitize(String str) {
- if (str == null) {
- return str;
- }
- str = str.replaceAll("&", "&");
- str = str.replaceAll("<", "<");
- str = str.replaceAll(">", ">");
- str = str.replaceAll("\"", """);
- str = str.replaceAll("'", "'");
- return str;
- }
-
- public GetAttributeImp getAttribute(String _bname, String nodePath, String revisionStr) {
- DefaultNodePath path = createNodePath(nodePath);
- JungleTree tree = jungle.getTreeByName(_bname);
- Either either = tree.getNodeOfPath(path);
- if (either.isA())
- return new GetAttributeImp(new DefaultTreeNode());
- TreeNode node = either.b();
- return new GetAttributeImp(node);
- }
-
- private DefaultNodePath createNodePath(String nodePath) {
- DefaultNodePath path = new DefaultNodePath();
- String[] nums = nodePath.split(",");
- for (String num : nums) {
- if (num.equals("-1"))
- continue;
- path = path.add(Integer.parseInt(num));
- }
- return path;
- }
}
diff -r 766f7668521f -r 2890ae6b1aef src/main/java/jp/ac/u_ryukyu/ie/cr/bbs/network/bbs/ShowMessageWithTimeStampServlet.java
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/bbs/network/bbs/ShowMessageWithTimeStampServlet.java Thu Feb 02 23:05:59 2017 +0900
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,64 +0,0 @@
-package jp.ac.u_ryukyu.ie.cr.bbs.network.bbs;
-
-import jp.ac.u_ryukyu.ie.cr.bbs.local.bbs.GetAttributeImp;
-import org.eclipse.jetty.util.thread.ThreadPool;
-
-import javax.servlet.http.HttpServlet;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import java.io.PrintWriter;
-import java.util.Iterator;
-
-public class ShowMessageWithTimeStampServlet extends HttpServlet {
- /**
- *
- */
- private static final long serialVersionUID = 1L;
- private final NetworkBulletinBoard bbs;
- private final String createBoardMessagePath;
-
- private static final String PARAM_BOARD_NAME = "bname";
- private final String editMessagePath;
-
- public ShowMessageWithTimeStampServlet(NetworkBulletinBoard _bbs,
- String _createBoardMessagePath, String _editMessagePath, ThreadPool thp) {
- bbs = _bbs;
- createBoardMessagePath = _createBoardMessagePath;
- editMessagePath = _editMessagePath;
- }
-
- public void doGet(HttpServletRequest _req, HttpServletResponse _res) {
- final String bname = (_req.getParameter(PARAM_BOARD_NAME));
- try {
- _res.setCharacterEncoding("UTF-8");
- printBoard(bname, _res.getWriter());
- } catch (Exception _e) {
- _res.setStatus(500);
- }
- }
-
- private void printBoard(String _bname, PrintWriter _pw) throws Exception {
- _pw.write("\n");
- _pw.write("" + bbs.sanitize(_bname) + "
\n");
- _pw.write("Latest renew time : " + bbs.getRenewTime(_bname)
- + "
\n");
- ;
-
- _pw.write("
\n");
- _pw.write("Message
\n");
- _pw.write("\n");
-
- GetAttributeImp attribute = bbs.getAttribute(_bname, "[-1]","1");
- Iterator keys = attribute.getKeys();
-
- while (keys.hasNext()) {
- String key = keys.next();
- String mesage = attribute.getMessage(key);
- _pw.write("" + key + " = " + mesage + "
\n");
- }
- _pw.write("edit" + "
");
- _pw.write("");
- _pw.flush();
- }
-}
diff -r 766f7668521f -r 2890ae6b1aef src/main/java/jp/ac/u_ryukyu/ie/cr/bbs/network/codesegment/StartBBSCodeSegment.java
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/bbs/network/codesegment/StartBBSCodeSegment.java Thu Feb 02 23:05:59 2017 +0900
+++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/bbs/network/codesegment/StartBBSCodeSegment.java Fri Feb 03 02:16:51 2017 +0900
@@ -3,14 +3,14 @@
import alice.codesegment.CodeSegment;
import alice.datasegment.CommandType;
import alice.datasegment.Receiver;
-import jp.ac.u_ryukyu.ie.cr.bbs.local.bbs.EditMessageUseGetServlet;
+import jp.ac.u_ryukyu.ie.cr.bbs.local.bbs.FindNodeServlet;
+import jp.ac.u_ryukyu.ie.cr.bbs.local.browsing.*;
import jp.ac.u_ryukyu.ie.cr.bbs.network.bbs.NetworkBulletinBoard;
import jp.ac.u_ryukyu.ie.cr.bbs.network.bbs.NetworkJungleBulletinBoard;
import jp.ac.u_ryukyu.ie.cr.bbs.network.bbs.RequestNumCheckServlet;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.servlet.ServletHandler;
import org.eclipse.jetty.servlet.ServletHolder;
-import org.eclipse.jetty.util.thread.ThreadPool;
import javax.servlet.Servlet;
import java.util.regex.Matcher;
@@ -57,34 +57,35 @@
System.out.println("StartBBSCodeSegment");
System.out.println("name : "+ name);
+
/* Jetty registration */
String createBoardMessagePath = "/createBoardMessage";
String createBoardPath = "/createBoard";
String editMessagePath = "/editMessage";
String showBoardMessagePath = "/showBoardMessage";
-
-
- Server serv = new Server(bbsPort);
- ThreadPool thp = serv.getThreadPool();
+ String createChildPath = "/createChildMessage";
+ String findNodeMessagePath = "/findNode";
Servlet createBoardMessage = new CreateBoardMessageServlet(cassaBBS);
Servlet createBoard = new CreateBoardServlet(cassaBBS);
+ Servlet createChild = new CreateChildServlet(cassaBBS);
Servlet editBoardMessage = new EditMessageServlet(cassaBBS);
- Servlet index = new ShowBoardsServlet(cassaBBS,createBoardPath,showBoardMessagePath);
- Servlet board = new ShowBoardMessageServlet(cassaBBS,createBoardMessagePath,editMessagePath);
- //Servlet board = new ShowMessageWithTimeStampServlet(cassaBBS,createBoardMessagePath,thp);
-
+ Servlet index = new ShowBoardsServlet(cassaBBS, createBoardPath, showBoardMessagePath, findNodeMessagePath);
+ Servlet find = new FindNodeServlet(cassaBBS, showBoardMessagePath);
+ Servlet board = new ShowBoardMessageServlet(cassaBBS, createBoardMessagePath, createChildPath, editMessagePath, showBoardMessagePath);
+ Server serv = new Server(bbsPort );
ServletHandler context = new ServletHandler();
- context.addServletWithMapping(new ServletHolder(createBoardMessage),createBoardMessagePath);
- context.addServletWithMapping(new ServletHolder(createBoard),createBoardPath);
- context.addServletWithMapping(new ServletHolder(editBoardMessage),editMessagePath);
- context.addServletWithMapping(new ServletHolder(index),"/");
- context.addServletWithMapping(new ServletHolder(board),showBoardMessagePath);
- /*
- * For write benchmark
- */
- String editMessageUseGetPath = "/editMessageUseGet";
- Servlet editMessageUseGet = new EditMessageUseGetServlet(cassaBBS);
- context.addServletWithMapping(new ServletHolder(editMessageUseGet), editMessageUseGetPath);
+ context.addServletWithMapping(new ServletHolder(find), findNodeMessagePath);
+ context.addServletWithMapping(new ServletHolder(createBoardMessage), createBoardMessagePath);
+ context.addServletWithMapping(new ServletHolder(createBoard), createBoardPath);
+ context.addServletWithMapping(new ServletHolder(createChild), createChildPath);
+ context.addServletWithMapping(new ServletHolder(editBoardMessage), editMessagePath);
+ context.addServletWithMapping(new ServletHolder(index), "/");
+ context.addServletWithMapping(new ServletHolder(board), showBoardMessagePath);
+ serv.setHandler(context);
+
+
+
+ //リクエストのカウントcheckに使う? 測定用
String requestNumCheckPath = "/requestNum";
Servlet requestNumCheckServlet = new RequestNumCheckServlet(cassaBBS);
context.addServletWithMapping(new ServletHolder(requestNumCheckServlet), requestNumCheckPath);