Mercurial > hg > Database > jungle-network
changeset 133:00fcb468de27
Rename to BulletinBoardJungleManager
author | Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Sat, 11 Jan 2014 09:30:57 +0900 |
parents | 0b3375dee51d |
children | a6fa10e42601 |
files | src/main/java/app/bbs/BullentInBoardJungleManager.java src/main/java/app/bbs/BulletinBoardJungleManager.java src/main/java/app/bbs/NetworkJungleBulletinBoard.java src/main/java/app/bbs/codesegment/LogUpdateCodeSegment.java |
diffstat | 4 files changed, 88 insertions(+), 88 deletions(-) [+] |
line wrap: on
line diff
--- a/src/main/java/app/bbs/BullentInBoardJungleManager.java Sat Jan 11 09:29:57 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,85 +0,0 @@ -package app.bbs; - -import java.nio.ByteBuffer; - -import alice.jungle.operations.NetworkTreeOperationLog; -import alice.jungle.transaction.JungleUpdater; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.DefaultJungle; -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.store.impl.DefaultTreeEditor; -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 BullentInBoardJungleManager { - private static BullentInBoardJungleManager instance = new BullentInBoardJungleManager(); - private Jungle jungle; - - private BullentInBoardJungleManager() { - jungle = new DefaultJungle(null,"default",new DefaultTreeEditor(new DefaultTraverser())); - } - - public static BullentInBoardJungleManager getInstantce() { - return instance; - } - - public static void setJungle(Jungle _j) { - instance.jungle = _j; - } - - 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 = BullentInBoardJungleManager.getJungle(); - if (jungle.getTreeByName(treeName) == null) { - if(null == jungle.createNewTree(treeName)){ - throw new IllegalStateException(); - } - } - Either<Error, JungleTreeEditor> either = null; - do { - JungleTree tree = jungle.getTreeByName(treeName); - 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.success(); - }while(either.isA()); - return either; - } - - private static int calculatePosition(Node node, long newNodeTimeStamp) { - int count = 0; - long childTimeStamp = 0; - for(Node n : node.getChildren()) { - ByteBuffer timestamp = n.getAttributes().get("timestamp"); - if(timestamp == null) { - return count; - } - childTimeStamp = timestamp.getLong(); - if (newNodeTimeStamp < childTimeStamp) { - break; - } - count++; - } - return count; - } -}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/app/bbs/BulletinBoardJungleManager.java Sat Jan 11 09:30:57 2014 +0900 @@ -0,0 +1,85 @@ +package app.bbs; + +import java.nio.ByteBuffer; + +import alice.jungle.operations.NetworkTreeOperationLog; +import alice.jungle.transaction.JungleUpdater; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.DefaultJungle; +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.store.impl.DefaultTreeEditor; +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 BulletinBoardJungleManager { + private static BulletinBoardJungleManager instance = new BulletinBoardJungleManager(); + private Jungle jungle; + + private BulletinBoardJungleManager() { + jungle = new DefaultJungle(null,"default",new DefaultTreeEditor(new DefaultTraverser())); + } + + public static BulletinBoardJungleManager getInstantce() { + return instance; + } + + public static void setJungle(Jungle _j) { + instance.jungle = _j; + } + + 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; + do { + JungleTree tree = jungle.getTreeByName(treeName); + 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.success(); + }while(either.isA()); + return either; + } + + private static int calculatePosition(Node node, long newNodeTimeStamp) { + int count = 0; + long childTimeStamp = 0; + for(Node n : node.getChildren()) { + ByteBuffer timestamp = n.getAttributes().get("timestamp"); + if(timestamp == null) { + return count; + } + childTimeStamp = timestamp.getLong(); + if (newNodeTimeStamp < childTimeStamp) { + break; + } + count++; + } + return count; + } +}
--- a/src/main/java/app/bbs/NetworkJungleBulletinBoard.java Sat Jan 11 09:29:57 2014 +0900 +++ b/src/main/java/app/bbs/NetworkJungleBulletinBoard.java Sat Jan 11 09:30:57 2014 +0900 @@ -30,7 +30,7 @@ { jungle = new NetworkDefaultJungle(new AliceJournal(), _uuid,new DefaultTreeEditor(new DefaultTraverser())); jungle.createNewTree("boards"); - BullentInBoardJungleManager.setJungle(jungle); + BulletinBoardJungleManager.setJungle(jungle); } public void init() {
--- a/src/main/java/app/bbs/codesegment/LogUpdateCodeSegment.java Sat Jan 11 09:29:57 2014 +0900 +++ b/src/main/java/app/bbs/codesegment/LogUpdateCodeSegment.java Sat Jan 11 09:30:57 2014 +0900 @@ -6,7 +6,7 @@ import alice.datasegment.CommandType; import alice.datasegment.Receiver; import alice.jungle.operations.NetworkTreeOperationLog; -import app.bbs.BullentInBoardJungleManager; +import app.bbs.BulletinBoardJungleManager; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.JungleTreeEditor; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Either; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Error; @@ -32,7 +32,7 @@ @SuppressWarnings("unchecked") List<String> list = clist.asClass(List.class); if (!log.from.equals("local")) { - Either<Error, JungleTreeEditor> either = BullentInBoardJungleManager.update(netLog); + Either<Error, JungleTreeEditor> either = BulletinBoardJungleManager.update(netLog); if(either.isA()) { /* Should throw after new LogUpdateCodeSegment */ throw new IllegalStateException();