Mercurial > hg > Members > shoshi > jungle > jungle-core
changeset 223:f0cc848b9af6
merge jungle-network but test faild
line wrap: on
line diff
--- a/build.gradle Tue Sep 15 02:03:04 2015 +0900 +++ b/build.gradle Tue Sep 15 17:31:19 2015 +0900 @@ -1,5 +1,4 @@ apply plugin: "java" -apply plugin: "eclipse" sourceCompatibility = 1.8 targetCompatibility = 1.8 @@ -8,6 +7,8 @@ repositories { mavenCentral() + maven { url "http://eaio.com/maven2" } + maven { url "http://repo.maven.apache.org/maven2" } } dependencies { @@ -18,12 +19,13 @@ compile fileTree(dir: 'lib', include: '*.jar') compile "junit:junit:4.7" compile group: 'org.eclipse.jetty', name: 'jetty-server', version:'9.1.1.v20140108' + compile group: 'org.eclipse.jetty', name: 'jetty-servlet', version:'9.2.1.v20140609' compile group: 'org.hectorclient', name: 'hector-core', version:'1.1-2' + compile group: 'com.github.stephenc.eaio-uuid', name: 'uuid', version:'3.3.0' compile(group: 'org.apache.cassandra', name: 'cassandra-all', version:'1.2.1') { exclude(module: 'slf4j-log4j12') exclude(module: 'log4j') } - compile group: 'com.eaio.uuid', name: 'uuid', version:'3.3' }
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/test/TreeMapBenchMark.java Tue Sep 15 02:03:04 2015 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/test/TreeMapBenchMark.java Tue Sep 15 17:31:19 2015 +0900 @@ -40,7 +40,7 @@ } break; } - case "tatsuki": { + case "data": { TreeMap<Long,String> map = new TreeMap<>(); for (long count = 0; count < 1000; count++) { map = map.put(count, String.valueOf(count));
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungleNetwork/bbs/BoardRenewTime.java Tue Sep 15 17:31:19 2015 +0900 @@ -0,0 +1,8 @@ +package jp.ac.u_ryukyu.ie.cr.jungleNetwork.bbs; + +public interface BoardRenewTime { + + public String getboardName(); + public Long getRenewTime(); + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungleNetwork/bbs/BulletinBoardJungleManager.java Tue Sep 15 17:31:19 2015 +0900 @@ -0,0 +1,109 @@ +package jp.ac.u_ryukyu.ie.cr.jungleNetwork.bbs; + + +import jp.ac.u_ryukyu.ie.cr.jungle.DefaultJungle; +import jp.ac.u_ryukyu.ie.cr.jungle.Jungle; +import jp.ac.u_ryukyu.ie.cr.jungle.JungleTree; +import jp.ac.u_ryukyu.ie.cr.jungle.JungleTreeEditor; +import jp.ac.u_ryukyu.ie.cr.jungle.store.impl.DefaultNodePath; +import jp.ac.u_ryukyu.ie.cr.jungle.store.impl.DefaultTreeEditor; +import jp.ac.u_ryukyu.ie.cr.jungle.store.impl.TreeNode; +import jp.ac.u_ryukyu.ie.cr.jungle.traverser.DefaultTraverser; +import jp.ac.u_ryukyu.ie.cr.jungle.util.Either; +import jp.ac.u_ryukyu.ie.cr.jungle.util.Error; +import jp.ac.u_ryukyu.ie.cr.jungleNetwork.operations.NetworkTreeOperationLog; +import jp.ac.u_ryukyu.ie.cr.jungleNetwork.transaction.JungleUpdater; + +import java.nio.ByteBuffer; +import java.util.concurrent.atomic.AtomicInteger; + +public class BulletinBoardJungleManager { + private static BulletinBoardJungleManager instance = new BulletinBoardJungleManager(); + private Jungle jungle; + private static AtomicInteger requestCounter = new AtomicInteger(0); + + private BulletinBoardJungleManager() { + jungle = new DefaultJungle(null,"default",new DefaultTreeEditor(new DefaultTraverser())); + } + + public static int requestGetAndIncrement() { + return requestCounter.getAndIncrement(); + } + + public static int requestIncrementAndGet() { + return requestCounter.incrementAndGet(); + } + + public static BulletinBoardJungleManager getInstantce() { + return instance; + } + + public static void setJungle(Jungle _j) { + instance.jungle = _j; + } + public static AtomicInteger getRequestCounter() { + return requestCounter; + } + + public static Jungle getJungle() { + return instance.jungle; + } + + public static JungleTree createNewTree(String name) { + return instance.jungle.createNewTree(name); + } + + public static Either<Error, JungleTreeEditor> update(NetworkTreeOperationLog netLog) { + String treeName = netLog.getTreeName(); + Jungle jungle = BulletinBoardJungleManager.getJungle(); + if (jungle.getTreeByName(treeName) == null) { + if(null == jungle.createNewTree(treeName)){ + throw new IllegalStateException(); + } + } + Either<Error, JungleTreeEditor> either = null; + JungleTree tree = jungle.getTreeByName(treeName); + + long timestamp = System.currentTimeMillis(); + ByteBuffer tBuffer = ByteBuffer.allocate(16); + DefaultNodePath root = new DefaultNodePath(); + tBuffer.putLong(timestamp); + do { + JungleTreeEditor editor = tree.getLocalTreeEditor(); + /* + * Merge. + */ + int pos = calculatePosition(tree.getRootNode(), netLog.getTimeStamp()); + either = JungleUpdater.edit(editor, netLog, pos); + if(either.isA()) { + throw new IllegalStateException(); + } + editor = either.b(); + either = editor.putAttribute(root, "renewtime", tBuffer); + if(either.isA()) { + throw new IllegalStateException(); + } + editor = either.b(); + either = editor.success(); + }while(either.isA()); + requestIncrementAndGet(); + return either; + } + + private static int calculatePosition(TreeNode node, long newNodeTimeStamp) { + int count = 0; + long childTimeStamp = 0; + for(TreeNode n : node.getChildren()) { + ByteBuffer timestamp = n.getAttributes().get("timestamp"); + if(timestamp == null) { + return count; + } + childTimeStamp = timestamp.getLong(0); + if (newNodeTimeStamp < childTimeStamp) { + break; + } + count++; + } + return count; + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungleNetwork/bbs/DistributeApp.java Tue Sep 15 17:31:19 2015 +0900 @@ -0,0 +1,20 @@ +package jp.ac.u_ryukyu.ie.cr.jungleNetwork.bbs; + +import alice.topology.node.TopologyNode; +import jp.ac.u_ryukyu.ie.cr.jungleNetwork.bbs.codesegment.StartBBSCodeSegment; +import jp.ac.u_ryukyu.ie.cr.jungleNetwork.remote.RemoteConfig; + +public class DistributeApp { + public static void main(String[] args) throws Exception { + RemoteConfig conf = new RemoteConfig(args); + System.out.println("test"); + if (conf.getManagerHostName() == null) { + // String localHostName ="localhost"; + // HostMessage host = new HostMessage(localHostName, conf.localPort); + StartBBSCodeSegment cs1 = new StartBBSCodeSegment(args, conf.bbsPort); + cs1.ods.put("host", "node0"); + } else { + new TopologyNode(conf, new StartBBSCodeSegment(args, conf.bbsPort)); + } + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungleNetwork/bbs/NetworkBulletinBoard.java Tue Sep 15 17:31:19 2015 +0900 @@ -0,0 +1,16 @@ +package jp.ac.u_ryukyu.ie.cr.jungleNetwork.bbs; + + +import jp.ac.u_ryukyu.ie.cr.jungle.bbs.BulletinBoard; + +public interface NetworkBulletinBoard extends BulletinBoard { + 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); + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungleNetwork/bbs/NetworkJungleBulletinBoard.java Tue Sep 15 17:31:19 2015 +0900 @@ -0,0 +1,706 @@ +package jp.ac.u_ryukyu.ie.cr.jungleNetwork.bbs; + + +import jp.ac.u_ryukyu.ie.cr.jungle.Jungle; +import jp.ac.u_ryukyu.ie.cr.jungle.JungleTree; +import jp.ac.u_ryukyu.ie.cr.jungle.JungleTreeEditor; +import jp.ac.u_ryukyu.ie.cr.jungle.bbs.BoardMessage; +import jp.ac.u_ryukyu.ie.cr.jungle.bbs.GetAttributeImp; +import jp.ac.u_ryukyu.ie.cr.jungle.bbs.IterableConverter; +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.impl.DefaultNodePath; +import jp.ac.u_ryukyu.ie.cr.jungle.store.impl.DefaultTreeEditor; +import jp.ac.u_ryukyu.ie.cr.jungle.store.impl.TreeNode; +import jp.ac.u_ryukyu.ie.cr.jungle.store.impl.logger.DefaultOperationLog; +import jp.ac.u_ryukyu.ie.cr.jungle.store.impl.logger.LoggingNode; +import jp.ac.u_ryukyu.ie.cr.jungle.store.impl.logger.OperationLog; +import jp.ac.u_ryukyu.ie.cr.jungle.store.trasnformer.NodeEditor; +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.util.DefaultEither; +import jp.ac.u_ryukyu.ie.cr.jungle.util.Either; +import jp.ac.u_ryukyu.ie.cr.jungle.util.Error; +import jp.ac.u_ryukyu.ie.cr.jungleNetwork.core.NetworkDefaultJungle; +import jp.ac.u_ryukyu.ie.cr.jungleNetwork.persistent.AliceJournal; +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; + private final NetworkJournal journal; + private final String LOG_DIR; + private Boolean persistentFlag; + private AtomicInteger requestCounter; + private long renewTime; + + private NetworkJungleBulletinBoard(String _uuid, NetworkJournal _journal) { + journal = _journal; + jungle = new NetworkDefaultJungle(journal, _uuid, new DefaultTreeEditor(new DefaultTraverser())); + BulletinBoardJungleManager.setJungle(jungle); + persistentFlag = false; + requestCounter = BulletinBoardJungleManager.getRequestCounter(); + LOG_DIR = "./log"; + renewTime = 0; + } + + public NetworkJungleBulletinBoard(String _uuid) { + this(_uuid, new AliceJournal()); + jungle.createNewTree("boards"); + } + + public static NetworkBulletinBoard NewPersistentJungle(String _uuid) { + NetworkJungleBulletinBoard board = new NetworkJungleBulletinBoard(_uuid, new PersistentJournal()); + board.persistentFlag = true; + return board; + } + + public void init() { + if (!persistentFlag) { + return; + } + checkAndCreateLogDirectory(); + try { + commitLogRecover(); + } catch (IOException e) { + e.printStackTrace(); + } + } + + public void checkAndCreateLogDirectory() { + File logFile = new File(LOG_DIR); + if (!logFile.exists()) { + logFile.mkdir(); + return; + } + if (logFile.isFile()) { + logFile.delete(); + logFile.mkdir(); + } + } + + public void commitLogRecover() throws IOException { + File[] logFiles = new File(LOG_DIR).listFiles(); + for (File logFile : logFiles) { + commitLogRecover(logFile); + logFile.delete(); + } + if (jungle.getTreeByName("boards") == null) { + jungle.createNewTree("boards"); + } + } + + private void commitLogRecover(File logFile) throws IOException { + journal.setInputFile(logFile); + ChangeListReader reader = journal.getReader(); + if (reader == null) + return; + for (ChangeList chList : reader) { + String treeName = chList.getTreeName(); + JungleTree tree = jungle.getTreeByName(treeName); + if (tree == null) { + tree = jungle.createNewTree(treeName); + } + JungleTreeEditor editor = tree.getLocalTreeEditor(); + Either<Error, JungleTreeEditor> either = JungleUpdater.edit(editor, chList); + editor = either.b(); + if (either.isA()) { + throw new IOException("Failed commit log recovery"); + } + editor.success(); + } + } + + public Iterable<String> getBoards() { + JungleTree tree = jungle.getTreeByName("boards"); + TreeNode node = tree.getRootNode(); + Children chs = node.getChildren(); + + IterableConverter.Converter<String, TreeNode> converter = new IterableConverter.Converter<String, TreeNode>() { + 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<String, TreeNode>(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.getTreeEditor(); + DefaultNodePath root = new DefaultNodePath(); + Either<Error, JungleTreeEditor> 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.getTreeEditor(); + either = editor.addNewChildAt(root, 0); + if (either.isA()) { + throw new IllegalStateException(); + } + editor = either.b(); + + NodeEditor e = new NodeEditor() { + ByteBuffer tBuffer2 = ByteBuffer.allocate(16); + + public Either<Error, LoggingNode> edit(TreeNode node) { + LoggingNode logNode = wrap(node, 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(); + tBuffer2.putLong(timestamp); + logNode = logNode.getAttributes().put("timestamp", tBuffer2).b(); + return DefaultEither.newB(logNode); + } + + @Override + public LoggingNode wrap(TreeNode node, OperationLog op) { + return new LoggingNode(node, op); + } + }; + + 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 _nodeNum) { + JungleTree tree = jungle.getTreeByName(_board); + if (tree == null) { + throw new IllegalStateException(); + } + + DefaultNodePath path = new DefaultNodePath(); + try { + for (int count = 0; _nodeNum.substring(count, count + 1) != null; count++) { + if (!_nodeNum.substring(count, count + 1).equals("/")) + path = path.add(Integer.parseInt(_nodeNum.substring(count, count + 1))); + } + } catch (Exception _e) { + } + requestCounter.incrementAndGet(); + Either<Error, JungleTreeEditor> 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<Error, Traversal> 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.getTreeEditor(); + either = editor.addNewChildAt(path, size); + if (either.isA()) { + throw new IllegalStateException(); + } + editor = either.b(); + + NodeEditor e = new NodeEditor() { + + public Either<Error, LoggingNode> edit(TreeNode node) { + LoggingNode logNode = wrap(node, 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, 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(); + } 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<Error, JungleTreeEditor> 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.getTreeEditor(); + either = editor.addNewChildAt(path, size); + if (either.isA()) { + throw new IllegalStateException(); + } + editor = either.b(); + + NodeEditor e = new NodeEditor() { + public Either<Error, LoggingNode> edit(TreeNode node) { + LoggingNode logNode = wrap(node, new DefaultOperationLog()); + 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 LoggingNode wrap(TreeNode node, 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(); + } while (either.isA()); + + } + + public void editMessage(String _board, String _nodeNum, 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<Error, JungleTreeEditor> either = null; + + do { + DefaultNodePath path = new DefaultNodePath(); + try { + for (int count = 0; _nodeNum.substring(count, count + 1) != null; count++) { + if (!_nodeNum.substring(count, count + 1).equals("/")) + path = path.add(Integer.parseInt(_nodeNum.substring(count, count + 1))); + } + } catch (Exception _e) { + } + JungleTreeEditor editor = tree.getTreeEditor(); + NodeEditor e = new NodeEditor() { + public Either<Error, LoggingNode> edit(TreeNode node) { + LoggingNode logNode = wrap(node, new DefaultOperationLog()); + System.out.println(new String(node.getAttributes().get("mes").array())); + 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(); + System.out.println(new String(node.getAttributes().get("mes").array())); + return DefaultEither.newB(logNode); + } + + @Override + public LoggingNode wrap(TreeNode node, OperationLog op) { + return new LoggingNode(node, op); + } + }; + 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 _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<Error, JungleTreeEditor> either = null; + DefaultNodePath path = new DefaultNodePath(); + do { + try { + for (int count = 0; _uuid.substring(count, count + 1) != null; count++) { + if (!_uuid.substring(count, count + 1).equals("/")) + path = path.add(Integer.parseInt(_uuid.substring(count, count + 1))); + } + } catch (Exception _e) { + } + + JungleTreeEditor editor = tree.getTreeEditor(); + NodeEditor e = new NodeEditor() { + String str; + + public Either<Error, LoggingNode> edit(TreeNode node) { + LoggingNode logNode = wrap(node, new DefaultOperationLog()); + 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 LoggingNode wrap(TreeNode node, OperationLog op) { + return new LoggingNode(node, op); + } + }; + either = editor.edit(path, e); + if (either.isA()) { + throw new IllegalStateException(); + } + editor = either.b(); + either = editor.success(); + } while (either.isA()); + } + + public void editAttribute(String boardName, 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(boardName); + Either<Error, JungleTreeEditor> either = null; + DefaultNodePath path = new DefaultNodePath(); + do { + try { + for (int count = 0; _path.substring(count, count + 1) != null; count++) { + if (!_path.substring(count, count + 1).equals("/")) + path = path.add(Integer.parseInt(_path.substring(count, count + 1))); + } + } catch (Exception _e) { + } + + JungleTreeEditor editor = tree.getTreeEditor(); + NodeEditor e = new NodeEditor() { + public Either<Error, LoggingNode> edit(TreeNode node) { + LoggingNode logNode = wrap(node, new DefaultOperationLog()); + // EnableNodeWrapper<T> node = _e.getWrap(); + 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 LoggingNode wrap(TreeNode node, OperationLog op) { + return new LoggingNode(node, op); + } + }; + 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<Error, JungleTreeEditor> either = null; + DefaultNodePath path = new DefaultNodePath(); + do { + try { + for (int count = 0; _path.substring(count, count + 1) != null; count++) { + if (!_path.substring(count, count + 1).equals("/")) + path = path.add(Integer.parseInt(_path.substring(count, count + 1))); + } + } catch (Exception _e) { + } + + JungleTreeEditor editor = tree.getTreeEditor(); + + 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<Error, JungleTreeEditor> either = null; + DefaultNodePath path = new DefaultNodePath(); + do { + try { + for (int count = 0; _path.substring(count, count + 1) != null; count++) { + if (!_path.substring(count, count + 1).equals("/")) + path = path.add(Integer.parseInt(_path.substring(count, count + 1))); + } + } catch (Exception _e) { + System.out.println("屑"); + } + + JungleTreeEditor editor = tree.getTreeEditor(); + NodeEditor e = new NodeEditor() { + public Either<Error, LoggingNode> edit(TreeNode node) { + LoggingNode logNode = wrap(node, new DefaultOperationLog()); + 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 LoggingNode wrap(TreeNode node, OperationLog op) { + return new LoggingNode(node, op); + } + }; + 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<Error, JungleTreeEditor> either = null; + do { + DefaultNodePath path = new DefaultNodePath(); + path = path.add(Integer.parseInt(_uuid)); + + JungleTreeEditor editor = tree.getTreeEditor(); + NodeEditor e = new NodeEditor() { + public Either<Error, LoggingNode> edit(TreeNode node) { + LoggingNode logNode = wrap(node, new DefaultOperationLog()); + 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 LoggingNode wrap(TreeNode node, OperationLog op) { + return new LoggingNode(node, op); + } + }; + either = editor.edit(path, e); + if (either.isA()) { + throw new IllegalStateException(); + } + editor = either.b(); + either = editor.success(); + } while (either.isA()); + renewTime = timestamp; + } + + public Iterable<BoardMessage> getFolder(String _boardName, String _nodeNum) { + + DefaultNodePath path = new DefaultNodePath(); + try { + for (int count = 0; _nodeNum.substring(count, count + 1) != null; count++) { + if (!_nodeNum.substring(count, count + 1).equals("/")) + path = path.add(Integer.parseInt(_nodeNum.substring(count, count + 1))); + } + } catch (Exception _e) { + } + requestCounter.incrementAndGet(); + JungleTree tree = jungle.getTreeByName(_boardName); + TreeNode node = tree.getRootNode(); + + DefaultTraverser traverser = new DefaultTraverser(); + // TraversableNodeWrapper<Node> traversable = new + // TraversableNodeWrapper<Node>(node); + DefaultEvaluator evaluator = new DefaultEvaluator(path); + Either<Error, Traversal> 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<BoardMessage, TreeNode> converter = new IterableConverter.Converter<BoardMessage, TreeNode>() { + 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<BoardMessage, TreeNode>(chs, converter); + } + + public boolean compare(TreeNode compareNode, String compareAttribute) { + String labName = compareNode.getAttributes().getString("mes"); + if (labName.equals(compareAttribute)) + return true; + + int loopCount = 0; + for (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; + } + + @Override + public GetAttributeImp getAttribute(String _bname, String _nodeNum, String revisionStr) { + + DefaultNodePath path = new DefaultNodePath(); + try { + for (int count = 0; _nodeNum.substring(count, count + 1) != null; count++) { + if (!_nodeNum.substring(count, count + 1).equals("/")) + path = path.add(Integer.parseInt(_nodeNum.substring(count, count + 1))); + } + } catch (Exception _e) { + } + JungleTree tree = jungle.getTreeByName(_bname); + System.out.println(tree.revision()); + Long revision = Long.parseLong(revisionStr); + JungleTree oldTree = tree.getOldTree(revision).b(); + System.out.println(oldTree.revision()); + TreeNode node = oldTree.getRootNode(); + + DefaultTraverser traverser = new DefaultTraverser(); + DefaultEvaluator evaluator = new DefaultEvaluator(path); + Either<Error, Traversal> ret = traverser.traverse(node, evaluator); + if (ret.isA()) { + Assert.fail(); + } + + Traversal traversal = ret.b(); + TreeNode target = traversal.destination(); + return new GetAttributeImp(target); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungleNetwork/bbs/RequestNumCheckServlet.java Tue Sep 15 17:31:19 2015 +0900 @@ -0,0 +1,34 @@ +package jp.ac.u_ryukyu.ie.cr.jungleNetwork.bbs; + +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.PrintWriter; + + +public class RequestNumCheckServlet extends HttpServlet +{ + private final NetworkBulletinBoard bbs; + private static final long serialVersionUID = 1L; + + public RequestNumCheckServlet(NetworkBulletinBoard _bbs) + { + bbs = _bbs; + } + + public void doGet(HttpServletRequest _req,HttpServletResponse _res) + { + int num = bbs.getRequestNum(); + + try{ + PrintWriter pw = _res.getWriter(); + pw.write(Integer.toString(num)); + pw.flush(); + }catch(Exception _e){ + _res.setStatus(500); + } + + + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungleNetwork/bbs/ShowMessageWithTimeStampServlet.java Tue Sep 15 17:31:19 2015 +0900 @@ -0,0 +1,62 @@ +package jp.ac.u_ryukyu.ie.cr.jungleNetwork.bbs; + +import jp.ac.u_ryukyu.ie.cr.jungle.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"; + + public ShowMessageWithTimeStampServlet(NetworkBulletinBoard _bbs, + String _createBoardMessagePath, ThreadPool thp) { + bbs = _bbs; + createBoardMessagePath = _createBoardMessagePath; + } + + 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("<html><body>\n"); + _pw.write("<h1>" + bbs.sanitize(_bname) + "</h1>\n"); + _pw.write("<p>Latest renew time : " + bbs.getRenewTime(_bname) + + "</p>\n"); + ; + + _pw.write("<form action='" + createBoardMessagePath + "' method='POST'\n"); + _pw.write("<p>Author : <input type='text' name='author'/> <input type='hidden' name='bname' value='" +bbs.sanitize( _bname) + "'/> EditKey : <input type='textarea' name='key'/></p>\n"); + _pw.write("<p>Message<br/> <input type='textarea' name='msg'/> </p>\n"); + _pw.write("<p><input type='submit' value='submit'/></p>\n"); + + GetAttributeImp attribute = bbs.getAttribute(_bname, "[-1]","0"); + Iterator<String> keys = attribute.getKeys(); + + while(keys.hasNext()){ + String key = keys.next(); + String mesage = attribute.getMessage(key); + _pw.write("<p>" + key + " = " + mesage + "</p>\n"); + } + + _pw.write("</body></html>"); + _pw.flush(); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungleNetwork/bbs/codesegment/LogPutCodeSegment.java Tue Sep 15 17:31:19 2015 +0900 @@ -0,0 +1,20 @@ +package jp.ac.u_ryukyu.ie.cr.jungleNetwork.bbs.codesegment; + +import alice.codesegment.CodeSegment; +import jp.ac.u_ryukyu.ie.cr.jungleNetwork.operations.NetworkTreeOperationLog; + + +public class LogPutCodeSegment extends CodeSegment{ + + NetworkTreeOperationLog log; + + public LogPutCodeSegment(NetworkTreeOperationLog _log) { + log = _log; + } + + @Override + public void run() { + ods.put("log", log); + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungleNetwork/bbs/codesegment/LogUpdateCodeSegment.java Tue Sep 15 17:31:19 2015 +0900 @@ -0,0 +1,48 @@ +package jp.ac.u_ryukyu.ie.cr.jungleNetwork.bbs.codesegment; + +import alice.codesegment.CodeSegment; +import alice.datasegment.CommandType; +import alice.datasegment.Receiver; +import jp.ac.u_ryukyu.ie.cr.jungle.JungleTreeEditor; +import jp.ac.u_ryukyu.ie.cr.jungle.util.Either; +import jp.ac.u_ryukyu.ie.cr.jungle.util.Error; +import jp.ac.u_ryukyu.ie.cr.jungleNetwork.bbs.BulletinBoardJungleManager; +import jp.ac.u_ryukyu.ie.cr.jungleNetwork.operations.NetworkTreeOperationLog; + +import java.util.List; + +public class LogUpdateCodeSegment extends CodeSegment { + + Receiver log = ids.create(CommandType.TAKE); + Receiver clist = ids.create(CommandType.PEEK); + + public LogUpdateCodeSegment() { + log.setKey("log"); + clist.setKey("_CLIST");; + } + + public LogUpdateCodeSegment(int index) { + log.setKey("log", index); + clist.setKey("_CLIST");; + } + + public void run() { + int index = log.index; + new LogUpdateCodeSegment(); + NetworkTreeOperationLog netLog = log.asClass(NetworkTreeOperationLog.class); + @SuppressWarnings("unchecked") + List<String> list = clist.asClass(List.class); + for (String node : list) { + if (!node.equals(log.from)) { + ods.put(node, log.key, log.getVal()); + } + } + if (!log.from.equals("local")) { + Either<Error, JungleTreeEditor> either = BulletinBoardJungleManager.update(netLog); + if(either.isA()) { + new LogUpdateCodeSegment(index); + throw new IllegalStateException(); + } + } + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungleNetwork/bbs/codesegment/StartBBSCodeSegment.java Tue Sep 15 17:31:19 2015 +0900 @@ -0,0 +1,101 @@ +package jp.ac.u_ryukyu.ie.cr.jungleNetwork.bbs.codesegment; + +import alice.codesegment.CodeSegment; +import alice.datasegment.CommandType; +import alice.datasegment.Receiver; +import jp.ac.u_ryukyu.ie.cr.jungle.bbs.*; +import jp.ac.u_ryukyu.ie.cr.jungleNetwork.bbs.NetworkBulletinBoard; +import jp.ac.u_ryukyu.ie.cr.jungleNetwork.bbs.NetworkJungleBulletinBoard; +import jp.ac.u_ryukyu.ie.cr.jungleNetwork.bbs.RequestNumCheckServlet; +import jp.ac.u_ryukyu.ie.cr.jungleNetwork.bbs.ShowMessageWithTimeStampServlet; +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; +import java.util.regex.Pattern; + +public class StartBBSCodeSegment extends CodeSegment { + + int bbsPort = 8080; + Receiver host = ids.create(CommandType.PEEK); + private Pattern pattern = Pattern.compile("^(node|cli)([0-9]+)$"); + private String[] args; + boolean persistentFlag = false; + + public StartBBSCodeSegment(String[] _args, int p) { + args = _args; + bbsPort = p; + host.setKey("host"); + } + + public StartBBSCodeSegment() { + args = null; + host.setKey("host"); + } + + @Override + public void run() { + String name = host.asString(); + Matcher matcher = pattern.matcher(name); + matcher.find(); + // String type = matcher.group(1); + for(String arg: args) { + if(arg.equals("-persistent")){ + persistentFlag = true; + } + } + NetworkBulletinBoard cassaBBS = null; + if(persistentFlag) { + System.out.println("log loading..."); + cassaBBS = NetworkJungleBulletinBoard.NewPersistentJungle(name); + cassaBBS.init(); + } else { + cassaBBS = new NetworkJungleBulletinBoard(name); + cassaBBS.init(); + } + + 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(); + Servlet createBoardMessage = new CreateBoardMessageServlet(cassaBBS); + Servlet createBoard = new CreateBoardServlet(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); + + 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); + String requestNumCheckPath = "/requestNum"; + Servlet requestNumCheckServlet = new RequestNumCheckServlet(cassaBBS); + context.addServletWithMapping(new ServletHolder(requestNumCheckServlet), requestNumCheckPath); + + serv.setHandler(context); + try { + serv.start(); + } catch (Exception e) { } + new LogUpdateCodeSegment(); + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungleNetwork/bbs/io/NullOutputStream.java Tue Sep 15 17:31:19 2015 +0900 @@ -0,0 +1,15 @@ +package jp.ac.u_ryukyu.ie.cr.jungleNetwork.bbs.io; + +import java.io.IOException; +import java.io.OutputStream; + +public class NullOutputStream extends OutputStream { + + public NullOutputStream() { + } + + @Override + public void write(int arg0) throws IOException { + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungleNetwork/core/NetworkDefaultJungle.java Tue Sep 15 17:31:19 2015 +0900 @@ -0,0 +1,67 @@ +package jp.ac.u_ryukyu.ie.cr.jungleNetwork.core; + + +import jp.ac.u_ryukyu.ie.cr.jungle.Jungle; +import jp.ac.u_ryukyu.ie.cr.jungle.JungleTree; +import jp.ac.u_ryukyu.ie.cr.jungle.data.list.List; +import jp.ac.u_ryukyu.ie.cr.jungle.persistent.ChangeList; +import jp.ac.u_ryukyu.ie.cr.jungle.persistent.Journal; +import jp.ac.u_ryukyu.ie.cr.jungle.store.TreeContext; +import jp.ac.u_ryukyu.ie.cr.jungle.store.TreeEditor; +import jp.ac.u_ryukyu.ie.cr.jungle.store.impl.TreeNode; +import jp.ac.u_ryukyu.ie.cr.jungle.store.operations.TreeOperation; +import jp.ac.u_ryukyu.ie.cr.jungle.transaction.DefaultTreeContext; +import jp.ac.u_ryukyu.ie.cr.jungle.transaction.DefaultTreeNode; +import jp.ac.u_ryukyu.ie.cr.jungle.traverser.InterfaceTraverser; +import jp.ac.u_ryukyu.ie.cr.jungleNetwork.transaction.NetworkDefaultJungleTree; + +import java.util.Iterator; +import java.util.concurrent.ConcurrentHashMap; + +public class NetworkDefaultJungle implements Jungle { + private Journal journal; + private ConcurrentHashMap<String, JungleTree> trees; + private String uuid; + private TreeEditor editor; + + public NetworkDefaultJungle(Journal _journal, String _uuid, TreeEditor _editor) { + journal = _journal; + trees = new ConcurrentHashMap<String, JungleTree>(); + uuid = _uuid; + editor = _editor; + } + + @Override + public JungleTree getTreeByName(String _name) { + return trees.get(_name); + } + + @Override + public JungleTree createNewTree(final String name) { + ChangeList list = new ChangeList() { + @Override + public Iterator<TreeOperation> iterator() { + List<TreeOperation> nil = new List(); + return nil.iterator(); + } + + @Override + public String uuid() { + return uuid; + } + + @Override + public String getTreeName() { + return name; + } + }; + TreeNode root = new DefaultTreeNode(); + InterfaceTraverser traverser = new InterfaceTraverser(root,true); + TreeContext tc = new DefaultTreeContext(root, null, list, uuid, name, 0, traverser); + JungleTree newTree = new NetworkDefaultJungleTree(name, tc, uuid, journal.getWriter(), editor); + if (trees.putIfAbsent(name, newTree) != null) { + return null; + } + return newTree; + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungleNetwork/operations/NetworkAppendChildAtOperation.java Tue Sep 15 17:31:19 2015 +0900 @@ -0,0 +1,55 @@ +package jp.ac.u_ryukyu.ie.cr.jungleNetwork.operations; + + +import jp.ac.u_ryukyu.ie.cr.jungle.store.Command; +import jp.ac.u_ryukyu.ie.cr.jungle.store.impl.TreeNode; +import jp.ac.u_ryukyu.ie.cr.jungle.store.operations.NodeOperation; +import jp.ac.u_ryukyu.ie.cr.jungle.util.Either; +import jp.ac.u_ryukyu.ie.cr.jungle.util.Error; +import org.msgpack.annotation.Message; + +import java.nio.ByteBuffer; + +@Message +public class NetworkAppendChildAtOperation implements NodeOperation { + + /* MessagePack cannot handle final.*/ + // private final int pos; + private int pos; + + /* Position -1 represent root position. */ + public NetworkAppendChildAtOperation() { pos = -2; } + + public NetworkAppendChildAtOperation(int _pos) { + pos = _pos; + } + + public Command getCommand() + { + return Command.APPEND_CHILD; + } + + @Override + public Either<Error,TreeNode> invoke(TreeNode _target) + { + return _target.getChildren().addNewChildAt(pos); + } + + @Override + public int getPosition() + { + return pos; + } + + @Override + public String getKey() + { + return null; + } + + @Override + public ByteBuffer getValue() + { + return null; + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungleNetwork/operations/NetworkDeleteAttributeOperation.java Tue Sep 15 17:31:19 2015 +0900 @@ -0,0 +1,59 @@ +package jp.ac.u_ryukyu.ie.cr.jungleNetwork.operations; + + +import jp.ac.u_ryukyu.ie.cr.jungle.store.Command; +import jp.ac.u_ryukyu.ie.cr.jungle.store.impl.TreeNode; +import jp.ac.u_ryukyu.ie.cr.jungle.store.operations.NodeOperation; +import jp.ac.u_ryukyu.ie.cr.jungle.util.Error; +import jp.ac.u_ryukyu.ie.cr.jungle.util.Either; +import org.msgpack.annotation.Message; + +import java.nio.ByteBuffer; + +@Message +public class NetworkDeleteAttributeOperation implements NodeOperation +{ + /* MessagePack cannot handle final.*/ + //private final String key; + private String key; + + public NetworkDeleteAttributeOperation() + { + key = null; + } + + public NetworkDeleteAttributeOperation(String _key) + { + key = _key; + } + + @Override + public Command getCommand() + { + return Command.DELETE_ATTRIBUTE; + } + + @Override + public Either<Error, TreeNode> invoke(TreeNode _target) + { + return _target.getAttributes().delete(key); + } + + @Override + public int getPosition() + { + return -1; + } + + @Override + public String getKey() + { + return key; + } + + @Override + public ByteBuffer getValue() + { + return null; + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungleNetwork/operations/NetworkDeleteChildAtOperation.java Tue Sep 15 17:31:19 2015 +0900 @@ -0,0 +1,58 @@ +package jp.ac.u_ryukyu.ie.cr.jungleNetwork.operations; + +import jp.ac.u_ryukyu.ie.cr.jungle.store.Command; +import jp.ac.u_ryukyu.ie.cr.jungle.store.impl.TreeNode; +import jp.ac.u_ryukyu.ie.cr.jungle.store.operations.NodeOperation; +import jp.ac.u_ryukyu.ie.cr.jungle.util.Either; +import jp.ac.u_ryukyu.ie.cr.jungle.util.Error; + +import org.msgpack.annotation.Message; + +import java.nio.ByteBuffer; + +@Message +public class NetworkDeleteChildAtOperation implements NodeOperation +{ + /* MessagePack cannot handle final.*/ + //private final int pos; + private int pos; + + + public NetworkDeleteChildAtOperation() {} + + /* Position -1 represent root position. */ + public NetworkDeleteChildAtOperation(int _pos) + { + pos = _pos; + } + + @Override + public Command getCommand() + { + return Command.DELETE_CHILD; + } + + @Override + public Either<Error, TreeNode> invoke(TreeNode _target) + { + return _target.getChildren().deleteChildAt(pos); + } + + @Override + public int getPosition() + { + return pos; + } + + @Override + public String getKey() + { + return null; + } + + @Override + public ByteBuffer getValue() + { + return null; + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungleNetwork/operations/NetworkNodeOperation.java Tue Sep 15 17:31:19 2015 +0900 @@ -0,0 +1,105 @@ +package jp.ac.u_ryukyu.ie.cr.jungleNetwork.operations; + + +import jp.ac.u_ryukyu.ie.cr.jungle.store.Command; +import jp.ac.u_ryukyu.ie.cr.jungle.store.impl.TreeNode; +import jp.ac.u_ryukyu.ie.cr.jungle.store.operations.NodeOperation; +import jp.ac.u_ryukyu.ie.cr.jungle.util.Either; +import jp.ac.u_ryukyu.ie.cr.jungle.util.Error; +import org.msgpack.annotation.Message; + +import java.nio.ByteBuffer; + +@Message +public class NetworkNodeOperation implements NodeOperation { + + public int pos; + public String key; + public ByteBuffer value; + public int commandType; + + public final static int NUM_PUT_ATTRIBUTE = 1; + public final static int NUM_APPEND_CHILD = 2; + public final static int NUM_DELETE_CHILD = 3; + public final static int NUM_DELETE_ATTRIBUTE = 4; + + public NetworkNodeOperation() { + pos = -2; + key = null; + value = null; + commandType = 0; + } + + public NetworkNodeOperation(NodeOperation _op) { + pos = _op.getPosition(); + key = _op.getKey(); + value = _op.getValue(); + commandType = getCommandType(_op.getCommand()); + } + + public static int getCommandType(Command c) { + switch(c) { + case PUT_ATTRIBUTE: + return NUM_PUT_ATTRIBUTE; + case APPEND_CHILD: + return NUM_APPEND_CHILD; + case DELETE_CHILD: + return NUM_DELETE_CHILD; + case DELETE_ATTRIBUTE: + return NUM_DELETE_ATTRIBUTE; + default: + break; + } + return 0; + } + + public static Command getCommand(int num) { + switch(num) { + case NUM_PUT_ATTRIBUTE: + return Command.PUT_ATTRIBUTE; + case NUM_APPEND_CHILD: + return Command.APPEND_CHILD; + case NUM_DELETE_CHILD: + return Command.DELETE_CHILD; + case NUM_DELETE_ATTRIBUTE: + return Command.DELETE_ATTRIBUTE; + default: + break; + } + return null; + } + + public Command getCommand() { + return getCommand(commandType); + } + + public int getPosition() { + return pos; + } + + public String getKey() { + return key; + } + + public ByteBuffer getValue() { + return value; + } + + @Override + public Either<Error, TreeNode> invoke(TreeNode _target) { + switch(getCommand(commandType)) { + case PUT_ATTRIBUTE: + return _target.getAttributes().put(key, value); + case APPEND_CHILD: + return _target.getChildren().addNewChildAt(pos); + case DELETE_CHILD: + return _target.getChildren().deleteChildAt(pos); + case DELETE_ATTRIBUTE: + return _target.getAttributes().delete(key); + default: + break; + } + return null; + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungleNetwork/operations/NetworkNodePath.java Tue Sep 15 17:31:19 2015 +0900 @@ -0,0 +1,81 @@ +package jp.ac.u_ryukyu.ie.cr.jungleNetwork.operations; + + +import jp.ac.u_ryukyu.ie.cr.jungle.store.NodePath; +import jp.ac.u_ryukyu.ie.cr.jungle.util.Pair; +import org.msgpack.annotation.Message; + +import java.util.Iterator; +import java.util.LinkedList; + +@Message +public class NetworkNodePath implements NodePath { + LinkedList<Integer> path; + + public NetworkNodePath() { + path = new LinkedList<Integer>(); + path.add(-1); + } + + public NetworkNodePath(NodePath _p) { + path = new LinkedList<Integer>(); + for (Integer pos : _p) { + path.add(pos); + } + } + + private NetworkNodePath(LinkedList<Integer> _path) { + path = _path; + } + + @Override + public Iterator<Integer> iterator() { + return path.iterator(); + } + + @Override + public NetworkNodePath add(int _pos) { + LinkedList<Integer> newPath = copyPath(); + newPath.add(_pos); + return new NetworkNodePath(newPath); + } + + @Override + public Pair<Integer, NodePath> pop() { + LinkedList<Integer> cPath = copyPath(); + int e = cPath.getFirst(); + cPath.remove(); + return new Pair<Integer, NodePath>(e, new NetworkNodePath(cPath)); + } + + @Override + public int size() { + return path.size(); + } + + private LinkedList<Integer> copyPath() { + LinkedList<Integer> newPath = new LinkedList<Integer>(); + for (Integer i : path) { + newPath.add(i); + } + return newPath; + } + + @Override + public String toString() { + return path.toString(); + } + + @Override + public NodePath tail() { + path.removeLast(); + return new NetworkNodePath(path); + } + + @Override + public Pair<Integer, NodePath> last() { + Integer num = path.removeLast(); + return new Pair<Integer, NodePath>(num, new NetworkNodePath(path)); + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungleNetwork/operations/NetworkPutAttributeOperation.java Tue Sep 15 17:31:19 2015 +0900 @@ -0,0 +1,66 @@ +package jp.ac.u_ryukyu.ie.cr.jungleNetwork.operations; + + +import jp.ac.u_ryukyu.ie.cr.jungle.util.Error; +import jp.ac.u_ryukyu.ie.cr.jungle.store.Command; +import jp.ac.u_ryukyu.ie.cr.jungle.store.impl.TreeNode; +import jp.ac.u_ryukyu.ie.cr.jungle.store.operations.NodeOperation; +import jp.ac.u_ryukyu.ie.cr.jungle.util.Either; +import org.msgpack.annotation.Message; + +import java.nio.ByteBuffer; + +@Message +public class NetworkPutAttributeOperation implements NodeOperation +{ + +/* MessagePack cannot handle final. + * + * private final String key; + * private final ByteBuffer value; + */ + public String key; + public ByteBuffer value; + + public NetworkPutAttributeOperation() + { + key = null; + value = null; + } + + public NetworkPutAttributeOperation(String _key,ByteBuffer _value) + { + key = _key; + value = _value; + } + + @Override + public Command getCommand() + { + return Command.PUT_ATTRIBUTE; + } + + @Override + public Either<Error, TreeNode> invoke(TreeNode _target) + { + return _target.getAttributes().put(key,value); + } + + @Override + public int getPosition() + { + return -1; + } + + @Override + public String getKey() + { + return key; + } + + @Override + public ByteBuffer getValue() + { + return value; + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungleNetwork/operations/NetworkTreeOperation.java Tue Sep 15 17:31:19 2015 +0900 @@ -0,0 +1,68 @@ +package jp.ac.u_ryukyu.ie.cr.jungleNetwork.operations; + + +import jp.ac.u_ryukyu.ie.cr.jungle.store.Command; +import jp.ac.u_ryukyu.ie.cr.jungle.store.NodePath; +import jp.ac.u_ryukyu.ie.cr.jungle.store.operations.*; +import org.msgpack.annotation.Message; + +@Message +public class NetworkTreeOperation implements TreeOperation { + + public NetworkNodePath path; + public NetworkNodeOperation operation; + + public NetworkTreeOperation() { + path = null; + operation = null; + } + + public NetworkTreeOperation(TreeOperation treeOp) { + path = new NetworkNodePath(treeOp.getNodePath()); + operation = new NetworkNodeOperation(treeOp.getNodeOperation()); + } + + public NetworkTreeOperation(NodePath _p, NodeOperation _op) { + path = new NetworkNodePath(_p); + operation = new NetworkNodeOperation(_op); + } + + public NetworkTreeOperation(NetworkNodePath _p, NodeOperation _op) { + path = _p; + operation = new NetworkNodeOperation(_op); + } + + public NetworkTreeOperation(NodePath _p, NetworkNodeOperation _op) { + path = new NetworkNodePath(_p); + operation = _op; + } + + public NetworkTreeOperation(NetworkNodePath _p, NetworkNodeOperation _op) { + path = _p; + operation = _op; + } + + @Override + public NodePath getNodePath() { + return path; + } + + @Override + public NodeOperation getNodeOperation() { + Command c = operation.getCommand(); + switch(c) { + case PUT_ATTRIBUTE: + return new PutAttributeOperation(operation.getKey(), operation.getValue()); + case APPEND_CHILD: + return new AppendChildAtOperation(operation.getPosition()); + case DELETE_CHILD: + return new DeleteChildAtOperation(operation.getPosition()); + case DELETE_ATTRIBUTE: + return new DeleteAttributeOperation(operation.getKey()); + default: + break; + } + return null; + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungleNetwork/operations/NetworkTreeOperationLog.java Tue Sep 15 17:31:19 2015 +0900 @@ -0,0 +1,103 @@ +package jp.ac.u_ryukyu.ie.cr.jungleNetwork.operations; + + +import jp.ac.u_ryukyu.ie.cr.jungle.store.NodePath; +import jp.ac.u_ryukyu.ie.cr.jungle.store.impl.logger.TreeOperationLog; +import jp.ac.u_ryukyu.ie.cr.jungle.store.operations.NodeOperation; +import jp.ac.u_ryukyu.ie.cr.jungle.store.operations.TreeOperation; +import org.msgpack.annotation.Message; + +import java.util.Date; +import java.util.Iterator; +import java.util.LinkedList; + +@Message +public class NetworkTreeOperationLog implements TreeOperationLog +{ + public LinkedList<NetworkTreeOperation> list; + public int size; + String uuid; + String treeName; + long timestamp; + + public NetworkTreeOperationLog() { + list = new LinkedList<NetworkTreeOperation>(); + size = 0; + treeName = ""; + timestamp = new Date().getTime(); + } + + public NetworkTreeOperationLog(String _uuid, String _treeName, Iterable<TreeOperation> _list) + { + this(_uuid, _treeName, _list, new Date().getTime()); + } + + public NetworkTreeOperationLog(String _uuid, String _treeName, Iterable<TreeOperation> _list, long _timestamp) + { + uuid = _uuid; + treeName = _treeName; + list = new LinkedList<NetworkTreeOperation>(); + timestamp = _timestamp; + for(TreeOperation op: _list) { + NetworkTreeOperation nOp = new NetworkTreeOperation(op); + list.add(nOp); + } + size = list.size(); + } + + public NetworkTreeOperationLog(Iterable<TreeOperation> _list) + { + this("", "", _list); + } + + + @Override + public Iterator<TreeOperation> iterator() { + LinkedList<TreeOperation> opList = new LinkedList<TreeOperation>(); + for(NetworkTreeOperation op : list) { + opList.add(op); + } + return opList.iterator(); + } + + @Override + public NetworkTreeOperationLog add(NodePath _p, NodeOperation _op) + { + NetworkTreeOperation op = new NetworkTreeOperation(_p, _op); + list.add(op); + return this; + } + + @Override + public NetworkTreeOperationLog append(TreeOperationLog _log) + { + for (TreeOperation o : _log) { + NetworkTreeOperation op = new NetworkTreeOperation(o); + list.add(op); + } + return this; + } + + @Override + public int length() + { + return size; + } + + public String getUUID() { + return uuid; + } + + public String getTreeName() { + return treeName; + } + + public long getTimeStamp() { + return timestamp; + } + + public void setTimeStamp(long _timestamp) { + timestamp = _timestamp; + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungleNetwork/persistent/AliceJournal.java Tue Sep 15 17:31:19 2015 +0900 @@ -0,0 +1,95 @@ +package jp.ac.u_ryukyu.ie.cr.jungleNetwork.persistent; + + +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.persistent.ChangeListWriter; +import jp.ac.u_ryukyu.ie.cr.jungle.persistent.Result; + +import java.io.File; +import java.io.FileNotFoundException; +import java.util.Iterator; + +public class AliceJournal implements NetworkJournal { + + private static final AliceChangeListWriter ALICE_WRITER = new AliceChangeListWriter(); + private static final AliceChangeListReader ALICE_READER = new AliceChangeListReader(); + @Override + public ChangeListReader getReader() { + return ALICE_READER; + } + @Override + public ChangeListWriter getWriter() { + return ALICE_WRITER; + } + + private static class AliceChangeListWriter implements ChangeListWriter + { + @Override + public Result write(ChangeList _operations) + { + /* + for(TreeOperation op : _operations){ + NodePath p = op.getNodePath(); + NodeOperation nodeOp = op.getNodeOperation(); + Command c = nodeOp.getCommand(); + String args = ""; + switch(c){ + case PUT_ATTRIBUTE: + String key = nodeOp.getKey(); + ByteBuffer value = nodeOp.getValue(); + if(value.limit() < 100){ + args = String.format("key:%s,value:%s",key,new String(value.array())); + }else{ + args = String.format("key:%s,value:%d",key,value.limit()); + } + break; + case DELETE_ATTRIBUTE: + args = String.format("key:%s",nodeOp.getKey()); + break; + case APPEND_CHILD: + args = String.format("pos:%d",nodeOp.getPosition()); + break; + case DELETE_CHILD: + args = String.format("pos:%d",nodeOp.getPosition()); + break; + } + System.out.println(String.format("[%s:%s:%s]",c,p,args)); + } + */ + return Result.SUCCESS; + } + } + + private static class AliceChangeListReader implements ChangeListReader + { + @Override + public ChangeListReader newReader() + { + return this; + } + + @Override + public ChangeList read() + { + return null; + } + + @Override + public Iterator<ChangeList> iterator() { + return null; + } + + } + + @Override + public void setInputFile(File file) throws FileNotFoundException { + + } + @Override + public void setOutputFile(File file) throws FileNotFoundException { + + } + + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungleNetwork/persistent/NetworkJournal.java Tue Sep 15 17:31:19 2015 +0900 @@ -0,0 +1,15 @@ +package jp.ac.u_ryukyu.ie.cr.jungleNetwork.persistent; + + +import jp.ac.u_ryukyu.ie.cr.jungle.persistent.Journal; + +import java.io.File; +import java.io.FileNotFoundException; + +public interface NetworkJournal extends Journal { + + public void setInputFile(File file) throws FileNotFoundException; + public void setOutputFile(File file) throws FileNotFoundException; + + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungleNetwork/persistent/PersistentChangeList.java Tue Sep 15 17:31:19 2015 +0900 @@ -0,0 +1,54 @@ +package jp.ac.u_ryukyu.ie.cr.jungleNetwork.persistent; + + +import jp.ac.u_ryukyu.ie.cr.jungle.persistent.ChangeList; +import jp.ac.u_ryukyu.ie.cr.jungle.store.TreeContext; +import jp.ac.u_ryukyu.ie.cr.jungle.store.impl.logger.TreeOperationLog; +import jp.ac.u_ryukyu.ie.cr.jungle.store.operations.TreeOperation; +import jp.ac.u_ryukyu.ie.cr.jungleNetwork.operations.NetworkTreeOperationLog; + +import java.util.Iterator; + +public class PersistentChangeList implements ChangeList { + + public NetworkTreeOperationLog log; + public String treeName; + public String uuid; + + public PersistentChangeList(String _uuid, String _treeName, TreeOperationLog _log) { + uuid = _uuid; + treeName = _treeName; + log = new NetworkTreeOperationLog(_log); + } + + public PersistentChangeList(NetworkTreeOperationLog _log) { + log = _log; + treeName = _log.getTreeName(); + uuid = _log.getUUID(); + } + + public PersistentChangeList(TreeContext cs) { + treeName = cs.getTreeName(); + uuid = cs.uuid(); + log = new NetworkTreeOperationLog(cs.getChangeList()); + } + + @Override + public Iterator<TreeOperation> iterator() { + return log.iterator(); + } + + public NetworkTreeOperationLog getTreeOperationLog() { + return log; + } + + public String getTreeName() { + return treeName; + } + + public String uuid() { + return uuid; + } + + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungleNetwork/persistent/PersistentChangeListReader.java Tue Sep 15 17:31:19 2015 +0900 @@ -0,0 +1,67 @@ +package jp.ac.u_ryukyu.ie.cr.jungleNetwork.persistent; + + +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.jungleNetwork.operations.NetworkTreeOperationLog; +import org.msgpack.MessagePack; + +import java.io.EOFException; +import java.io.IOException; +import java.io.InputStream; +import java.util.Iterator; + +public class PersistentChangeListReader implements ChangeListReader { + + private InputStream in; + MessagePack msgpack = SingletonMessageFromAlice.getInstance(); + + public PersistentChangeListReader(InputStream _in) { + in = _in; + } + + @Override + public ChangeListReader newReader() + { + return null; + } + + @Override + public ChangeList read() + { + try { + final NetworkTreeOperationLog readLog = msgpack.read(in, NetworkTreeOperationLog.class); + PersistentChangeList cl = new PersistentChangeList(readLog); + return cl; + } catch (EOFException e){ + + } catch (IOException e) { + } + return null; + } + + @Override + public Iterator<ChangeList> iterator() { + return new Iterator<ChangeList>() { + + @Override + public boolean hasNext() { + try { + return in.available() != 0; + } catch (IOException e) { + return false; + } + } + + @Override + public ChangeList next() { + return read(); + } + + @Override + public void remove() { + + } + }; + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungleNetwork/persistent/PersistentChangeListWriter.java Tue Sep 15 17:31:19 2015 +0900 @@ -0,0 +1,35 @@ +package jp.ac.u_ryukyu.ie.cr.jungleNetwork.persistent; + + +import jp.ac.u_ryukyu.ie.cr.jungle.persistent.ChangeList; +import jp.ac.u_ryukyu.ie.cr.jungle.persistent.ChangeListWriter; +import jp.ac.u_ryukyu.ie.cr.jungle.persistent.Result; +import jp.ac.u_ryukyu.ie.cr.jungleNetwork.operations.NetworkTreeOperationLog; +import org.msgpack.MessagePack; + +import java.io.IOException; +import java.io.OutputStream; + +public class PersistentChangeListWriter implements ChangeListWriter { + + MessagePack msgpack = SingletonMessageFromAlice.getInstance(); + OutputStream out; + + public PersistentChangeListWriter(OutputStream _out) { + out = _out; + } + + @Override + public Result write(ChangeList cs) + { + NetworkTreeOperationLog log = new NetworkTreeOperationLog(cs.uuid(), cs.getTreeName(), cs); + try { + msgpack.write(out, log); + out.flush(); + return Result.SUCCESS; + } catch (IOException e) { + + } + return null; + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungleNetwork/persistent/PersistentJournal.java Tue Sep 15 17:31:19 2015 +0900 @@ -0,0 +1,80 @@ +package jp.ac.u_ryukyu.ie.cr.jungleNetwork.persistent; + + +import jp.ac.u_ryukyu.ie.cr.jungle.persistent.ChangeListReader; +import jp.ac.u_ryukyu.ie.cr.jungle.persistent.ChangeListWriter; + +import java.io.*; + +public class PersistentJournal implements NetworkJournal { + + private ChangeListWriter WRITER; + private ChangeListReader READER; + private OutputStream out; + private InputStream in; + private String logFileName; + + public PersistentJournal() { + } + + public PersistentJournal(File file) throws FileNotFoundException { + out = new FileOutputStream(file,true); + in = new FileInputStream(file); + WRITER = new PersistentChangeListWriter(out); + READER = new PersistentChangeListReader(in); + } + + @Override + public ChangeListReader getReader() { + return READER; + } + + @Override + public ChangeListWriter getWriter() { + String timeStamp = Long.toString(System.currentTimeMillis()); + logFileName = timeStamp + ".log"; + OutputStream outStream = null; + try { + outStream = new FileOutputStream(new File("./log/"+logFileName)); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } + ChangeListWriter writer = new PersistentChangeListWriter(outStream); + return writer; + } + + public void setOutputFile(File file) throws FileNotFoundException { + setOutputStream(new FileOutputStream(file, true)); + } + + public void setInputFile(File file) throws FileNotFoundException { + setInputStream(new FileInputStream(file)); + } + + public void setOutputStream(OutputStream _out) { + out = _out; + WRITER = new PersistentChangeListWriter(out); + } + + public OutputStream getOutputStream() { + return out; + } + + public void setInputStream(InputStream _in) { + in = _in; + READER = new PersistentChangeListReader(in); + } + + public InputStream getInputStream() { + return in; + } + + public String getLogName(){ + return logFileName; + } + + public void close() throws IOException { + out.close(); + in.close(); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungleNetwork/persistent/PersistentJungle.java Tue Sep 15 17:31:19 2015 +0900 @@ -0,0 +1,65 @@ +package jp.ac.u_ryukyu.ie.cr.jungleNetwork.persistent; + + +import jp.ac.u_ryukyu.ie.cr.jungle.Jungle; +import jp.ac.u_ryukyu.ie.cr.jungle.JungleTree; +import jp.ac.u_ryukyu.ie.cr.jungle.data.list.List; +import jp.ac.u_ryukyu.ie.cr.jungle.persistent.ChangeList; +import jp.ac.u_ryukyu.ie.cr.jungle.store.TreeContext; +import jp.ac.u_ryukyu.ie.cr.jungle.store.TreeEditor; +import jp.ac.u_ryukyu.ie.cr.jungle.store.impl.TreeNode; +import jp.ac.u_ryukyu.ie.cr.jungle.store.operations.TreeOperation; +import jp.ac.u_ryukyu.ie.cr.jungle.transaction.DefaultTreeNode; +import jp.ac.u_ryukyu.ie.cr.jungle.traverser.InterfaceTraverser; + +import java.util.Iterator; +import java.util.concurrent.ConcurrentHashMap; + +public class PersistentJungle implements Jungle { + private PersistentJournal journal; + private ConcurrentHashMap<String, JungleTree> trees; + final private String uuid; + private TreeEditor editor; + + public PersistentJungle(PersistentJournal _journal, String _uuid, TreeEditor _editor) { + journal = _journal; + trees = new ConcurrentHashMap<String, JungleTree>(); + uuid = _uuid; + editor = _editor; + } + + @Override + public JungleTree getTreeByName(String _name) { + return trees.get(_name); + } + + @Override + public JungleTree createNewTree(final String name) { + ChangeList list = new ChangeList() { + @Override + public Iterator<TreeOperation> iterator() { + List<TreeOperation> nil = new List(); + return nil.iterator(); + } + + @Override + public String uuid() { + return uuid; + } + + @Override + public String getTreeName() { + return name; + } + }; + TreeNode root = new DefaultTreeNode(); + InterfaceTraverser traverser = new InterfaceTraverser(root,true); + TreeContext tc = new PersistentTreeContext(root, null, list, uuid, name, 0, traverser); + JungleTree newTree = new PersistentJungleTree(name, tc, uuid, journal.getWriter(), editor); + if (trees.putIfAbsent(name, newTree) != null) { + return null; + } + return newTree; + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungleNetwork/persistent/PersistentJungleTree.java Tue Sep 15 17:31:19 2015 +0900 @@ -0,0 +1,116 @@ +package jp.ac.u_ryukyu.ie.cr.jungleNetwork.persistent; + + +import jp.ac.u_ryukyu.ie.cr.jungle.DefaultJungleTree; +import jp.ac.u_ryukyu.ie.cr.jungle.JungleTree; +import jp.ac.u_ryukyu.ie.cr.jungle.JungleTreeEditor; +import jp.ac.u_ryukyu.ie.cr.jungle.data.list.List; +import jp.ac.u_ryukyu.ie.cr.jungle.data.treemap.TreeMap; +import jp.ac.u_ryukyu.ie.cr.jungle.persistent.ChangeListWriter; +import jp.ac.u_ryukyu.ie.cr.jungle.store.NodePath; +import jp.ac.u_ryukyu.ie.cr.jungle.store.TreeContext; +import jp.ac.u_ryukyu.ie.cr.jungle.store.TreeEditor; +import jp.ac.u_ryukyu.ie.cr.jungle.store.impl.TreeNode; +import jp.ac.u_ryukyu.ie.cr.jungle.store.index.ParentIndex; +import jp.ac.u_ryukyu.ie.cr.jungle.transaction.DefaultJungleTreeEditor; +import jp.ac.u_ryukyu.ie.cr.jungle.traverser.InterfaceTraverser; +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; +import jp.ac.u_ryukyu.ie.cr.jungle.util.GetOldTreeError; + +import java.util.concurrent.atomic.AtomicReference; + +public class PersistentJungleTree implements JungleTree { + private final AtomicReference<TreeContext> repository; + private final String uuid; + private final String treeName; + private final ChangeListWriter writer; + private final TreeEditor editor; + + public PersistentJungleTree(String _treeName, TreeContext _tc,String _uuid, ChangeListWriter _writer,TreeEditor _editor) + { + treeName = _treeName; + repository = new AtomicReference<TreeContext>(_tc); + uuid = _uuid; + writer = _writer; + editor = _editor; + } + + @Override + public JungleTreeEditor getTreeEditor() + { + TreeContext tc = repository.get(); + PersistentTransactionManager txManager = new PersistentTransactionManager(treeName, writer,tc,repository,uuid); + TreeNode root = tc.getRoot(); + return new DefaultJungleTreeEditor(root,txManager,editor); + } + + @Override + public TreeNode getRootNode() + { + TreeContext tc = repository.get(); + return tc.getRoot(); + } + + @Override + public JungleTreeEditor getLocalTreeEditor() { + return getTreeEditor(); + } + + @Override + public long revision() { + TreeContext tc = repository.get(); + return tc.revision(); + } + + @Override + public Either<Error, JungleTree> getOldTree(long revision) { + TreeContext tc = repository.get(); + + for (; tc.revision() != revision;) { + tc = tc.prev(); + if (tc == null) + return DefaultEither.newA(GetOldTreeError.OLD_TREE_NOT_FOUND); + } + + + String oldTreeUuid = uuid + revision; + JungleTree oldTree = new DefaultJungleTree(tc, oldTreeUuid, writer, editor); + return DefaultEither.newB(oldTree); + } + + @Override + public ParentIndex getParentIndex() { + TreeContext tc = repository.get(); + return tc.getParentIndex(); + } + + @Override + public TreeMap<String, TreeMap<String,List<TreeNode>>> getIndex() { + TreeContext tc = repository.get(); + return tc.getIndex(); + } + + @Override + public InterfaceTraverser getTraverser(boolean useIndex) { + TreeMap<String, TreeMap<String, List<TreeNode>>> index = getIndex(); + ParentIndex parentIndex = getParentIndex(); + return new InterfaceTraverser(getRootNode(), index, parentIndex, useIndex); + } + + @Override + public Either<Error, TreeNode> getNodeOfPath(NodePath path) { + TreeNode node = repository.get().getRoot(); + for (int num : path) { + if (num == -1) + continue; + Either<Error, TreeNode> either = node.getChildren().at(num); + if (either.isA()) + return either; + node = either.b(); + } + return DefaultEither.newB(node); + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungleNetwork/persistent/PersistentTransactionManager.java Tue Sep 15 17:31:19 2015 +0900 @@ -0,0 +1,63 @@ +package jp.ac.u_ryukyu.ie.cr.jungleNetwork.persistent; + + +import jp.ac.u_ryukyu.ie.cr.jungle.persistent.ChangeListWriter; +import jp.ac.u_ryukyu.ie.cr.jungle.store.TreeContext; +import jp.ac.u_ryukyu.ie.cr.jungle.store.impl.TreeNode; +import jp.ac.u_ryukyu.ie.cr.jungle.store.impl.logger.TreeOperationLog; +import jp.ac.u_ryukyu.ie.cr.jungle.transaction.TransactionManager; +import jp.ac.u_ryukyu.ie.cr.jungle.traverser.InterfaceTraverser; +import jp.ac.u_ryukyu.ie.cr.jungle.util.DefaultEither; +import jp.ac.u_ryukyu.ie.cr.jungle.util.DefaultError; +import jp.ac.u_ryukyu.ie.cr.jungle.util.Either; +import jp.ac.u_ryukyu.ie.cr.jungle.util.Error; + +import java.util.concurrent.atomic.AtomicReference; + +public class PersistentTransactionManager implements TransactionManager { + private final AtomicReference<TreeContext> repository; + private final TreeContext tip; + private final ChangeListWriter writer; + private final String uuid; + private final String treeName; + + public PersistentTransactionManager(String _treeName, ChangeListWriter _writer, TreeContext _tip, + AtomicReference<TreeContext> _repository, String _uuid) { + repository = _repository; + tip = _tip; + writer = _writer; + uuid = _uuid; + treeName = _treeName; + } + + @Override + public Either<Error, TransactionManager> commit(TreeNode _newRoot, final TreeOperationLog _log) { + long currentRevision = tip.revision(); + long nextRevision = currentRevision + 1; + + PersistentChangeList list = new PersistentChangeList(uuid, treeName, _log); + InterfaceTraverser traverser = new InterfaceTraverser(_newRoot, false); + traverser.createIndex(); + PersistentTreeContext newContext = new PersistentTreeContext(_newRoot, tip, list, uuid, treeName, nextRevision, traverser); + + if (repository.compareAndSet(newContext.prev(), newContext)) { + TransactionManager txManager = new PersistentTransactionManager(treeName, writer, newContext, repository, uuid); + return DefaultEither.newB(txManager); + } + + return DefaultEither.newA((Error) new DefaultError()); + + } + + @Override + public long getRevision() { + return tip.revision(); + } + + @Override + public String getUUID() { + return uuid; + } + + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungleNetwork/persistent/PersistentTreeContext.java Tue Sep 15 17:31:19 2015 +0900 @@ -0,0 +1,82 @@ +package jp.ac.u_ryukyu.ie.cr.jungleNetwork.persistent; + + +import jp.ac.u_ryukyu.ie.cr.jungle.data.list.List; +import jp.ac.u_ryukyu.ie.cr.jungle.data.treemap.TreeMap; +import jp.ac.u_ryukyu.ie.cr.jungle.persistent.ChangeList; +import jp.ac.u_ryukyu.ie.cr.jungle.store.TreeContext; +import jp.ac.u_ryukyu.ie.cr.jungle.store.impl.TreeNode; +import jp.ac.u_ryukyu.ie.cr.jungle.store.index.ParentIndex; +import jp.ac.u_ryukyu.ie.cr.jungle.store.operations.TreeOperation; +import jp.ac.u_ryukyu.ie.cr.jungle.traverser.InterfaceTraverser; + +public class PersistentTreeContext implements TreeContext { + private final TreeNode root; + private final TreeContext previous; + private final ChangeList changeList; + private final String uuid; + private final long revision; + private final String treeName; + private InterfaceTraverser traverser; + + public PersistentTreeContext(TreeNode _node, TreeContext _prev, ChangeList _log, String _uuid, String _treeName, + long _revision, InterfaceTraverser traverser) { + this.root = _node; + this.previous = _prev; + this.changeList = _log; + this.uuid = _uuid; + this.revision = _revision; + this.treeName = _treeName; + this.traverser = traverser; + } + + @Override + public TreeNode getRoot() { + return root; + } + + @Override + public TreeContext prev() { + return previous; + } + + @Override + public ChangeList getChangeList() { + return changeList; + } + + @Override + public String uuid() { + return uuid; + } + + @Override + public long revision() { + return revision; + } + + @Override + public Iterable<TreeOperation> getOperations() { + return changeList; + } + + public String getTreeName() { + return treeName; + } + + @Override + public TreeMap<String, TreeMap<String, List<TreeNode>>> getIndex() { + return traverser.getIndex(); + } + + @Override + public ParentIndex getParentIndex() { + return traverser.getParentIndex(); + } + + @Override + public InterfaceTraverser getTraverser() { + return traverser; + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungleNetwork/persistent/SingletonMessageFromAlice.java Tue Sep 15 17:31:19 2015 +0900 @@ -0,0 +1,11 @@ +package jp.ac.u_ryukyu.ie.cr.jungleNetwork.persistent; + +import alice.codesegment.SingletonMessage; +import org.msgpack.MessagePack; + +public class SingletonMessageFromAlice { + + public static MessagePack getInstance(){ + return SingletonMessage.getInstance(); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungleNetwork/remote/RemoteConfig.java Tue Sep 15 17:31:19 2015 +0900 @@ -0,0 +1,21 @@ +package jp.ac.u_ryukyu.ie.cr.jungleNetwork.remote; + +import alice.topology.node.TopologyNodeConfig; + + +public class RemoteConfig extends TopologyNodeConfig { + + public int bbsPort = 8080; + + public RemoteConfig(String[] args) { + super(args); + for (int i = 0; i< args.length; i++) { + if ("-bbsPort".equals(args[i])) { + bbsPort = Integer.parseInt(args[++i]); + } else if("-bp".equals(args[i])) { + bbsPort = Integer.parseInt(args[++i]); + } + } + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungleNetwork/transaction/JungleUpdater.java Tue Sep 15 17:31:19 2015 +0900 @@ -0,0 +1,76 @@ +package jp.ac.u_ryukyu.ie.cr.jungleNetwork.transaction; + + +import jp.ac.u_ryukyu.ie.cr.jungle.JungleTreeEditor; +import jp.ac.u_ryukyu.ie.cr.jungle.store.Command; +import jp.ac.u_ryukyu.ie.cr.jungle.store.NodePath; +import jp.ac.u_ryukyu.ie.cr.jungle.store.operations.NodeOperation; +import jp.ac.u_ryukyu.ie.cr.jungle.store.operations.TreeOperation; +import jp.ac.u_ryukyu.ie.cr.jungle.util.Either; +import jp.ac.u_ryukyu.ie.cr.jungle.util.Error; + +import java.nio.ByteBuffer; + +public class JungleUpdater { + + public JungleUpdater() { + + } + + public static Either<Error, JungleTreeEditor> edit(JungleTreeEditor _editor ,Iterable<TreeOperation> _log) { + JungleTreeEditor editor = _editor; + Either<Error, JungleTreeEditor> either = null; + for (TreeOperation op : _log) { + NodePath path = op.getNodePath(); + NodeOperation nodeOp = op.getNodeOperation(); + either = _edit(editor, path, nodeOp, nodeOp.getPosition()); + if(either.isA()) { + return either; + } + editor = either.b(); + } + return either; + } + + /* + * This method decide node position by param. + */ + public static Either<Error, JungleTreeEditor> edit(JungleTreeEditor _editor ,Iterable<TreeOperation> _log, int pos) { + JungleTreeEditor editor = _editor; + Either<Error, JungleTreeEditor> either = null; + for (TreeOperation op : _log) { + NodePath path = op.getNodePath(); + NodeOperation nodeOp = op.getNodeOperation(); + either = _edit(editor, path, nodeOp, pos); + if(either.isA()) { + return either; + } + editor = either.b(); + } + return either; + } + + + private static Either<Error, JungleTreeEditor> _edit(JungleTreeEditor editor, NodePath path, + NodeOperation nodeOp, int pos) { + String key = ""; + Command c = nodeOp.getCommand(); + System.out.println("path = " + path.toString()); + switch (c) { + case PUT_ATTRIBUTE: + key = nodeOp.getKey(); + ByteBuffer value = nodeOp.getValue(); + System.out.println("key = " + key + " : " + "value = " + new String(value.array())); + return editor.putAttribute(path, key, value); + case DELETE_ATTRIBUTE: + key = nodeOp.getKey(); + return editor.deleteAttribute(path, key); + case APPEND_CHILD: + return editor.addNewChildAt(path, pos); + case DELETE_CHILD: + return editor.deleteChildAt(path, 0); + } + return null; + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungleNetwork/transaction/NetworkDefaultJungleTree.java Tue Sep 15 17:31:19 2015 +0900 @@ -0,0 +1,121 @@ +package jp.ac.u_ryukyu.ie.cr.jungleNetwork.transaction; + + +import jp.ac.u_ryukyu.ie.cr.jungle.DefaultJungleTree; +import jp.ac.u_ryukyu.ie.cr.jungle.JungleTree; +import jp.ac.u_ryukyu.ie.cr.jungle.JungleTreeEditor; +import jp.ac.u_ryukyu.ie.cr.jungle.data.list.List; +import jp.ac.u_ryukyu.ie.cr.jungle.data.treemap.TreeMap; +import jp.ac.u_ryukyu.ie.cr.jungle.persistent.ChangeListWriter; +import jp.ac.u_ryukyu.ie.cr.jungle.store.NodePath; +import jp.ac.u_ryukyu.ie.cr.jungle.store.TreeContext; +import jp.ac.u_ryukyu.ie.cr.jungle.store.TreeEditor; +import jp.ac.u_ryukyu.ie.cr.jungle.store.impl.TreeNode; +import jp.ac.u_ryukyu.ie.cr.jungle.store.index.ParentIndex; +import jp.ac.u_ryukyu.ie.cr.jungle.traverser.InterfaceTraverser; +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; +import jp.ac.u_ryukyu.ie.cr.jungle.util.GetOldTreeError; + +import java.util.concurrent.atomic.AtomicReference; + +public class NetworkDefaultJungleTree implements JungleTree { + private final AtomicReference<TreeContext> repository; + private final String uuid; + private final String treeName; + private final ChangeListWriter writer; + private final TreeEditor editor; + + public NetworkDefaultJungleTree(String _treeName, TreeContext _tc,String _uuid,ChangeListWriter _writer,TreeEditor _editor) + { + treeName = _treeName; + repository = new AtomicReference<TreeContext>(_tc); + uuid = _uuid; + writer = _writer; + editor = _editor; + } + + @Override + public JungleTreeEditor getTreeEditor() + { + TreeContext tc = repository.get(); + NetworkTransactionManager txManager = new NetworkTransactionManager(treeName, writer,tc,repository,uuid); + TreeNode root = tc.getRoot(); + return new NetworkDefaultJungleTreeEditor(treeName, root,txManager,editor); + } + + @Override + public JungleTreeEditor getLocalTreeEditor() + { + TreeContext tc = repository.get(); + NetworkTransactionManager txManager = new NetworkTransactionManager(treeName, writer,tc,repository,uuid); + TreeNode root = tc.getRoot(); + return NetworkDefaultJungleTreeEditor.NewLocalJungleTreeEditor(treeName,root,txManager, editor); + } + + @Override + public TreeNode getRootNode() + { + TreeContext tc = repository.get(); + return tc.getRoot(); + } + + @Override + public long revision() { + TreeContext tc = repository.get(); + return tc.revision(); + } + + @Override + public Either<Error, JungleTree> getOldTree(long revision) { + TreeContext tc = repository.get(); + + for (; tc.revision() != revision;) { + tc = tc.prev(); + if (tc == null) + return DefaultEither.newA(GetOldTreeError.OLD_TREE_NOT_FOUND); + } + + + String oldTreeUuid = uuid + revision; + JungleTree oldTree = new DefaultJungleTree(tc, oldTreeUuid, writer, editor); + return DefaultEither.newB(oldTree); + } + + @Override + public ParentIndex getParentIndex() { + TreeContext tc = repository.get(); + return tc.getParentIndex(); + } + + @Override + public TreeMap<String, TreeMap<String, List<TreeNode>>> getIndex() { + TreeContext tc = repository.get(); + return tc.getIndex(); + } + + @Override + public InterfaceTraverser getTraverser(boolean useIndex) { + TreeMap<String, TreeMap<String, List<TreeNode>>> index = getIndex(); + ParentIndex parentIndex = getParentIndex(); + return new InterfaceTraverser(getRootNode(), index, parentIndex, useIndex); + } + + + @Override + public Either<Error, TreeNode> getNodeOfPath(NodePath path) { + TreeNode node = repository.get().getRoot(); + for (int num : path) { + if (num == -1) + continue; + Either<Error, TreeNode> either = node.getChildren().at(num); + if (either.isA()) + return either; + node = either.b(); + } + return DefaultEither.newB(node); + } + + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungleNetwork/transaction/NetworkDefaultJungleTreeEditor.java Tue Sep 15 17:31:19 2015 +0900 @@ -0,0 +1,187 @@ +package jp.ac.u_ryukyu.ie.cr.jungleNetwork.transaction; + + +import alice.codesegment.CodeSegment; +import jp.ac.u_ryukyu.ie.cr.jungle.JungleTreeEditor; +import jp.ac.u_ryukyu.ie.cr.jungle.store.NodePath; +import jp.ac.u_ryukyu.ie.cr.jungle.store.TreeEditor; +import jp.ac.u_ryukyu.ie.cr.jungle.store.impl.TreeNode; +import jp.ac.u_ryukyu.ie.cr.jungle.store.impl.logger.DefaultTreeOperationLog; +import jp.ac.u_ryukyu.ie.cr.jungle.store.impl.logger.LoggingNode; +import jp.ac.u_ryukyu.ie.cr.jungle.store.impl.logger.OperationLog; +import jp.ac.u_ryukyu.ie.cr.jungle.store.impl.logger.TreeOperationLog; +import jp.ac.u_ryukyu.ie.cr.jungle.store.operations.DefaultTreeOperation; +import jp.ac.u_ryukyu.ie.cr.jungle.store.operations.NodeOperation; +import jp.ac.u_ryukyu.ie.cr.jungle.store.operations.TreeOperation; +import jp.ac.u_ryukyu.ie.cr.jungle.store.trasnformer.*; +import jp.ac.u_ryukyu.ie.cr.jungle.transaction.TransactionManager; +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; +import jp.ac.u_ryukyu.ie.cr.jungle.util.IterableConverter; +import jp.ac.u_ryukyu.ie.cr.jungleNetwork.bbs.codesegment.LogPutCodeSegment; +import jp.ac.u_ryukyu.ie.cr.jungleNetwork.operations.NetworkTreeOperationLog; + +import java.io.IOException; +import java.nio.ByteBuffer; + +public class NetworkDefaultJungleTreeEditor implements JungleTreeEditor { + + private final TransactionManager txManager; + private final TreeNode root; + private final TreeEditor editor; + private final String treeName; + private final TreeOperationLog log; + private boolean exportLog; + + public NetworkDefaultJungleTreeEditor(String _treeName, TreeNode _root,TransactionManager _txManager,TreeEditor _editor) + { + this(_treeName, _root,_txManager,_editor,new DefaultTreeOperationLog()); + } + + public NetworkDefaultJungleTreeEditor(String _treeName, TreeNode _root,TransactionManager _txManager,TreeEditor _editor, TreeOperationLog _log) + { + treeName = _treeName; + root = _root; + txManager = _txManager; + editor = _editor; + log = _log; + exportLog = true; + } + + public static NetworkDefaultJungleTreeEditor NewLocalJungleTreeEditor(String _treeName, TreeNode _root,TransactionManager _txManager,TreeEditor _editor) { + NetworkDefaultJungleTreeEditor treeEditor = new NetworkDefaultJungleTreeEditor(_treeName, _root,_txManager,_editor,new DefaultTreeOperationLog()); + treeEditor.exportLog = false; + return treeEditor; + } + + public static NetworkDefaultJungleTreeEditor NewLocalJungleTreeEditor(String _treeName, TreeNode _root,TransactionManager _txManager,TreeEditor _editor, TreeOperationLog _log) { + NetworkDefaultJungleTreeEditor treeEditor = new NetworkDefaultJungleTreeEditor(_treeName, _root,_txManager,_editor,_log); + treeEditor.exportLog = false; + return treeEditor; + } + + private Either<Error,JungleTreeEditor> _edit(final NodePath _path,NodeEditor _e) + { + //LoggingNodeHook hook = new LoggingNodeHook(_e); + Either<Error,LoggingNode> either = editor.edit(root,_path,_e); + if(either.isA()){ + return DefaultEither.newA(either.a()); + } + + TreeNode newNode = either.b().getWrap(); + OperationLog newLog = either.b().getOperationLog(); + + IterableConverter.Converter<TreeOperation,NodeOperation> converter = new IterableConverter.Converter<TreeOperation,NodeOperation>(){ + @Override + public TreeOperation conv(NodeOperation _b){ + return new DefaultTreeOperation(_path,_b); + } + }; + + Iterable<TreeOperation> iterable = new IterableConverter<TreeOperation,NodeOperation>(newLog,converter); + DefaultTreeOperationLog treeOperationLog = new DefaultTreeOperationLog(iterable,newLog.length()); + TreeOperationLog newTreeOpLog = log.append(treeOperationLog); + + JungleTreeEditor newEditor; + if(exportLog) { + newEditor = new NetworkDefaultJungleTreeEditor(treeName, newNode,txManager,editor,newTreeOpLog); + } else { + newEditor = NetworkDefaultJungleTreeEditor.NewLocalJungleTreeEditor(treeName, newNode, txManager, editor, newTreeOpLog); + } + return DefaultEither.newB(newEditor); + } + + @Override + public Either<Error,JungleTreeEditor> addNewChildAt(NodePath _path, int _pos) + { + AppendChildAt appendChildAt = new AppendChildAt(_pos); + return _edit(_path,appendChildAt); + } + + @Override + public Either<Error,JungleTreeEditor> deleteChildAt(NodePath _path, int _pos) + { + DeleteChildAt deleteChildAt = new DeleteChildAt(_pos); + return _edit(_path,deleteChildAt); + } + + @Override + public Either<Error,JungleTreeEditor> putAttribute(NodePath _path,String _key,ByteBuffer _value) + { + PutAttribute putAttribute = new PutAttribute(_key,_value); + return _edit(_path,putAttribute); + } + + @Override + public Either<Error,JungleTreeEditor> deleteAttribute(NodePath _path, String _key) + { + DeleteAttribute deleteAttribute = new DeleteAttribute(_key); + return _edit(_path,deleteAttribute); + } + + @Override + public Either<Error,JungleTreeEditor> edit(NodePath _path,NodeEditor _editor) + { + return _edit(_path,_editor); + } + + @Override + public Either<Error,JungleTreeEditor> success() + { + Either<Error,TransactionManager> either = txManager.commit(root,log); + if(either.isA()){ + return DefaultEither.newA(either.a()); + } + if(exportLog) { + try { + putTreeOperationLog(log); + } catch (IOException e) { + return DefaultEither.newA(either.a()); + } + } + + TransactionManager newTxManager = either.b(); + JungleTreeEditor newTreeEditor = new NetworkDefaultJungleTreeEditor(treeName, root,newTxManager,editor); + + return DefaultEither.newB(newTreeEditor); + } + + private String getID() + { + return txManager.getUUID(); + } + + private String getRevision() + { + return Long.toString(txManager.getRevision()); + } + + public String getTreeName() { + return treeName; + } + + public TreeOperationLog getTreeOperationLog() { + return log; + } + + public void putTreeOperationLog(Iterable<TreeOperation> newLog) throws IOException { + String uuid = getID(); + String treeName = getTreeName(); + String updaterName = getID(); + String revision = getRevision(); + putDataSegment(uuid, treeName, updaterName, newLog, revision); + } + + public void putDataSegment(String _uuid, String _treeName, String _updaterName, Iterable<TreeOperation> newLog, String nextRevision) throws IOException { + NetworkTreeOperationLog netLog = new NetworkTreeOperationLog(_uuid, _treeName,newLog); + CodeSegment cs = new LogPutCodeSegment(netLog); + cs.execute(); + } + + @Override + public Either<Error, JungleTreeEditor> replaceNewRootNode() { + // TODO Auto-generated method stub + return null; + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungleNetwork/transaction/NetworkTransactionManager.java Tue Sep 15 17:31:19 2015 +0900 @@ -0,0 +1,83 @@ +package jp.ac.u_ryukyu.ie.cr.jungleNetwork.transaction; + + +import jp.ac.u_ryukyu.ie.cr.jungle.persistent.ChangeList; +import jp.ac.u_ryukyu.ie.cr.jungle.persistent.ChangeListWriter; +import jp.ac.u_ryukyu.ie.cr.jungle.store.TreeContext; +import jp.ac.u_ryukyu.ie.cr.jungle.store.impl.TreeNode; +import jp.ac.u_ryukyu.ie.cr.jungle.store.impl.logger.TreeOperationLog; +import jp.ac.u_ryukyu.ie.cr.jungle.store.operations.TreeOperation; +import jp.ac.u_ryukyu.ie.cr.jungle.transaction.DefaultTreeContext; +import jp.ac.u_ryukyu.ie.cr.jungle.transaction.TransactionManager; +import jp.ac.u_ryukyu.ie.cr.jungle.traverser.InterfaceTraverser; +import jp.ac.u_ryukyu.ie.cr.jungle.util.DefaultEither; +import jp.ac.u_ryukyu.ie.cr.jungle.util.DefaultError; +import jp.ac.u_ryukyu.ie.cr.jungle.util.Either; +import jp.ac.u_ryukyu.ie.cr.jungle.util.Error; + +import java.util.Iterator; +import java.util.concurrent.atomic.AtomicReference; + +public class NetworkTransactionManager implements TransactionManager { + private final AtomicReference<TreeContext> repository; + private final TreeContext tip; + private final ChangeListWriter writer; + private final String uuid; + private final String treeName; + + public NetworkTransactionManager(String _treeName, ChangeListWriter _writer, TreeContext _tip, + AtomicReference<TreeContext> _repository, String _uuid) { + repository = _repository; + tip = _tip; + writer = _writer; + uuid = _uuid; + treeName = _treeName; + } + + @Override + public Either<Error, TransactionManager> commit(TreeNode newRoot, final TreeOperationLog _log) { + long currentRevision = tip.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; + } + }; + + InterfaceTraverser traverser = new InterfaceTraverser(newRoot, true); + traverser.createIndex(); + TreeContext newTreeContext = new DefaultTreeContext(newRoot , tip, list, uuid, treeName, nextRevision,traverser); + + + if (repository.compareAndSet(newTreeContext.prev(),newTreeContext)) { + TransactionManager txManager = new NetworkTransactionManager(treeName, writer, newTreeContext, repository, uuid); + return DefaultEither.newB(txManager); + } + + return DefaultEither.newA((Error) new DefaultError()); + + } + + @Override + public long getRevision() { + return tip.revision(); + } + + @Override + public String getUUID() { + return uuid; + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungleNetwork/transformer/NetworkAppendChildAt.java Tue Sep 15 17:31:19 2015 +0900 @@ -0,0 +1,51 @@ +package jp.ac.u_ryukyu.ie.cr.jungleNetwork.transformer; + + +/* + * This code same AppendChildAt. + */ + +import jp.ac.u_ryukyu.ie.cr.jungle.store.impl.TreeNode; +import jp.ac.u_ryukyu.ie.cr.jungle.store.impl.logger.LoggingNode; +import jp.ac.u_ryukyu.ie.cr.jungle.store.impl.logger.OperationLog; +import jp.ac.u_ryukyu.ie.cr.jungle.store.trasnformer.NodeEditor; +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; +import org.msgpack.annotation.Message; + +@Message +public class NetworkAppendChildAt implements NodeEditor { + + private final int pos; + + public NetworkAppendChildAt(int _pos) { + pos = _pos; + } + + public Either<Error, LoggingNode> _edit(LoggingNode _e) + { + Either<Error,LoggingNode> either = _e.getChildren().addNewChildAt(pos); + if(either.isA()){ + // error + return either; + } + return DefaultEither.newB(either.b()); + } + + @Override + public Either<Error, LoggingNode> edit(TreeNode _e) { + LoggingNode logNode = wrap(_e); + return _edit(logNode); + } + + public LoggingNode wrap(TreeNode node) { + return new LoggingNode(node); + } + + @Override + public LoggingNode wrap(TreeNode node, OperationLog op) { + return new LoggingNode(node, op); + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/jp/ac/u_ryukyu/ie/cr/alice/local/HasFieldCodeSegment.java Tue Sep 15 17:31:19 2015 +0900 @@ -0,0 +1,23 @@ +package jp.ac.u_ryukyu.ie.cr.alice.local; + +import alice.codesegment.CodeSegment; +import alice.datasegment.CommandType; +import alice.datasegment.Receiver; + +public class HasFieldCodeSegment extends CodeSegment { + + Receiver arg1 = ids.create(CommandType.TAKE); + String str; + + public HasFieldCodeSegment(String s) { + str = s; + } + + + public void run() { + int count = arg1.asInteger(); + System.out.println("-HasFieldCodeSegment- : "+str+" "+count); + System.exit(0); + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/jp/ac/u_ryukyu/ie/cr/alice/local/StartLocalCodeSegment.java Tue Sep 15 17:31:19 2015 +0900 @@ -0,0 +1,11 @@ +package jp.ac.u_ryukyu.ie.cr.alice.local; + +public class StartLocalCodeSegment { + + public static void main(String[] arg) { + HasFieldCodeSegment cs = new HasFieldCodeSegment("test"); + cs.arg1.setKey("count"); + cs.ods.update("count", 0); + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/jp/ac/u_ryukyu/ie/cr/alice/remote/ClientCodeSegment.java Tue Sep 15 17:31:19 2015 +0900 @@ -0,0 +1,23 @@ +package jp.ac.u_ryukyu.ie.cr.alice.remote; + +import alice.codesegment.CodeSegment; +import alice.datasegment.CommandType; +import alice.datasegment.Receiver; + +public class ClientCodeSegment extends CodeSegment { + + Receiver arg1 = ids.create(CommandType.TAKE); + + public void run() { + System.out.println("--ClientCodeSegment--"); + System.out.println("from : " + arg1.from); + System.out.println("index : "+ arg1.index); + int num = arg1.asInteger(); + System.out.println("num : "+num); + num++; + ods.put("remote", "num", num); + System.exit(0); + + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/jp/ac/u_ryukyu/ie/cr/alice/remote/ClientFirstSetKey.java Tue Sep 15 17:31:19 2015 +0900 @@ -0,0 +1,12 @@ +package jp.ac.u_ryukyu.ie.cr.alice.remote; + +import alice.codesegment.CodeSegment; + +public class ClientFirstSetKey extends CodeSegment { + + public void run() { + System.out.println("--ClientFirstSetKey--"); + ClientCodeSegment cs = new ClientCodeSegment(); + cs.arg1.setKey("remote","num"); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/jp/ac/u_ryukyu/ie/cr/alice/remote/HostCodeSegment.java Tue Sep 15 17:31:19 2015 +0900 @@ -0,0 +1,22 @@ +package jp.ac.u_ryukyu.ie.cr.alice.remote; + +import alice.codesegment.CodeSegment; +import alice.datasegment.CommandType; +import alice.datasegment.Receiver; + +public class HostCodeSegment extends CodeSegment { + + Receiver arg1 = ids.create(CommandType.TAKE); + + public void run() { + System.out.println("--HostCodeSegment--"); + System.out.println("index : "+ arg1.index); + System.out.println("from : "+ arg1.from); + int num = arg1.asInteger(); + System.out.println("num : "+ num); + num++; + ods.put("local", "num", num); + System.exit(0); + + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/jp/ac/u_ryukyu/ie/cr/alice/remote/HostFirstPut.java Tue Sep 15 17:31:19 2015 +0900 @@ -0,0 +1,13 @@ +package jp.ac.u_ryukyu.ie.cr.alice.remote; + +import alice.codesegment.CodeSegment; + +public class HostFirstPut extends CodeSegment { + + public void run() { + System.out.println("--HostFirstPut--"); + ods.put("local", "num", 0); + HostCodeSegment cs = new HostCodeSegment(); + cs.arg1.setKey("local", "num", 1); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/jp/ac/u_ryukyu/ie/cr/alice/remote/StartHostCodeSegment.java Tue Sep 15 17:31:19 2015 +0900 @@ -0,0 +1,15 @@ +package jp.ac.u_ryukyu.ie.cr.alice.remote; + +import alice.daemon.AliceDaemon; +import jp.ac.u_ryukyu.ie.cr.jungleNetwork.remote.RemoteConfig; + + +public class StartHostCodeSegment { + + static public void main(String[] args) { + System.out.println("--StartHostCodeSegment--"); + RemoteConfig conf = new RemoteConfig(args); + new AliceDaemon(conf).listen(); + new HostFirstPut().execute(); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/jp/ac/u_ryukyu/ie/cr/data/list/appendTest.java Tue Sep 15 17:31:19 2015 +0900 @@ -0,0 +1,35 @@ +package jp.ac.u_ryukyu.ie.cr.data.list; + +import jp.ac.u_ryukyu.ie.cr.jungle.data.list.List; +import junit.framework.Assert; +import org.junit.Test; + +import java.util.Iterator; + +/** + * Created by e115731 on 15/05/19. + */ +public class appendTest { + @Test + public void appendTest() { + + List<Integer> list = new List<>(); + for (int count = 1; count <= 10; count++) { + list = list.addLast(count); + } + + List<Integer> list2 = new List<>(); + for (int count = 11; count <= 20; count++) { + list2 = list2.addLast(count); + } + + List<Integer> newList = list.append(list2); + Iterator<Integer> iterator = newList.iterator(); + for (int count = 1; count <= 20; count++) { + Assert.assertTrue(iterator.hasNext()); + int num = iterator.next(); + Assert.assertEquals(num, count); + } + + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/jp/ac/u_ryukyu/ie/cr/data/list/deleteTest.java Tue Sep 15 17:31:19 2015 +0900 @@ -0,0 +1,29 @@ +package jp.ac.u_ryukyu.ie.cr.data.list; + +import jp.ac.u_ryukyu.ie.cr.jungle.data.list.List; +import junit.framework.Assert; +import org.junit.Test; + +/** + * Created by e115731 on 15/05/18. + */ +public class deleteTest { + @Test + public void deleteTest() { + List<Integer> list = new List<Integer>(); + + for (int count = 0; count < 10; count++) { + list = list.addLast(count); + } + List<Integer> newList = list.delete(5); + Assert.assertEquals(newList.length(),9); + newList = newList.deleteHead(); + int attribute = newList.index(1); + Assert.assertEquals(attribute,2); + Assert.assertEquals(newList.length(),8); + newList = newList.deleteLast(); + attribute = newList.index(6); + Assert.assertEquals(attribute,8); + Assert.assertEquals(list.length(),10); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/jp/ac/u_ryukyu/ie/cr/data/list/listAdd.java Tue Sep 15 17:31:19 2015 +0900 @@ -0,0 +1,39 @@ +package jp.ac.u_ryukyu.ie.cr.data.list; + +import jp.ac.u_ryukyu.ie.cr.jungle.data.list.List; +import junit.framework.Assert; +import org.junit.Test; + +/** + * Created by e115731 on 15/05/17. + */ +public class listAdd { + + @Test + public void listAddTest() { + + List<Integer> list = new List<Integer>(); + List<Integer> list2 = new List<Integer>(); + + for (int count = 0; count < 10; count++) { + list = list.addLast(count); + list2 = list2.add(count, count); + } + + for (int count = 0; count < 10; count++) { + int num = list.index(count); + int num2 = list2.index(count); + Assert.assertEquals(num,count); + Assert.assertEquals(num2,count); + } + + List<Integer> newList = list.add(5, 50); + int num = list.index(5); + int num2 = newList.index(5); + Assert.assertEquals(num,5); + Assert.assertEquals(num2,50); + + } + + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/jp/ac/u_ryukyu/ie/cr/data/list/listIterator.java Tue Sep 15 17:31:19 2015 +0900 @@ -0,0 +1,33 @@ +package jp.ac.u_ryukyu.ie.cr.data.list; + +import jp.ac.u_ryukyu.ie.cr.jungle.data.list.List; +import junit.framework.Assert; +import org.junit.Test; + +import java.util.Iterator; + +/** + * Created by e115731 on 15/05/17. + */ +public class listIterator { + @Test + public void listIteratorTest() { + List<Integer> list = new List<Integer>(); + for (int count = 1; count < 10; count++) { + list = list.addLast(count); + } + Iterator<Integer> iterator = list.iterator(); + for (int count = 1; count < 10; count++) { + Assert.assertTrue(iterator.hasNext()); + int attribute = iterator.next(); + Assert.assertEquals(attribute, count); + } + + iterator = list.reverseIterator(); + for (int count = 9; count > 0; count--) { + Assert.assertTrue(iterator.hasNext()); + int attribute = iterator.next(); + Assert.assertEquals(attribute, count); + } + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/jp/ac/u_ryukyu/ie/cr/data/list/replaceTest.java Tue Sep 15 17:31:19 2015 +0900 @@ -0,0 +1,25 @@ +package jp.ac.u_ryukyu.ie.cr.data.list; + +import jp.ac.u_ryukyu.ie.cr.jungle.data.list.List; +import junit.framework.Assert; +import org.junit.Test; + +/** + * Created by e115731 on 15/05/18. + */ +public class replaceTest { + @Test + public void replaceTest() { + List<Integer> list = new List<Integer>(); + for (int count = 0; count < 10; count++) { + list = list.addLast(count); + } + List<Integer> newList = list.replace(5, 15); + Assert.assertEquals(list.length(), 10); + int attribute = list.index(5); + Assert.assertEquals(attribute, 5); + attribute = newList.index(5); + Assert.assertEquals(newList.length(), 10); + Assert.assertEquals(attribute, 15); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/jp/ac/u_ryukyu/ie/cr/data/treemap/TreeMapDelete.java Tue Sep 15 17:31:19 2015 +0900 @@ -0,0 +1,32 @@ +package jp.ac.u_ryukyu.ie.cr.data.treemap; + +import jp.ac.u_ryukyu.ie.cr.jungle.data.treemap.RotateParent; +import jp.ac.u_ryukyu.ie.cr.jungle.data.treemap.TreeMap; +import org.junit.Test; + +import java.util.ArrayList; +import java.util.Collections; + +public class TreeMapDelete { + + @Test + public void TreeMapDeleteTest() throws RotateParent { + TreeMap<Integer, Integer> map = new TreeMap<>(); + for (int count = 1; count < 1000; count++) { + map = map.put(count, count); + map.checkDepth(); + } + + ArrayList<Integer> list = new ArrayList<>(); + for (int i = 1; i < 1000; i++) { + list.add(i); + } + Collections.shuffle(list); + for (Integer num : list) { + System.out.println(num); + map = map.delete(num); + map.checkDepth(); + } + System.out.println("end"); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/jp/ac/u_ryukyu/ie/cr/data/treemap/TreeMapTest.java Tue Sep 15 17:31:19 2015 +0900 @@ -0,0 +1,43 @@ +package jp.ac.u_ryukyu.ie.cr.data.treemap; + +import jp.ac.u_ryukyu.ie.cr.jungle.data.treemap.TreeMap; +import org.junit.Test; + +import java.util.Optional; + +public class TreeMapTest { + + @Test + public void TreeMapTest() { + TreeMap<Integer, Integer> map = new TreeMap<>(); + for (int count = 100; count > -10; count--) { + map = map.put(count, count); + map.checkDepth(); + System.out.println("-------------------------------------------"); + } + + for (int count = 100; count > -10; count--) { + + Optional<Integer> op = map.get(count); + if (op.isPresent()) + System.out.println(op.get()); + } + + System.out.println("end"); + } +} + + + + + + + + + + + + + + +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/jp/ac/u_ryukyu/ie/cr/data/treemap/TreeNodeIteratorTest.java Tue Sep 15 17:31:19 2015 +0900 @@ -0,0 +1,30 @@ +package jp.ac.u_ryukyu.ie.cr.data.treemap; + +import jp.ac.u_ryukyu.ie.cr.jungle.data.treemap.TreeMap; +import junit.framework.Assert; +import org.junit.Test; + +import java.util.Iterator; + +/** + * Created by e115731 on 15/05/06. + */ +public class TreeNodeIteratorTest { + @Test + public void getKeyTest() { + TreeMap<Integer, Integer> map = new TreeMap(); + for (int attributeMaxCount = 10; attributeMaxCount < 1000; attributeMaxCount = attributeMaxCount + 10) { + for (int count = 0; count < attributeMaxCount; count++) { //insertData + map = map.put(count, count); + } + Iterator<Integer> it = map.keys(); + int iteratorCount = 0; + while (it.hasNext()) { // count return iterator Attribute Count + iteratorCount++; + System.out.println(it.next()); + } + Assert.assertTrue(iteratorCount == attributeMaxCount); // check + } + + } +}
--- a/src/test/java/jp/ac/u_ryukyu/ie/cr/jungle/core/GetNodeOfPathTest.java Tue Sep 15 02:03:04 2015 +0900 +++ b/src/test/java/jp/ac/u_ryukyu/ie/cr/jungle/core/GetNodeOfPathTest.java Tue Sep 15 17:31:19 2015 +0900 @@ -26,7 +26,7 @@ DefaultNodePath path = new DefaultNodePath(); editor = editor.addNewChildAt(path, 0).b(); path = path.add(0); - editor = editor.putAttribute(path, "KEY", ByteBuffer.wrap("tatsuki".getBytes())).b(); + editor = editor.putAttribute(path, "KEY", ByteBuffer.wrap("data".getBytes())).b(); editor = editor.addNewChildAt(path, 0).b(); path = path.add(0); editor = editor.putAttribute(path, "KEY", ByteBuffer.wrap("kanagawa".getBytes())).b();
--- a/src/test/java/jp/ac/u_ryukyu/ie/cr/jungle/core/GetOldTreeTest.java Tue Sep 15 02:03:04 2015 +0900 +++ b/src/test/java/jp/ac/u_ryukyu/ie/cr/jungle/core/GetOldTreeTest.java Tue Sep 15 17:31:19 2015 +0900 @@ -29,7 +29,7 @@ for (int num = 0; num < 10; num++) { JungleTreeEditor addChildEditor = editor.addNewChildAt(path, num).b(); - JungleTreeEditor putAttributeEditor = addChildEditor.putAttribute(path.add(num), "test", ByteBuffer.wrap("tatsuki".getBytes())).b(); + JungleTreeEditor putAttributeEditor = addChildEditor.putAttribute(path.add(num), "test", ByteBuffer.wrap("data".getBytes())).b(); Either<Error, JungleTreeEditor> successEither = putAttributeEditor.success(); Assert.assertFalse(successEither.isA()); editor = successEither.b();
--- a/src/test/java/jp/ac/u_ryukyu/ie/cr/jungle/index/parentIndexTest.java Tue Sep 15 02:03:04 2015 +0900 +++ b/src/test/java/jp/ac/u_ryukyu/ie/cr/jungle/index/parentIndexTest.java Tue Sep 15 17:31:19 2015 +0900 @@ -31,7 +31,7 @@ for (int count = 0; count < 100; count++) { editor = editor.addNewChildAt(path, 0).b(); path = path.add(0); - editor = editor.putAttribute(path, "KEY", ByteBuffer.wrap(("tatsuki" + count).getBytes())).b(); + editor = editor.putAttribute(path, "KEY", ByteBuffer.wrap(("data" + count).getBytes())).b(); } Either<Error, JungleTreeEditor> either = editor.success(); @@ -40,7 +40,7 @@ ParentIndex parentIndex = tree.getParentIndex(); for (int count = 99; count >= 0; count--) { String attribute = node.getAttributes().getString("KEY"); - Assert.assertEquals(attribute, "tatsuki" + count); + Assert.assertEquals(attribute, "data" + count); node = parentIndex.get(node); } }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/jp/ac/u_ryukyu/ie/cr/junglenetwork/HashSetConvertTest.java Tue Sep 15 17:31:19 2015 +0900 @@ -0,0 +1,40 @@ +package jp.ac.u_ryukyu.ie.cr.junglenetwork; + +import alice.codesegment.CodeSegment; +import alice.datasegment.CommandType; +import alice.datasegment.Receiver; +import org.msgpack.annotation.Message; + +import java.util.HashSet; + +public class HashSetConvertTest extends CodeSegment { + + Receiver hash = ids.create(CommandType.TAKE); + + public HashSetConvertTest() { + hash.setKey("hash"); + } + + public static void main(String[] args) { + HashSetDataSegment h = new HashSetDataSegment(); + h.hash.add("test1"); + h.hash.add("test2"); + + HashSetConvertTest cs = new HashSetConvertTest(); + cs.ods.put("hash", h); + } + + public void run() { + HashSetDataSegment h = hash.asClass(HashSetDataSegment.class); + for(String s : h.hash ) { + System.out.println("s : "+s); + } + System.exit(0); + } + + @Message + private static class HashSetDataSegment { + public HashSet<String> hash = new HashSet<String>(); + public HashSetDataSegment() {} + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/jp/ac/u_ryukyu/ie/cr/junglenetwork/PersistentJournalTest.java Tue Sep 15 17:31:19 2015 +0900 @@ -0,0 +1,85 @@ +package jp.ac.u_ryukyu.ie.cr.junglenetwork; + +import jp.ac.u_ryukyu.ie.cr.jungle.Jungle; +import jp.ac.u_ryukyu.ie.cr.jungle.JungleTree; +import jp.ac.u_ryukyu.ie.cr.jungle.JungleTreeEditor; +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.NodePath; +import jp.ac.u_ryukyu.ie.cr.jungle.store.impl.DefaultTreeEditor; +import jp.ac.u_ryukyu.ie.cr.jungle.store.impl.TreeNode; +import jp.ac.u_ryukyu.ie.cr.jungle.traverser.DefaultTraverser; +import jp.ac.u_ryukyu.ie.cr.jungle.util.Either; +import jp.ac.u_ryukyu.ie.cr.jungle.util.Error; +import jp.ac.u_ryukyu.ie.cr.jungleNetwork.operations.NetworkNodePath; +import jp.ac.u_ryukyu.ie.cr.jungleNetwork.persistent.PersistentJournal; +import jp.ac.u_ryukyu.ie.cr.jungleNetwork.persistent.PersistentJungle; +import jp.ac.u_ryukyu.ie.cr.jungleNetwork.transaction.JungleUpdater; +import junit.framework.TestCase; + +import java.io.File; +import java.io.IOException; +import java.nio.ByteBuffer; + +public class PersistentJournalTest extends TestCase { + + public void testPersistentJounal() throws IOException { + PersistentJournal journal1 = new PersistentJournal(new File("./log/commit.log")); + Jungle jungle = new PersistentJungle(journal1, "uuid",new DefaultTreeEditor(new DefaultTraverser())); + jungle.createNewTree("hoge"); + JungleTree tree1 = jungle.getTreeByName("hoge"); + JungleTreeEditor editor = tree1.getTreeEditor(); + NetworkNodePath path = new NetworkNodePath(); + String key = "key"; + ByteBuffer value = ByteBuffer.wrap("value".getBytes()); + int pos = 0; + Either<Error, JungleTreeEditor> either = editor.addNewChildAt(path, pos); + NodePath childPath = path.add(pos); + assertFalse(either.isA()); + editor = either.b(); + either = editor.putAttribute(childPath, key, value); + JungleTreeEditor e = either.b(); + either = e.success(); + assertFalse(either.isA()); + + PersistentJournal journal2 = new PersistentJournal(); + journal2.setInputFile(new File("./log/"+journal1.getLogName())); + journal2.setOutputFile(new File("./log/"+journal1.getLogName())); + Jungle jungle2 = new PersistentJungle(journal1, "uuid2", new DefaultTreeEditor(new DefaultTraverser())); + ChangeListReader reader = journal2.getReader(); + for (ChangeList chList : reader) { + String treeName = chList.getTreeName(); + JungleTree tree2 = jungle2.getTreeByName(treeName); + if(tree2 == null) { + tree2 = jungle2.createNewTree(treeName); + } + JungleTreeEditor editor2 = tree2.getTreeEditor(); + Either<Error, JungleTreeEditor> either2 = JungleUpdater.edit(editor2, chList); + assertFalse(either2.isA()); + editor2 = either2.b(); + editor2.success(); + } + JungleTree tree2 = jungle2.getTreeByName("hoge"); + TreeNode node1 = tree1.getRootNode(); + TreeNode node2 = tree2.getRootNode(); + Children child1 = node1.getChildren(); + Children child2 = node2.getChildren(); + assertEquals(child1.size(), child2.size()); + Either<Error, TreeNode> either1 = child1.at(pos); + Either<Error, TreeNode> either2 = child1.at(pos); + assertFalse(either1.isA()); + assertFalse(either2.isA()); + + TreeNode nodeA = either1.b(); + TreeNode nodeB = either2.b(); + ByteBuffer bb1 = nodeA.getAttributes().get(key); + ByteBuffer bb2 = nodeB.getAttributes().get(key); + String strA = new String(bb1.array()); + String strB = new String(bb2.array()); + assertTrue(strA.equals(strB)); + journal1.close(); + journal2.close(); + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/jp/ac/u_ryukyu/ie/cr/junglenetwork/core/operations/NetworkAppendChildOperationTest.java Tue Sep 15 17:31:19 2015 +0900 @@ -0,0 +1,23 @@ +package jp.ac.u_ryukyu.ie.cr.junglenetwork.core.operations; + + +import jp.ac.u_ryukyu.ie.cr.jungleNetwork.operations.NetworkAppendChildAtOperation; +import junit.framework.TestCase; +import org.msgpack.MessagePack; +import org.msgpack.type.Value; + +import java.io.IOException; + +public class NetworkAppendChildOperationTest extends TestCase { + + public void testMsgpackConvert() throws IOException { + NetworkAppendChildAtOperation op = new NetworkAppendChildAtOperation(1); + MessagePack msgpack = new MessagePack(); + Value v = msgpack.unconvert(op); + NetworkAppendChildAtOperation mOp = msgpack.convert(v, NetworkAppendChildAtOperation.class); +// NodeOperation mOp = msgpack.convert(v, NodeOperation.class); + assertEquals(op.getCommand(), mOp.getCommand()); + assertEquals(op.getPosition(), 1); + assertEquals(op.getPosition(), mOp.getPosition()); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/jp/ac/u_ryukyu/ie/cr/junglenetwork/core/operations/NetworkDeleteAttributeOprationTest.java Tue Sep 15 17:31:19 2015 +0900 @@ -0,0 +1,24 @@ +package jp.ac.u_ryukyu.ie.cr.junglenetwork.core.operations; + + +import jp.ac.u_ryukyu.ie.cr.jungleNetwork.operations.NetworkDeleteAttributeOperation; +import junit.framework.TestCase; +import org.msgpack.MessagePack; +import org.msgpack.type.Value; + +import java.io.IOException; + +public class NetworkDeleteAttributeOprationTest extends TestCase { + + public void testMsgpackConvert() throws IOException { + NetworkDeleteAttributeOperation op = new NetworkDeleteAttributeOperation("hoge"); + MessagePack msgpack = new MessagePack(); + Value v = msgpack.unconvert(op); + NetworkDeleteAttributeOperation mOp = msgpack.convert(v, NetworkDeleteAttributeOperation.class); + assertEquals(op.getCommand(), mOp.getCommand()); + assert(mOp.getKey().equals("hoge")); + + } + + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/jp/ac/u_ryukyu/ie/cr/junglenetwork/core/operations/NetworkDeleteChildAtOperationTest.java Tue Sep 15 17:31:19 2015 +0900 @@ -0,0 +1,24 @@ +package jp.ac.u_ryukyu.ie.cr.junglenetwork.core.operations; + + +import jp.ac.u_ryukyu.ie.cr.jungleNetwork.operations.NetworkDeleteChildAtOperation; +import junit.framework.TestCase; +import org.msgpack.MessagePack; +import org.msgpack.type.Value; + +import java.io.IOException; + +public class NetworkDeleteChildAtOperationTest extends TestCase { + + + public void testMsgpackConvert() throws IOException { + NetworkDeleteChildAtOperation op = new NetworkDeleteChildAtOperation(1); + MessagePack msgpack = new MessagePack(); + Value v = msgpack.unconvert(op); + NetworkDeleteChildAtOperation mOp = msgpack.convert(v, NetworkDeleteChildAtOperation.class); + assertEquals(op.getCommand(), mOp.getCommand()); + assertEquals(op.getPosition(), mOp.getPosition()); + + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/jp/ac/u_ryukyu/ie/cr/junglenetwork/core/operations/NetworkNodeOperationTest.java Tue Sep 15 17:31:19 2015 +0900 @@ -0,0 +1,25 @@ +package jp.ac.u_ryukyu.ie.cr.junglenetwork.core.operations; + + +import jp.ac.u_ryukyu.ie.cr.jungleNetwork.operations.NetworkAppendChildAtOperation; +import jp.ac.u_ryukyu.ie.cr.jungleNetwork.operations.NetworkNodeOperation; +import junit.framework.TestCase; +import org.msgpack.MessagePack; +import org.msgpack.type.Value; + +import java.io.IOException; + +public class NetworkNodeOperationTest extends TestCase { + + public void testMsgpackConvert() throws IOException { + NetworkAppendChildAtOperation op = new NetworkAppendChildAtOperation(1); + NetworkNodeOperation nOp = new NetworkNodeOperation(op); + MessagePack msgpack = new MessagePack(); + Value v = msgpack.unconvert(nOp); + NetworkNodeOperation mOp = msgpack.convert(v, NetworkNodeOperation.class); + assertEquals(op.getCommand(), mOp.getCommand()); + assertEquals(op.getPosition(), 1); + assertEquals(op.getPosition(), mOp.getPosition()); + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/jp/ac/u_ryukyu/ie/cr/junglenetwork/core/operations/NetworkPutAttributeOperationTest.java Tue Sep 15 17:31:19 2015 +0900 @@ -0,0 +1,25 @@ +package jp.ac.u_ryukyu.ie.cr.junglenetwork.core.operations; + + +import jp.ac.u_ryukyu.ie.cr.jungleNetwork.operations.NetworkPutAttributeOperation; +import junit.framework.TestCase; +import org.msgpack.MessagePack; +import org.msgpack.type.Value; + +import java.io.IOException; +import java.nio.ByteBuffer; + +public class NetworkPutAttributeOperationTest extends TestCase { + + public void testMsgpackConvert() throws IOException { + ByteBuffer value = ByteBuffer.allocate(16); + value.put( "fuga".getBytes()); + NetworkPutAttributeOperation op = new NetworkPutAttributeOperation("hoge", value); + MessagePack msgpack = new MessagePack(); + Value v = msgpack.unconvert(op); + NetworkPutAttributeOperation mOp = msgpack.convert(v, NetworkPutAttributeOperation.class); + assertEquals(op.getCommand(), mOp.getCommand()); + assert((new String(op.getValue().array())).equals(new String(mOp.getValue().array()))); + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/jp/ac/u_ryukyu/ie/cr/junglenetwork/core/operations/NetworkTreeOperationLogTest.java Tue Sep 15 17:31:19 2015 +0900 @@ -0,0 +1,29 @@ +package jp.ac.u_ryukyu.ie.cr.junglenetwork.core.operations; + + +import jp.ac.u_ryukyu.ie.cr.jungleNetwork.operations.NetworkAppendChildAtOperation; +import jp.ac.u_ryukyu.ie.cr.jungleNetwork.operations.NetworkNodePath; +import jp.ac.u_ryukyu.ie.cr.jungleNetwork.operations.NetworkTreeOperationLog; +import junit.framework.TestCase; +import org.msgpack.MessagePack; +import org.msgpack.type.Value; + +import java.io.IOException; + +public class NetworkTreeOperationLogTest extends TestCase { + + public void testMsgpackConvert() throws IOException { + NetworkAppendChildAtOperation op = new NetworkAppendChildAtOperation(1); + NetworkNodePath path = new NetworkNodePath(); + path.add(1).add(2); + NetworkTreeOperationLog log = new NetworkTreeOperationLog(); + log.add(path, op); + log.add(path, op); + MessagePack msgpack = new MessagePack(); + Value v = msgpack.unconvert(log); + NetworkTreeOperationLog mLog = msgpack.convert(v, NetworkTreeOperationLog.class); + assertNotNull(mLog); + + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/jp/ac/u_ryukyu/ie/cr/junglenetwork/core/operations/NetworkTreeOperationTest.java Tue Sep 15 17:31:19 2015 +0900 @@ -0,0 +1,27 @@ +package jp.ac.u_ryukyu.ie.cr.junglenetwork.core.operations; + + +import jp.ac.u_ryukyu.ie.cr.jungleNetwork.operations.NetworkAppendChildAtOperation; +import jp.ac.u_ryukyu.ie.cr.jungleNetwork.operations.NetworkNodePath; +import jp.ac.u_ryukyu.ie.cr.jungleNetwork.operations.NetworkTreeOperation; +import junit.framework.TestCase; +import org.msgpack.MessagePack; +import org.msgpack.type.Value; + +import java.io.IOException; + +public class NetworkTreeOperationTest extends TestCase { + + public void testMsgpackConvert() throws IOException { + NetworkAppendChildAtOperation op = new NetworkAppendChildAtOperation(1); + NetworkNodePath path = new NetworkNodePath(); + path.add(1).add(2); + NetworkTreeOperation treeOp = new NetworkTreeOperation(path, op); + MessagePack msgpack = new MessagePack(); + Value v = msgpack.unconvert(treeOp); + NetworkTreeOperation mOp = msgpack.convert(v, NetworkTreeOperation.class); + assertNotNull(mOp.getNodePath()); + assertEquals(op.getCommand(), mOp.getNodeOperation().getCommand()); + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/jp/ac/u_ryukyu/ie/cr/junglenetwork/datasegment/NetworkNodePathTest.java Tue Sep 15 17:31:19 2015 +0900 @@ -0,0 +1,32 @@ +package jp.ac.u_ryukyu.ie.cr.junglenetwork.datasegment; + + +import jp.ac.u_ryukyu.ie.cr.jungleNetwork.operations.NetworkNodePath; +import junit.framework.TestCase; +import org.msgpack.MessagePack; +import org.msgpack.type.Value; + +import java.io.IOException; +import java.util.Iterator; + +public class NetworkNodePathTest extends TestCase { + + public void testMsgpackConvert() throws IOException { + NetworkNodePath path = new NetworkNodePath(); + path = path.add(1).add(2).add(3); + MessagePack msgpack = new MessagePack(); + Value value = msgpack.unconvert(path); + NetworkNodePath mPath = msgpack.convert(value, NetworkNodePath.class); + assertEquals(path.size(), mPath.size()); + Iterator<Integer> iter1 = path.iterator(); + Iterator<Integer> iter2 = mPath.iterator(); + while(iter1.hasNext() & iter2.hasNext()) { + int i1 = iter1.next(); + int i2 = iter2.next(); + assertEquals(i1, i2); + } + } + + + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/jp/ac/u_ryukyu/ie/cr/junglenetwork/showMessageTest.java Tue Sep 15 17:31:19 2015 +0900 @@ -0,0 +1,54 @@ +package jp.ac.u_ryukyu.ie.cr.junglenetwork; + +import jp.ac.u_ryukyu.ie.cr.jungleNetwork.bbs.codesegment.StartBBSCodeSegment; +import jp.ac.u_ryukyu.ie.cr.jungleNetwork.remote.RemoteConfig; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.InputStreamReader; +import java.io.OutputStreamWriter; +import java.net.Socket; + + +public class showMessageTest { + + public static void main(String args[]) throws Exception { + String host = "localhost"; + int port = 8080; + String path = "/showBoardMessage?bname=" + args[0]; + String url = "http://" + host + ":" + port + path; + String str; + System.out.println(url); + RemoteConfig conf = new RemoteConfig(args); + StartBBSCodeSegment cs1 = new StartBBSCodeSegment(args, conf.bbsPort); + cs1.ods.put("host", "node0"); + BufferedReader input = new BufferedReader(new InputStreamReader( + System.in)); + Thread.sleep(1000); + + do{ + try { + Socket socket = new Socket(host, port); + BufferedReader readSocket = new BufferedReader( + new InputStreamReader(socket.getInputStream())); + BufferedWriter writeSocket = new BufferedWriter( + new OutputStreamWriter(socket.getOutputStream())); + + writeSocket.write("GET " + url + " HTTP/1.1\r\n"); + writeSocket.write("Host: " + host + "\n"); + writeSocket.write("\n"); + writeSocket.flush(); + while ((str = readSocket.readLine()) != null) { + System.out.println(str); + } + writeSocket.close(); + readSocket.close(); + socket.close(); + System.out.println("please input connection tree name or quit"); + + } catch (Exception ex) { + ex.printStackTrace(); + } + }while(input.readLine() != "quit"); + } +}
--- a/src/test/java/jp/ac/u_ryukyu/ie/cr/tatsuki/list/appendTest.java Tue Sep 15 02:03:04 2015 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,35 +0,0 @@ -package jp.ac.u_ryukyu.ie.cr.tatsuki.list; - -import jp.ac.u_ryukyu.ie.cr.jungle.data.list.List; -import junit.framework.Assert; -import org.junit.Test; - -import java.util.Iterator; - -/** - * Created by e115731 on 15/05/19. - */ -public class appendTest { - @Test - public void appendTest() { - - List<Integer> list = new List<>(); - for (int count = 1; count <= 10; count++) { - list = list.addLast(count); - } - - List<Integer> list2 = new List<>(); - for (int count = 11; count <= 20; count++) { - list2 = list2.addLast(count); - } - - List<Integer> newList = list.append(list2); - Iterator<Integer> iterator = newList.iterator(); - for (int count = 1; count <= 20; count++) { - Assert.assertTrue(iterator.hasNext()); - int num = iterator.next(); - Assert.assertEquals(num, count); - } - - } -}
--- a/src/test/java/jp/ac/u_ryukyu/ie/cr/tatsuki/list/deleteTest.java Tue Sep 15 02:03:04 2015 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,29 +0,0 @@ -package jp.ac.u_ryukyu.ie.cr.tatsuki.list; - -import jp.ac.u_ryukyu.ie.cr.jungle.data.list.List; -import junit.framework.Assert; -import org.junit.Test; - -/** - * Created by e115731 on 15/05/18. - */ -public class deleteTest { - @Test - public void deleteTest() { - List<Integer> list = new List<Integer>(); - - for (int count = 0; count < 10; count++) { - list = list.addLast(count); - } - List<Integer> newList = list.delete(5); - Assert.assertEquals(newList.length(),9); - newList = newList.deleteHead(); - int attribute = newList.index(1); - Assert.assertEquals(attribute,2); - Assert.assertEquals(newList.length(),8); - newList = newList.deleteLast(); - attribute = newList.index(6); - Assert.assertEquals(attribute,8); - Assert.assertEquals(list.length(),10); - } -}
--- a/src/test/java/jp/ac/u_ryukyu/ie/cr/tatsuki/list/listAdd.java Tue Sep 15 02:03:04 2015 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,39 +0,0 @@ -package jp.ac.u_ryukyu.ie.cr.tatsuki.list; - -import jp.ac.u_ryukyu.ie.cr.jungle.data.list.List; -import junit.framework.Assert; -import org.junit.Test; - -/** - * Created by e115731 on 15/05/17. - */ -public class listAdd { - - @Test - public void listAddTest() { - - List<Integer> list = new List<Integer>(); - List<Integer> list2 = new List<Integer>(); - - for (int count = 0; count < 10; count++) { - list = list.addLast(count); - list2 = list2.add(count, count); - } - - for (int count = 0; count < 10; count++) { - int num = list.index(count); - int num2 = list2.index(count); - Assert.assertEquals(num,count); - Assert.assertEquals(num2,count); - } - - List<Integer> newList = list.add(5, 50); - int num = list.index(5); - int num2 = newList.index(5); - Assert.assertEquals(num,5); - Assert.assertEquals(num2,50); - - } - - -}
--- a/src/test/java/jp/ac/u_ryukyu/ie/cr/tatsuki/list/listIterator.java Tue Sep 15 02:03:04 2015 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,33 +0,0 @@ -package jp.ac.u_ryukyu.ie.cr.tatsuki.list; - -import jp.ac.u_ryukyu.ie.cr.jungle.data.list.List; -import junit.framework.Assert; -import org.junit.Test; - -import java.util.Iterator; - -/** - * Created by e115731 on 15/05/17. - */ -public class listIterator { - @Test - public void listIteratorTest() { - List<Integer> list = new List<Integer>(); - for (int count = 1; count < 10; count++) { - list = list.addLast(count); - } - Iterator<Integer> iterator = list.iterator(); - for (int count = 1; count < 10; count++) { - Assert.assertTrue(iterator.hasNext()); - int attribute = iterator.next(); - Assert.assertEquals(attribute, count); - } - - iterator = list.reverseIterator(); - for (int count = 9; count > 0; count--) { - Assert.assertTrue(iterator.hasNext()); - int attribute = iterator.next(); - Assert.assertEquals(attribute, count); - } - } -}
--- a/src/test/java/jp/ac/u_ryukyu/ie/cr/tatsuki/list/replaceTest.java Tue Sep 15 02:03:04 2015 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,25 +0,0 @@ -package jp.ac.u_ryukyu.ie.cr.tatsuki.list; - -import jp.ac.u_ryukyu.ie.cr.jungle.data.list.List; -import junit.framework.Assert; -import org.junit.Test; - -/** - * Created by e115731 on 15/05/18. - */ -public class replaceTest { - @Test - public void replaceTest() { - List<Integer> list = new List<Integer>(); - for (int count = 0; count < 10; count++) { - list = list.addLast(count); - } - List<Integer> newList = list.replace(5, 15); - Assert.assertEquals(list.length(), 10); - int attribute = list.index(5); - Assert.assertEquals(attribute, 5); - attribute = newList.index(5); - Assert.assertEquals(newList.length(), 10); - Assert.assertEquals(attribute, 15); - } -}
--- a/src/test/java/jp/ac/u_ryukyu/ie/cr/tatsuki/treemap/TreeMapDelete.java Tue Sep 15 02:03:04 2015 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,32 +0,0 @@ -package jp.ac.u_ryukyu.ie.cr.tatsuki.treemap; - -import jp.ac.u_ryukyu.ie.cr.jungle.data.treemap.RotateParent; -import jp.ac.u_ryukyu.ie.cr.jungle.data.treemap.TreeMap; -import org.junit.Test; - -import java.util.ArrayList; -import java.util.Collections; - -public class TreeMapDelete { - - @Test - public void TreeMapDeleteTest() throws RotateParent { - TreeMap<Integer, Integer> map = new TreeMap<>(); - for (int count = 1; count < 1000; count++) { - map = map.put(count, count); - map.checkDepth(); - } - - ArrayList<Integer> list = new ArrayList<>(); - for (int i = 1; i < 1000; i++) { - list.add(i); - } - Collections.shuffle(list); - for (Integer num : list) { - System.out.println(num); - map = map.delete(num); - map.checkDepth(); - } - System.out.println("end"); - } -}
--- a/src/test/java/jp/ac/u_ryukyu/ie/cr/tatsuki/treemap/TreeMapTest.java Tue Sep 15 02:03:04 2015 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,43 +0,0 @@ -package jp.ac.u_ryukyu.ie.cr.tatsuki.treemap; - -import jp.ac.u_ryukyu.ie.cr.jungle.data.treemap.TreeMap; -import org.junit.Test; - -import java.util.Optional; - -public class TreeMapTest { - - @Test - public void TreeMapTest() { - TreeMap<Integer, Integer> map = new TreeMap<>(); - for (int count = 100; count > -10; count--) { - map = map.put(count, count); - map.checkDepth(); - System.out.println("-------------------------------------------"); - } - - for (int count = 100; count > -10; count--) { - - Optional<Integer> op = map.get(count); - if (op.isPresent()) - System.out.println(op.get()); - } - - System.out.println("end"); - } -} - - - - - - - - - - - - - - -
--- a/src/test/java/jp/ac/u_ryukyu/ie/cr/tatsuki/treemap/TreeNodeIteratorTest.java Tue Sep 15 02:03:04 2015 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,30 +0,0 @@ -package jp.ac.u_ryukyu.ie.cr.tatsuki.treemap; - -import jp.ac.u_ryukyu.ie.cr.jungle.data.treemap.TreeMap; -import junit.framework.Assert; -import org.junit.Test; - -import java.util.Iterator; - -/** - * Created by e115731 on 15/05/06. - */ -public class TreeNodeIteratorTest { - @Test - public void getKeyTest() { - TreeMap<Integer, Integer> map = new TreeMap(); - for (int attributeMaxCount = 10; attributeMaxCount < 1000; attributeMaxCount = attributeMaxCount + 10) { - for (int count = 0; count < attributeMaxCount; count++) { //insertData - map = map.put(count, count); - } - Iterator<Integer> it = map.keys(); - int iteratorCount = 0; - while (it.hasNext()) { // count return iterator Attribute Count - iteratorCount++; - System.out.println(it.next()); - } - Assert.assertTrue(iteratorCount == attributeMaxCount); // check - } - - } -}