Mercurial > hg > Database > jungle-network
changeset 116:895ab2907db3
Modified pom.xml
author | one |
---|---|
date | Fri, 20 Dec 2013 20:47:35 +0900 |
parents | 3f9c6ab43461 |
children | 24fdf5126f4d |
files | pom.xml src/main/java/alice/jungle/persistent/AliceJournal.java src/main/java/alice/jungle/persistent/PersistentChangeListReader.java src/main/java/alice/jungle/persistent/PersistentChangeListWriter.java src/main/java/alice/jungle/persistent/PersistentJournal.java src/main/java/app/bbs/JungleManager.java src/test/java/alice/jungle/PersistenJournalTest.java src/test/java/alice/jungle/PersistentJournalTest.java |
diffstat | 8 files changed, 51 insertions(+), 131 deletions(-) [+] |
line wrap: on
line diff
--- a/pom.xml Fri Dec 20 06:51:35 2013 +0900 +++ b/pom.xml Fri Dec 20 20:47:35 2013 +0900 @@ -2,7 +2,8 @@ <modelVersion>4.0.0</modelVersion> <groupId>jungle-network</groupId> <artifactId>jungle-network</artifactId> - <version>0.0.2-SNAPSHOT</version> + <packaging>pom</packaging> + <version>0.0.2-SNAPSHOT</version> <build> <sourceDirectory>src/main/java</sourceDirectory> <testSourceDirectory>src/test/java</testSourceDirectory> @@ -43,7 +44,7 @@ </plugins> </build> - <properties> + <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties> <dependencies> @@ -90,12 +91,13 @@ <version>3.1</version> </dependency> +<!-- <dependency> <groupId>alice</groupId> <artifactId>alice</artifactId> <version>0.2</version> </dependency> - +--> <dependency> <groupId>org.msgpack</groupId> <artifactId>msgpack</artifactId>
--- a/src/main/java/alice/jungle/persistent/AliceJournal.java Fri Dec 20 06:51:35 2013 +0900 +++ b/src/main/java/alice/jungle/persistent/AliceJournal.java Fri Dec 20 20:47:35 2013 +0900 @@ -1,5 +1,7 @@ package alice.jungle.persistent; +import java.util.Iterator; + import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.persistent.ChangeList; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.persistent.ChangeListReader; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.persistent.ChangeListWriter; @@ -70,6 +72,12 @@ { return null; } + + @Override + public Iterator<ChangeList> iterator() { + return null; + } + }
--- a/src/main/java/alice/jungle/persistent/PersistentChangeListReader.java Fri Dec 20 06:51:35 2013 +0900 +++ b/src/main/java/alice/jungle/persistent/PersistentChangeListReader.java Fri Dec 20 20:47:35 2013 +0900 @@ -3,6 +3,7 @@ import java.io.EOFException; import java.io.IOException; import java.io.InputStream; +import java.util.Iterator; import org.msgpack.MessagePack; @@ -13,7 +14,7 @@ public class PersistentChangeListReader implements ChangeListReader { private InputStream in; - MessagePack msgpack = PersistentJournal.getMessagePack(); + MessagePack msgpack = PersistentJournal.getMsgPackInstance(); public PersistentChangeListReader() { in = null; @@ -42,4 +43,29 @@ } 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() { + + } + }; + } }
--- a/src/main/java/alice/jungle/persistent/PersistentChangeListWriter.java Fri Dec 20 06:51:35 2013 +0900 +++ b/src/main/java/alice/jungle/persistent/PersistentChangeListWriter.java Fri Dec 20 20:47:35 2013 +0900 @@ -13,7 +13,7 @@ public class PersistentChangeListWriter implements ChangeListWriter { - MessagePack msgpack = PersistentJournal.getMessagePack(); + MessagePack msgpack = PersistentJournal.getMsgPackInstance(); OutputStream out; public PersistentChangeListWriter(OutputStream _out) { @@ -29,6 +29,7 @@ out.flush(); return Result.SUCCESS; } catch (IOException e) { + } return null; }
--- a/src/main/java/alice/jungle/persistent/PersistentJournal.java Fri Dec 20 06:51:35 2013 +0900 +++ b/src/main/java/alice/jungle/persistent/PersistentJournal.java Fri Dec 20 20:47:35 2013 +0900 @@ -18,10 +18,14 @@ private static ChangeListWriter WRITER; private static ChangeListReader READER; - private static MessagePack msgpack = new MessagePack(); + private static MessagePack msgpack; private static OutputStream out = null; private static InputStream in = null; + static { + msgpack = new MessagePack(); + } + public PersistentJournal() { } @@ -73,7 +77,7 @@ return in; } - public static MessagePack getMessagePack() { + public static MessagePack getMsgPackInstance() { return msgpack; }
--- a/src/main/java/app/bbs/JungleManager.java Fri Dec 20 06:51:35 2013 +0900 +++ b/src/main/java/app/bbs/JungleManager.java Fri Dec 20 20:47:35 2013 +0900 @@ -26,7 +26,7 @@ private static int NOT_CHANGE_POSITION = 0; private JungleManager() { - jungle = new DefaultJungle(null,"hogehoge",new DefaultTreeEditor(new DefaultTraverser())); + jungle = new DefaultJungle(null,"default",new DefaultTreeEditor(new DefaultTraverser())); } public static JungleManager getInstantce() { @@ -42,7 +42,7 @@ } public static JungleTree createNewTree(String name) { - return instance.jungle.createNewTree(name); + return instance.jungle.createNewTree(name); } public static Either<Error, JungleTreeEditor> edit(JungleTreeEditor _editor ,TreeOperationLog _log, int pos) {
--- a/src/test/java/alice/jungle/PersistenJournalTest.java Fri Dec 20 06:51:35 2013 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,116 +0,0 @@ -package alice.jungle; - -import java.io.File; -import java.io.IOException; -import java.nio.ByteBuffer; - -import alice.jungle.operations.NetworkNodePath; -import alice.jungle.persistent.PersistentChangeList; -import alice.jungle.persistent.PersistentJournal; -import alice.jungle.persistent.PersistentJungle; -import alice.jungle.transaction.JungleUpdater; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.Jungle; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.JungleTree; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.JungleTreeEditor; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.core.Node; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.persistent.ChangeList; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.persistent.ChangeListReader; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.Command; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.NodePath; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.DefaultTreeEditor; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.NodeOperation; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.TreeOperation; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.traverser.DefaultTraverser; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Either; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Error; - -public class PersistenJournalTest { - - public static void main(String[] args) throws IOException { - PersistentJournal journal = new PersistentJournal( - new File("./log/commit.log")); - Jungle jungle = new PersistentJungle(journal, "uuid",new DefaultTreeEditor(new DefaultTraverser())); - jungle.createNewTree("hoge"); - JungleTree tree = jungle.getTreeByName("hoge"); - JungleTreeEditor editor = tree.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); - if(either.isA()){ - System.out.println("Failed addNewChildAt"); - System.exit(0); - } - editor = either.b(); - either = editor.putAttribute(path, key, value); - JungleTreeEditor e = either.b(); - e.success(); - journal.close(); - - PersistentJournal journal2 = new PersistentJournal(); - journal2.setInputFile(new File("./log/commit.log")); - journal2.setOutputFile(new File("./log/commit2.log")); - Jungle jungle2 = new PersistentJungle(journal, "uuid2", new DefaultTreeEditor(new DefaultTraverser())); - ChangeListReader reader = journal2.getReader(); - PersistentChangeList chList = (PersistentChangeList) reader.read(); - for (; chList != null; chList = (PersistentChangeList) reader.read()) { - String treeName = chList.getTreeName(); - JungleTree tree2 = jungle2.getTreeByName(treeName); - if(tree2 == null) { - tree2 = jungle2.createNewTree(treeName); - } - System.out.println("Tree name :"+treeName); - JungleTreeEditor editor2 = tree2.getTreeEditor(); - Either<Error, JungleTreeEditor> either2 = JungleUpdater.edit(editor2, chList.getTreeOperationLog()); - if (either2.isA()) { - System.err.println("JungleUpdater Error"); - System.exit(0); - } - editor2 = either2.b(); - editor2.success(); - printChangeList(chList); - System.out.println(); - } - JungleTree tree2 = jungle2.getTreeByName("hoge"); - Node node = tree2.getRootNode(); - System.out.println("Children size : "+node.getChildren().size()); - - journal2.close(); - - } - - public static void printChangeList(ChangeList chList) { - for (TreeOperation op : chList) { - NodePath p = op.getNodePath(); - NodeOperation nodeOp = op.getNodeOperation(); - Command c = nodeOp.getCommand(); - String str = ""; - switch (c) { - case PUT_ATTRIBUTE: - String opKey = nodeOp.getKey(); - ByteBuffer opValue = nodeOp.getValue(); - if (opValue.limit() < 100) { - str = String.format("key:%s,value:%s", opKey, - new String(opValue.array())); - } else { - str = String.format("key:%s,value:%d", opKey, - opValue.limit()); - } - break; - case DELETE_ATTRIBUTE: - str = String.format("key:%s", nodeOp.getKey()); - break; - case APPEND_CHILD: - str = String.format("pos:%d", nodeOp.getPosition()); - break; - case DELETE_CHILD: - str = String.format("pos:%d", nodeOp.getPosition()); - break; - } - System.out.println(String.format("[%s:%s:%s]", c, p, str)); - } - - } - -}
--- a/src/test/java/alice/jungle/PersistentJournalTest.java Fri Dec 20 06:51:35 2013 +0900 +++ b/src/test/java/alice/jungle/PersistentJournalTest.java Fri Dec 20 20:47:35 2013 +0900 @@ -5,7 +5,6 @@ import java.nio.ByteBuffer; import alice.jungle.operations.NetworkNodePath; -import alice.jungle.persistent.PersistentChangeList; import alice.jungle.persistent.PersistentJournal; import alice.jungle.persistent.PersistentJungle; import alice.jungle.transaction.JungleUpdater; @@ -16,11 +15,8 @@ import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.core.Node; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.persistent.ChangeList; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.persistent.ChangeListReader; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.Command; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.NodePath; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.DefaultTreeEditor; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.NodeOperation; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.TreeOperation; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.traverser.DefaultTraverser; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Either; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Error; @@ -52,8 +48,7 @@ journal2.setOutputFile(new File("./log/commit2.log")); Jungle jungle2 = new PersistentJungle(journal1, "uuid2", new DefaultTreeEditor(new DefaultTraverser())); ChangeListReader reader = journal2.getReader(); - ChangeList chList = reader.read(); - for (; chList != null; chList = reader.read()) { + for (ChangeList chList : reader) {// != null; chList = reader.read()) { String treeName = chList.getTreeName(); JungleTree tree2 = jungle2.getTreeByName(treeName); if(tree2 == null) {