Mercurial > hg > Members > shoshi > jungle > bbs
changeset 20:7164db5bc76f
fix BulltinBoardJungleamanager singleton
line wrap: on
line diff
--- a/.idea/gradle.xml Mon Aug 07 19:37:14 2017 +0900 +++ b/.idea/gradle.xml Mon Aug 28 11:14:19 2017 +0900 @@ -4,17 +4,29 @@ <option name="linkedExternalProjectsSettings"> <GradleProjectSettings> <option name="distributionType" value="DEFAULT_WRAPPED" /> + <option name="externalProjectPath" value="$PROJECT_DIR$/../Alice" /> + <option name="modules"> + <set> + <option value="$PROJECT_DIR$/../Alice" /> + </set> + </option> + </GradleProjectSettings> + <GradleProjectSettings> + <option name="distributionType" value="DEFAULT_WRAPPED" /> <option name="externalProjectPath" value="$PROJECT_DIR$" /> - <option name="gradleHome" value="/usr/local/share/gradle" /> <option name="gradleJvm" value="1.8" /> <option name="modules"> <set> <option value="$PROJECT_DIR$" /> </set> </option> - <option name="myModules"> + </GradleProjectSettings> + <GradleProjectSettings> + <option name="distributionType" value="DEFAULT_WRAPPED" /> + <option name="externalProjectPath" value="$PROJECT_DIR$/../jungle-core" /> + <option name="modules"> <set> - <option value="$PROJECT_DIR$" /> + <option value="$PROJECT_DIR$/../jungle-core" /> </set> </option> </GradleProjectSettings>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/.idea/libraries/Gradle__com_googlecode_json_simple_json_simple_1_1.xml Mon Aug 28 11:14:19 2017 +0900 @@ -0,0 +1,11 @@ +<component name="libraryTable"> + <library name="Gradle: com.googlecode.json-simple:json-simple:1.1"> + <CLASSES> + <root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/com.googlecode.json-simple/json-simple/1.1/5e303a03d04e6788dddfa3655272580ae0fc13bb/json-simple-1.1.jar!/" /> + </CLASSES> + <JAVADOC /> + <SOURCES> + <root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/com.googlecode.json-simple/json-simple/1.1/19c6d8dee6803c520d855ff7e8a8c3d97f1271ec/json-simple-1.1-sources.jar!/" /> + </SOURCES> + </library> +</component> \ No newline at end of file
--- a/.idea/libraries/Gradle__cr_ie_u_ryukyu_ac_jp_jungle_core_1_1.xml Mon Aug 07 19:37:14 2017 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,9 +0,0 @@ -<component name="libraryTable"> - <library name="Gradle: cr.ie.u_ryukyu.ac.jp:jungle-core:1.1"> - <CLASSES> - <root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/cr.ie.u_ryukyu.ac.jp/jungle-core/1.1/9b1f7a72c78b7926d1216c5a93c3e32fdf167ac2/jungle-core-1.1.jar!/" /> - </CLASSES> - <JAVADOC /> - <SOURCES /> - </library> -</component> \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/.idea/libraries/Gradle__log4j_log4j_1_2_16.xml Mon Aug 28 11:14:19 2017 +0900 @@ -0,0 +1,11 @@ +<component name="libraryTable"> + <library name="Gradle: log4j:log4j:1.2.16"> + <CLASSES> + <root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/log4j/log4j/1.2.16/7999a63bfccbc7c247a9aea10d83d4272bd492c6/log4j-1.2.16.jar!/" /> + </CLASSES> + <JAVADOC /> + <SOURCES> + <root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/log4j/log4j/1.2.16/bf945d1dc995be7fe64923625f842fbb6bf443be/log4j-1.2.16-sources.jar!/" /> + </SOURCES> + </library> +</component> \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/.idea/libraries/Gradle__org_javassist_javassist_3_15_0_GA.xml Mon Aug 28 11:14:19 2017 +0900 @@ -0,0 +1,11 @@ +<component name="libraryTable"> + <library name="Gradle: org.javassist:javassist:3.15.0-GA"> + <CLASSES> + <root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/org.javassist/javassist/3.15.0-GA/79907309ca4bb4e5e51d4086cc4179b2611358d7/javassist-3.15.0-GA.jar!/" /> + </CLASSES> + <JAVADOC /> + <SOURCES> + <root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/org.javassist/javassist/3.15.0-GA/24e165af184887051239ff53425a70734c46db52/javassist-3.15.0-GA-sources.jar!/" /> + </SOURCES> + </library> +</component> \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/.idea/libraries/Gradle__org_msgpack_msgpack_0_6_0.xml Mon Aug 28 11:14:19 2017 +0900 @@ -0,0 +1,11 @@ +<component name="libraryTable"> + <library name="Gradle: org.msgpack:msgpack:0.6.0"> + <CLASSES> + <root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/org.msgpack/msgpack/0.6.0/cbd6d267fcc19690de301473a59efdd1ce91809/msgpack-0.6.0.jar!/" /> + </CLASSES> + <JAVADOC /> + <SOURCES> + <root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/org.msgpack/msgpack/0.6.0/c99290e65513e88676c544ae85b8a9459a5ea8b6/msgpack-0.6.0-sources.jar!/" /> + </SOURCES> + </library> +</component> \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/.idea/libraries/Gradle__org_slf4j_slf4j_log4j12_1_6_1.xml Mon Aug 28 11:14:19 2017 +0900 @@ -0,0 +1,11 @@ +<component name="libraryTable"> + <library name="Gradle: org.slf4j:slf4j-log4j12:1.6.1"> + <CLASSES> + <root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/org.slf4j/slf4j-log4j12/1.6.1/bd245d6746cdd4e6203e976e21d597a46f115802/slf4j-log4j12-1.6.1.jar!/" /> + </CLASSES> + <JAVADOC /> + <SOURCES> + <root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/org.slf4j/slf4j-log4j12/1.6.1/7a26b08b265f55622fa1fed3bda68bbd37a465ba/slf4j-log4j12-1.6.1-sources.jar!/" /> + </SOURCES> + </library> +</component> \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/.idea/misc.xml Mon Aug 28 11:14:19 2017 +0900 @@ -0,0 +1,6 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project version="4"> + <component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="1.8" project-jdk-type="JavaSDK"> + <output url="file://$PROJECT_DIR$/classes" /> + </component> +</project> \ No newline at end of file
--- a/.idea/modules.xml Mon Aug 07 19:37:14 2017 +0900 +++ b/.idea/modules.xml Mon Aug 28 11:14:19 2017 +0900 @@ -2,7 +2,15 @@ <project version="4"> <component name="ProjectModuleManager"> <modules> + <module fileurl="file://$PROJECT_DIR$/.idea/modules/Alice.iml" filepath="$PROJECT_DIR$/.idea/modules/Alice.iml" /> + <module fileurl="file://$PROJECT_DIR$/.idea/modules/Alice_main.iml" filepath="$PROJECT_DIR$/.idea/modules/Alice_main.iml" group="Alice" /> + <module fileurl="file://$PROJECT_DIR$/.idea/modules/Alice_test.iml" filepath="$PROJECT_DIR$/.idea/modules/Alice_test.iml" group="Alice" /> <module fileurl="file://$PROJECT_DIR$/bbs.iml" filepath="$PROJECT_DIR$/bbs.iml" /> + <module fileurl="file://$PROJECT_DIR$/.idea/modules/bbs_main.iml" filepath="$PROJECT_DIR$/.idea/modules/bbs_main.iml" group="bbs" /> + <module fileurl="file://$PROJECT_DIR$/.idea/modules/bbs_test.iml" filepath="$PROJECT_DIR$/.idea/modules/bbs_test.iml" group="bbs" /> + <module fileurl="file://$PROJECT_DIR$/.idea/modules/jungle-core.iml" filepath="$PROJECT_DIR$/.idea/modules/jungle-core.iml" /> + <module fileurl="file://$PROJECT_DIR$/.idea/modules/jungle-core_main.iml" filepath="$PROJECT_DIR$/.idea/modules/jungle-core_main.iml" group="jungle-core" /> + <module fileurl="file://$PROJECT_DIR$/.idea/modules/jungle-core_test.iml" filepath="$PROJECT_DIR$/.idea/modules/jungle-core_test.iml" group="jungle-core" /> </modules> </component> </project> \ No newline at end of file
--- a/.idea/vcs.xml Mon Aug 07 19:37:14 2017 +0900 +++ b/.idea/vcs.xml Mon Aug 28 11:14:19 2017 +0900 @@ -2,5 +2,8 @@ <project version="4"> <component name="VcsDirectoryMappings"> <mapping directory="" vcs="hg4idea" /> + <mapping directory="$PROJECT_DIR$/../Alice" vcs="hg4idea" /> + <mapping directory="$PROJECT_DIR$" vcs="hg4idea" /> + <mapping directory="$PROJECT_DIR$/../jungle-core" vcs="hg4idea" /> </component> </project> \ No newline at end of file
--- a/bbs.iml Mon Aug 07 19:37:14 2017 +0900 +++ b/bbs.iml Mon Aug 28 11:14:19 2017 +0900 @@ -1,18 +1,13 @@ <?xml version="1.0" encoding="UTF-8"?> <module external.linked.project.id="bbs" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$" external.system.id="GRADLE" external.system.module.group="" external.system.module.version="1.0" type="JAVA_MODULE" version="4"> - <component name="NewModuleRootManager" inherit-compiler-output="false"> - <output url="file://$MODULE_DIR$/build/classes/main" /> - <output-test url="file://$MODULE_DIR$/build/classes/test" /> + <component name="NewModuleRootManager" inherit-compiler-output="true"> <exclude-output /> <content url="file://$MODULE_DIR$"> - <sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" /> - <sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" /> - <sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" /> - <sourceFolder url="file://$MODULE_DIR$/src/test/resources" type="java-test-resource" /> <excludeFolder url="file://$MODULE_DIR$/.gradle" /> <excludeFolder url="file://$MODULE_DIR$/build" /> </content> <orderEntry type="inheritedJdk" /> <orderEntry type="sourceFolder" forTests="false" /> + <orderEntry type="library" name="jungle-core" level="project" /> </component> </module> \ No newline at end of file
--- a/build.gradle Mon Aug 07 19:37:14 2017 +0900 +++ b/build.gradle Mon Aug 28 11:14:19 2017 +0900 @@ -23,6 +23,8 @@ compile group: 'cr.ie.u_ryukyu.ac.jp', name: 'jungle-core', version: '1.1', ext: 'jar' compile group: 'com.massisframework.j3d', name: 'java3d-core', version: '1.6.0' compile group: 'com.massisframework.j3d', name: 'vecmath', version: '1.6.0.1' + compile group: 'org.msgpack', name: 'msgpack', version: '0.6.0' + jar { manifest { attributes 'Implementation-Title': 'Gradle Quickstart', 'Implementation-Version': version, @@ -52,4 +54,4 @@ baseName = "jungleBrowser" from configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } } -} \ No newline at end of file +}
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/bbs/network/BulletinBoardJungleManager.java Mon Aug 07 19:37:14 2017 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/bbs/network/BulletinBoardJungleManager.java Mon Aug 28 11:14:19 2017 +0900 @@ -9,51 +9,48 @@ import jp.ac.u_ryukyu.ie.cr.jungle.tree.JungleTree; import jp.ac.u_ryukyu.ie.cr.jungle.util.Either; import jp.ac.u_ryukyu.ie.cr.jungle.util.jungleError.Error; +import jp.ac.u_ryukyu.ie.cr.jungleNetwork.codesegment.JungleDistributedUpdator; 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(); +public class BulletinBoardJungleManager implements JungleDistributedUpdator { private Jungle jungle; - private static AtomicInteger requestCounter = new AtomicInteger(0); + private AtomicInteger requestCounter = new AtomicInteger(0); - private BulletinBoardJungleManager() { - jungle = new DefaultJungle(null,"default"); + BulletinBoardJungleManager(Jungle jungle) { + this.jungle = jungle; } - public static int requestGetAndIncrement() { + public int requestGetAndIncrement() { return requestCounter.getAndIncrement(); } - public static int requestIncrementAndGet() { + public int requestIncrementAndGet() { return requestCounter.incrementAndGet(); } - public static BulletinBoardJungleManager getInstantce() { - return instance; + public void setJungle(Jungle _j) { + jungle = _j; } - - public static void setJungle(Jungle _j) { - instance.jungle = _j; - } - public static AtomicInteger getRequestCounter() { + public AtomicInteger getRequestCounter() { return requestCounter; } - public static Jungle getJungle() { - return instance.jungle; + public Jungle getJungle() { + return jungle; } - public static JungleTree createNewTree(String name) { - return instance.jungle.createNewTree(name); + public JungleTree createNewTree(String name) { + return jungle.createNewTree(name); } - public static Either<Error, JungleTreeEditor> update(NetworkTreeOperationLog netLog) { + @Override + public Either<Error, JungleTreeEditor> update(NetworkTreeOperationLog netLog) { String treeName = netLog.getTreeName(); - Jungle jungle = BulletinBoardJungleManager.getJungle(); + Jungle jungle = getJungle(); if (jungle.getTreeByName(treeName) == null) { if(null == jungle.createNewTree(treeName)){ throw new IllegalStateException(); @@ -88,7 +85,7 @@ return either; } - private static int calculatePosition(TreeNode node, long newNodeTimeStamp) { + private int calculatePosition(TreeNode node, long newNodeTimeStamp) { int count = 0; long childTimeStamp = 0; for(TreeNode n : node.getChildren()) {
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/bbs/network/NetworkJungleBulletinBoard.java Mon Aug 07 19:37:14 2017 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/bbs/network/NetworkJungleBulletinBoard.java Mon Aug 28 11:14:19 2017 +0900 @@ -23,6 +23,7 @@ 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.jungleError.Error; +import jp.ac.u_ryukyu.ie.cr.jungleNetwork.codesegment.JungleDistributedUpdator; 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; @@ -39,6 +40,7 @@ protected final Jungle jungle; private final NetworkJournal journal; private final String LOG_DIR; + private final BulletinBoardJungleManager bm; private Boolean persistentFlag; private AtomicInteger requestCounter; private long renewTime; @@ -46,9 +48,9 @@ private NetworkJungleBulletinBoard(String _uuid, NetworkJournal _journal) { journal = _journal; jungle = new NetworkDefaultJungle(journal, _uuid); - BulletinBoardJungleManager.setJungle(jungle); + bm = new BulletinBoardJungleManager(jungle); persistentFlag = false; - requestCounter = BulletinBoardJungleManager.getRequestCounter(); + requestCounter = bm.getRequestCounter(); LOG_DIR = "./log"; renewTime = 0; } @@ -64,6 +66,8 @@ return board; } + JungleDistributedUpdator getUpdator() { return bm; } + public void init() { if (!persistentFlag) { return;
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/bbs/network/codesegment/LogPutCodeSegment.java Mon Aug 07 19:37:14 2017 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,20 +0,0 @@ -package jp.ac.u_ryukyu.ie.cr.bbs.network.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); - } - -}
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/bbs/network/codesegment/LogUpdateCodeSegment.java Mon Aug 07 19:37:14 2017 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,48 +0,0 @@ -package jp.ac.u_ryukyu.ie.cr.bbs.network.codesegment; - -import alice.codesegment.CodeSegment; -import alice.datasegment.CommandType; -import alice.datasegment.Receiver; -import jp.ac.u_ryukyu.ie.cr.bbs.network.BulletinBoardJungleManager; -import jp.ac.u_ryukyu.ie.cr.jungle.transaction.editor.jungleTreeEditor.JungleTreeEditor; -import jp.ac.u_ryukyu.ie.cr.jungle.util.Either; -import jp.ac.u_ryukyu.ie.cr.jungle.util.jungleError.Error; -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(); - } - } - } -}
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/bbs/network/codesegment/StartBBSCodeSegment.java Mon Aug 07 19:37:14 2017 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/bbs/network/codesegment/StartBBSCodeSegment.java Mon Aug 28 11:14:19 2017 +0900 @@ -54,6 +54,7 @@ cassaBBS = new NetworkJungleBulletinBoard(name); cassaBBS.init(); } + ods.put("updator", cassaBBS.getUpdator()); System.out.println("StartBBSCodeSegment"); System.out.println("name : "+ name);
--- a/src/test/java/jp/ac/u_ryukyu/ie/cr/bbs/network/showMessageTest.java Mon Aug 07 19:37:14 2017 +0900 +++ b/src/test/java/jp/ac/u_ryukyu/ie/cr/bbs/network/showMessageTest.java Mon Aug 28 11:14:19 2017 +0900 @@ -9,7 +9,6 @@ import java.io.OutputStreamWriter; import java.net.Socket; - public class showMessageTest { public static void main(String args[]) throws Exception { @@ -20,8 +19,8 @@ String str; System.out.println(url); RemoteConfig conf = new RemoteConfig(args); - StartBBSCodeSegment cs1 = new StartBBSCodeSegment(args, conf.bbsPort); - cs1.ods.put("host", "node0"); + // StartBBSCodeSegment cs1 = new StartBBSCodeSegment(args, conf.bbsPort); + // cs1.ods.put("host", "node0"); // should be passed BufferedReader input = new BufferedReader(new InputStreamReader( System.in)); Thread.sleep(1000);