Mercurial > hg > Database > jungle-network
annotate src/main/java/app/bbs/NetworkJungleBulletinBoard.java @ 190:269bada9eedc
add
author | tatsuki |
---|---|
date | Fri, 17 Oct 2014 15:16:56 +0900 |
parents | f9b26747ef63 |
children | 5d0734fd859d |
rev | line source |
---|---|
112 | 1 package app.bbs; |
38 | 2 |
135
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
3 import java.io.File; |
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
4 import java.io.IOException; |
38 | 5 import java.nio.ByteBuffer; |
186 | 6 import java.util.Iterator; |
38 | 7 import java.util.concurrent.atomic.AtomicInteger; |
39 | 8 |
179 | 9 import fj.data.List; |
10 import fj.data.TreeMap; | |
39 | 11 import alice.jungle.core.NetworkDefaultJungle; |
124 | 12 import alice.jungle.persistent.AliceJournal; |
135
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
13 import alice.jungle.persistent.NetworkJournal; |
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
14 import alice.jungle.persistent.PersistentJournal; |
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
15 import alice.jungle.transaction.JungleUpdater; |
166 | 16 import app.bbs.thinks.getAttributeImp; |
38 | 17 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.Jungle; |
18 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.JungleTree; | |
19 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.JungleTreeEditor; | |
125 | 20 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.bbs.BoardMessage; |
38 | 21 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.core.Children; |
135
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
22 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.persistent.ChangeList; |
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
23 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.persistent.ChangeListReader; |
180 | 24 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.NodePath; |
38 | 25 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.DefaultNodePath; |
26 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.DefaultTreeEditor; | |
176 | 27 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.TreeNode; |
28 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.logger.DefaultOperationLog; | |
179 | 29 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.logger.LoggingNode; |
176 | 30 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.logger.OperationLog; |
31 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.PutAttributeOperation; | |
38 | 32 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.trasnformer.NodeEditor; |
165 | 33 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.traverser.DefaultEvaluator; |
38 | 34 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.traverser.DefaultTraverser; |
186 | 35 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.traverser.InterfaceTraverser; |
165 | 36 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.traverser.Traversal; |
38 | 37 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.DefaultEither; |
38 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Either; | |
39 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Error; | |
40 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.IterableConverter; | |
180 | 41 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Pair; |
190 | 42 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.logger.LoggingNode; |
165 | 43 import junit.framework.Assert; |
38 | 44 |
165 | 45 public class NetworkJungleBulletinBoard implements NetworkBulletinBoard { |
38 | 46 private final Jungle jungle; |
135
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
47 private final NetworkJournal journal; |
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
48 private final String LOG_DIR; |
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
49 private Boolean persistentFlag; |
165 | 50 private AtomicInteger requestCounter; |
150
eef85b5faa15
Removed renew atribute
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
149
diff
changeset
|
51 private long renewTime; |
165 | 52 |
53 private NetworkJungleBulletinBoard(String _uuid, NetworkJournal _journal) { | |
135
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
54 journal = _journal; |
176 | 55 jungle = new NetworkDefaultJungle(journal, _uuid, |
56 new DefaultTreeEditor(new DefaultTraverser())); | |
135
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
57 BulletinBoardJungleManager.setJungle(jungle); |
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
58 persistentFlag = false; |
147
202ea963ec20
Added requestCounter in BulletinBoardJungleManager
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
146
diff
changeset
|
59 requestCounter = BulletinBoardJungleManager.getRequestCounter(); |
135
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
60 LOG_DIR = "./log"; |
150
eef85b5faa15
Removed renew atribute
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
149
diff
changeset
|
61 renewTime = 0; |
135
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
62 } |
165 | 63 |
64 public NetworkJungleBulletinBoard(String _uuid) { | |
135
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
65 this(_uuid, new AliceJournal()); |
124 | 66 jungle.createNewTree("boards"); |
135
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
67 } |
165 | 68 |
69 public static NetworkBulletinBoard NewPersistentJungle(String _uuid) { | |
176 | 70 NetworkJungleBulletinBoard board = new NetworkJungleBulletinBoard( |
71 _uuid, new PersistentJournal()); | |
135
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
72 board.persistentFlag = true; |
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
73 return board; |
38 | 74 } |
165 | 75 |
124 | 76 public void init() { |
165 | 77 if (!persistentFlag) { |
135
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
78 return; |
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
79 } |
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
80 checkAndCreateLogDirectory(); |
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
81 try { |
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
82 commitLogRecover(); |
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
83 } catch (IOException e) { |
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
84 e.printStackTrace(); |
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
85 } |
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
86 } |
165 | 87 |
135
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
88 public void checkAndCreateLogDirectory() { |
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
89 File logFile = new File(LOG_DIR); |
165 | 90 if (!logFile.exists()) { |
135
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
91 logFile.mkdir(); |
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
92 return; |
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
93 } |
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
94 if (logFile.isFile()) { |
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
95 logFile.delete(); |
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
96 logFile.mkdir(); |
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
97 } |
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
98 } |
165 | 99 |
135
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
100 public void commitLogRecover() throws IOException { |
165 | 101 File[] logFiles = new File(LOG_DIR).listFiles(); |
102 for (File logFile : logFiles) { | |
135
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
103 commitLogRecover(logFile); |
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
104 logFile.delete(); |
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
105 } |
165 | 106 if (jungle.getTreeByName("boards") == null) { |
135
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
107 jungle.createNewTree("boards"); |
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
108 } |
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
109 } |
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
110 |
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
111 private void commitLogRecover(File logFile) throws IOException { |
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
112 journal.setInputFile(logFile); |
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
113 ChangeListReader reader = journal.getReader(); |
165 | 114 if (reader == null) |
115 return; | |
135
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
116 for (ChangeList chList : reader) { |
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
117 String treeName = chList.getTreeName(); |
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
118 JungleTree tree = jungle.getTreeByName(treeName); |
165 | 119 if (tree == null) { |
135
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
120 tree = jungle.createNewTree(treeName); |
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
121 } |
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
122 JungleTreeEditor editor = tree.getLocalTreeEditor(); |
176 | 123 Either<Error, JungleTreeEditor> either = JungleUpdater.edit(editor, |
124 chList); | |
135
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
125 editor = either.b(); |
165 | 126 if (either.isA()) { |
135
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
127 throw new IOException("Failed commit log recovery"); |
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
128 } |
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
129 editor.success(); |
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
130 } |
118
f64ff5bd66f5
Implements persistent for bbs app and Fixed bug JungleUpdater
one
parents:
112
diff
changeset
|
131 } |
38 | 132 |
165 | 133 public Iterable<String> getBoards() { |
38 | 134 JungleTree tree = jungle.getTreeByName("boards"); |
176 | 135 TreeNode node = tree.getRootNode(); |
178 | 136 Children chs = node.getChildren(); |
165 | 137 |
176 | 138 IterableConverter.Converter<String, TreeNode> converter = new IterableConverter.Converter<String, TreeNode>() { |
139 public String conv(TreeNode _b) { | |
38 | 140 ByteBuffer e = _b.getAttributes().get("name"); |
173 | 141 System.out.println(new String(e.array())); |
38 | 142 return new String(e.array()); |
143 } | |
144 }; | |
165 | 145 |
176 | 146 return new IterableConverter<String, TreeNode>(chs, converter); |
38 | 147 } |
165 | 148 |
146
29734d7d6521
Added ShowMessageWithTimeStampServlet
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
143
diff
changeset
|
149 public long getRenewTime(String _boardName) { |
150
eef85b5faa15
Removed renew atribute
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
149
diff
changeset
|
150 return renewTime; |
146
29734d7d6521
Added ShowMessageWithTimeStampServlet
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
143
diff
changeset
|
151 } |
38 | 152 |
167 | 153 public void createBoards(final String _name, final String _author, final String _initMessage, final String _editKey) { |
143
7a7bac51a3cc
Added RequestNumCheckServlet
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
139
diff
changeset
|
154 requestCounter.incrementAndGet(); |
165 | 155 if (null == jungle.createNewTree(_name)) { |
38 | 156 throw new IllegalStateException(); |
157 } | |
165 | 158 |
38 | 159 JungleTree tree = jungle.getTreeByName("boards"); |
160 JungleTreeEditor editor = tree.getTreeEditor(); | |
161 DefaultNodePath root = new DefaultNodePath(); | |
165 | 162 Either<Error, JungleTreeEditor> either = editor.addNewChildAt(root, 0); |
163 if (either.isA()) { | |
38 | 164 throw new IllegalStateException(); |
165 } | |
166 editor = either.b(); | |
165 | 167 |
176 | 168 either = editor.putAttribute(root.add(0), "name", |
169 ByteBuffer.wrap(_name.getBytes())); | |
165 | 170 if (either.isA()) { |
38 | 171 throw new IllegalStateException(); |
172 } | |
173 editor = either.b(); | |
149
06cddf529325
Modified lates renew time
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
147
diff
changeset
|
174 final long timestamp = System.currentTimeMillis(); |
129
1a3edba05f50
Fixed bug NetworkJungleBulletinBoard
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
126
diff
changeset
|
175 ByteBuffer tBuffer = ByteBuffer.allocate(16); |
146
29734d7d6521
Added ShowMessageWithTimeStampServlet
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
143
diff
changeset
|
176 tBuffer.putLong(timestamp); |
165 | 177 either = editor.putAttribute(root.add(0), "timestamp", tBuffer); |
178 if (either.isA()) { | |
129
1a3edba05f50
Fixed bug NetworkJungleBulletinBoard
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
126
diff
changeset
|
179 throw new IllegalStateException(); |
1a3edba05f50
Fixed bug NetworkJungleBulletinBoard
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
126
diff
changeset
|
180 } |
146
29734d7d6521
Added ShowMessageWithTimeStampServlet
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
143
diff
changeset
|
181 either = either.b().success(); |
165 | 182 if (either.isA()) { |
38 | 183 throw new IllegalStateException(); |
184 } | |
165 | 185 |
38 | 186 tree = jungle.getTreeByName(_name); |
187 editor = tree.getTreeEditor(); | |
165 | 188 either = editor.addNewChildAt(root, 0); |
189 if (either.isA()) { | |
38 | 190 throw new IllegalStateException(); |
191 } | |
192 editor = either.b(); | |
165 | 193 |
194 NodeEditor e = new NodeEditor() { | |
176 | 195 ByteBuffer tBuffer2 = ByteBuffer.allocate(16); |
196 | |
190 | 197 public Either<Error,LoggingNode> edit(TreeNode node) { |
198 LoggingNode logNode = wrap(node , new DefaultOperationLog()); | |
179 | 199 logNode = logNode.getAttributes().put("author", ByteBuffer.wrap(_author.getBytes())).b(); |
200 logNode = logNode.getAttributes().put("mes", ByteBuffer.wrap(_initMessage.getBytes())).b(); | |
201 logNode = logNode.getAttributes().put("key", ByteBuffer.wrap(_editKey.getBytes())).b(); | |
146
29734d7d6521
Added ShowMessageWithTimeStampServlet
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
143
diff
changeset
|
202 tBuffer2.putLong(timestamp); |
179 | 203 logNode = logNode.getAttributes().put("timestamp", tBuffer2).b(); |
204 return DefaultEither.newB(logNode); | |
205 } | |
206 @Override | |
190 | 207 public LoggingNode wrap(TreeNode node, OperationLog op) { |
179 | 208 return new LoggingNode(node, op); |
209 } | |
210 @Override | |
180 | 211 public TreeMap<String, TreeMap<String, List<Pair<TreeNode, NodePath>>>> getIndex() { |
179 | 212 // TODO Auto-generated method stub |
213 return null; | |
176 | 214 } |
215 | |
38 | 216 }; |
165 | 217 |
218 either = editor.edit(root.add(0), e); | |
219 if (either.isA()) { | |
38 | 220 throw new IllegalStateException(); |
221 } | |
146
29734d7d6521
Added ShowMessageWithTimeStampServlet
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
143
diff
changeset
|
222 either.b().success(); |
147
202ea963ec20
Added requestCounter in BulletinBoardJungleManager
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
146
diff
changeset
|
223 |
38 | 224 } |
225 | |
167 | 226 public void createFolder(final String _board, final String _author, final String _message, final String _editKey, String _nodeNum) { |
38 | 227 JungleTree tree = jungle.getTreeByName(_board); |
165 | 228 if (tree == null) { |
38 | 229 throw new IllegalStateException(); |
230 } | |
176 | 231 |
165 | 232 DefaultNodePath path = new DefaultNodePath(); |
233 try { | |
234 for (int count = 0; _nodeNum.substring(count, count + 1) != null; count++) { | |
235 if (!_nodeNum.substring(count, count + 1).equals("/")) | |
176 | 236 path = path.add(Integer.parseInt(_nodeNum.substring(count, |
237 count + 1))); | |
165 | 238 } |
239 } catch (Exception _e) { | |
240 } | |
241 requestCounter.incrementAndGet(); | |
46 | 242 Either<Error, JungleTreeEditor> either; |
149
06cddf529325
Modified lates renew time
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
147
diff
changeset
|
243 final long timestamp = System.currentTimeMillis(); |
146
29734d7d6521
Added ShowMessageWithTimeStampServlet
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
143
diff
changeset
|
244 final ByteBuffer tBuffer = ByteBuffer.allocate(16); |
29734d7d6521
Added ShowMessageWithTimeStampServlet
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
143
diff
changeset
|
245 tBuffer.putLong(timestamp); |
176 | 246 |
165 | 247 do { |
176 | 248 TreeNode node = tree.getRootNode(); |
165 | 249 DefaultTraverser traverser = new DefaultTraverser(); |
176 | 250 // TraversableNodeWrapper<Node> traversable = new |
251 // TraversableNodeWrapper<Node>(node); | |
165 | 252 DefaultEvaluator evaluator = new DefaultEvaluator(path); |
178 | 253 Either<Error, Traversal> ret = traverser.traverse(node, |
176 | 254 evaluator); |
165 | 255 if (ret.isA()) { |
256 Assert.fail(); | |
257 } | |
258 | |
178 | 259 Traversal traversal = ret.b(); |
176 | 260 TreeNode target = traversal.destination(); |
261 int size = target.getChildren().size(); | |
65 | 262 JungleTreeEditor editor = tree.getTreeEditor(); |
165 | 263 either = editor.addNewChildAt(path, size); |
264 if (either.isA()) { | |
38 | 265 throw new IllegalStateException(); |
266 } | |
267 editor = either.b(); | |
146
29734d7d6521
Added ShowMessageWithTimeStampServlet
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
143
diff
changeset
|
268 |
165 | 269 NodeEditor e = new NodeEditor() { |
176 | 270 |
190 | 271 public Either<Error,LoggingNode> edit(TreeNode node) { |
272 LoggingNode logNode = wrap(node , new DefaultOperationLog()); | |
179 | 273 logNode = logNode.getAttributes().put("mes", ByteBuffer.wrap(_message.getBytes())).b(); |
274 logNode = logNode.getAttributes().put("timestamp", tBuffer).b(); | |
275 return DefaultEither.newB(logNode); | |
276 } | |
277 | |
278 @Override | |
190 | 279 public LoggingNode wrap(TreeNode node, OperationLog op) { |
179 | 280 return new LoggingNode(node, op); |
281 } | |
282 | |
283 @Override | |
180 | 284 public TreeMap<String, TreeMap<String, List<Pair<TreeNode, NodePath>>>> getIndex() { |
179 | 285 // TODO Auto-generated method stub |
286 return null; | |
176 | 287 } |
288 | |
38 | 289 }; |
290 path = path.add(size); | |
165 | 291 either = editor.edit(path, e); |
292 if (either.isA()) { | |
38 | 293 throw new IllegalStateException(); |
294 } | |
295 editor = either.b(); | |
46 | 296 either = editor.success(); |
165 | 297 } while (either.isA()); |
93 | 298 |
38 | 299 } |
300 | |
167 | 301 public void createBoardMessage(final String _board, final String _author, final String _message, final String _editKey) { |
165 | 302 requestCounter.incrementAndGet(); |
303 JungleTree tree = jungle.getTreeByName(_board); | |
304 if (tree == null) { | |
305 throw new IllegalStateException(); | |
306 } | |
307 | |
308 Either<Error, JungleTreeEditor> either; | |
309 final long timestamp = System.currentTimeMillis(); | |
310 final ByteBuffer tBuffer = ByteBuffer.allocate(16); | |
311 tBuffer.putLong(timestamp); | |
312 do { | |
176 | 313 |
314 TreeNode node = tree.getRootNode(); | |
165 | 315 int size = node.getChildren().size(); |
316 DefaultNodePath path = new DefaultNodePath(); | |
317 | |
318 JungleTreeEditor editor = tree.getTreeEditor(); | |
319 either = editor.addNewChildAt(path, size); | |
320 if (either.isA()) { | |
321 throw new IllegalStateException(); | |
322 } | |
323 editor = either.b(); | |
324 | |
325 NodeEditor e = new NodeEditor() { | |
190 | 326 public Either<Error,LoggingNode> edit(TreeNode node) { |
327 LoggingNode logNode = wrap(node , new DefaultOperationLog()); | |
179 | 328 logNode = logNode.getAttributes().put("author", ByteBuffer.wrap(_author.getBytes())).b(); |
329 logNode = logNode.getAttributes().put("mes", ByteBuffer.wrap(_message.getBytes())).b(); | |
330 logNode = logNode.getAttributes().put("key", ByteBuffer.wrap(_editKey.getBytes())).b(); | |
331 logNode = logNode.getAttributes().put("timestamp", tBuffer).b(); | |
332 return DefaultEither.newB(logNode); | |
333 } | |
334 | |
335 @Override | |
190 | 336 public LoggingNode wrap(TreeNode node, OperationLog op) { |
179 | 337 return new LoggingNode(node, op); |
338 } | |
339 | |
340 @Override | |
180 | 341 public TreeMap<String, TreeMap<String, List<Pair<TreeNode, NodePath>>>> getIndex() { |
179 | 342 // TODO Auto-generated method stub |
343 return null; | |
176 | 344 } |
345 | |
165 | 346 }; |
347 path = path.add(size); | |
348 either = editor.edit(path, e); | |
349 if (either.isA()) { | |
350 throw new IllegalStateException(); | |
351 } | |
352 editor = either.b(); | |
353 either = editor.success(); | |
354 } while (either.isA()); | |
355 | |
356 } | |
357 | |
176 | 358 public void editMessage(String _board, String _nodeNum,final String _author, final String _message, final String _editKey) { |
143
7a7bac51a3cc
Added RequestNumCheckServlet
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
139
diff
changeset
|
359 requestCounter.incrementAndGet(); |
149
06cddf529325
Modified lates renew time
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
147
diff
changeset
|
360 final long timestamp = System.currentTimeMillis(); |
146
29734d7d6521
Added ShowMessageWithTimeStampServlet
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
143
diff
changeset
|
361 final ByteBuffer tBuffer = ByteBuffer.allocate(16); |
29734d7d6521
Added ShowMessageWithTimeStampServlet
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
143
diff
changeset
|
362 tBuffer.putLong(timestamp); |
29734d7d6521
Added ShowMessageWithTimeStampServlet
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
143
diff
changeset
|
363 JungleTree tree = jungle.getTreeByName(_board); |
29734d7d6521
Added ShowMessageWithTimeStampServlet
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
143
diff
changeset
|
364 Either<Error, JungleTreeEditor> either = null; |
176 | 365 |
146
29734d7d6521
Added ShowMessageWithTimeStampServlet
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
143
diff
changeset
|
366 do { |
38 | 367 DefaultNodePath path = new DefaultNodePath(); |
168 | 368 try { |
369 for (int count = 0; _nodeNum.substring(count, count + 1) != null; count++) { | |
370 if (!_nodeNum.substring(count, count + 1).equals("/")) | |
176 | 371 path = path.add(Integer.parseInt(_nodeNum.substring(count, count + 1))); |
168 | 372 } |
373 } catch (Exception _e) { | |
374 } | |
65 | 375 JungleTreeEditor editor = tree.getTreeEditor(); |
165 | 376 NodeEditor e = new NodeEditor() { |
190 | 377 public Either<Error,LoggingNode> edit(TreeNode node) { |
378 LoggingNode logNode = wrap(node , new DefaultOperationLog()); | |
179 | 379 System.out.println(new String(node.getAttributes().get("mes").array())); |
380 logNode = logNode.getAttributes().put("author", ByteBuffer.wrap(_author.getBytes())).b(); | |
381 logNode = logNode.getAttributes().put("mes", ByteBuffer.wrap(_message.getBytes())).b(); | |
382 logNode = logNode.getAttributes().put("key", ByteBuffer.wrap(_editKey.getBytes())).b(); | |
383 logNode = logNode.getAttributes().put("timestamp", tBuffer).b(); | |
176 | 384 System.out.println(new String(node.getAttributes().get("mes").array())); |
179 | 385 return DefaultEither.newB(logNode); |
386 } | |
387 | |
388 @Override | |
190 | 389 public LoggingNode wrap(TreeNode node, OperationLog op) { |
179 | 390 return new LoggingNode(node, op); |
391 } | |
392 | |
393 @Override | |
180 | 394 public TreeMap<String, TreeMap<String, List<Pair<TreeNode, NodePath>>>> getIndex() { |
179 | 395 // TODO Auto-generated method stub |
396 return null; | |
176 | 397 } |
398 | |
38 | 399 }; |
165 | 400 either = editor.edit(path, e); |
401 if (either.isA()) { | |
38 | 402 throw new IllegalStateException(); |
403 } | |
404 editor = either.b(); | |
46 | 405 either = editor.success(); |
165 | 406 } while (either.isA()); |
407 renewTime = timestamp; | |
408 } | |
166 | 409 |
167 | 410 public void createAttribute(String _board, String _uuid, final String _author, final String _message, final String _editKey) { |
165 | 411 requestCounter.incrementAndGet(); |
412 final long timestamp = System.currentTimeMillis(); | |
413 final ByteBuffer tBuffer = ByteBuffer.allocate(16); | |
414 tBuffer.putLong(timestamp); | |
415 JungleTree tree = jungle.getTreeByName(_board); | |
416 Either<Error, JungleTreeEditor> either = null; | |
417 DefaultNodePath path = new DefaultNodePath(); | |
418 do { | |
419 try { | |
420 for (int count = 0; _uuid.substring(count, count + 1) != null; count++) { | |
421 if (!_uuid.substring(count, count + 1).equals("/")) | |
176 | 422 path = path.add(Integer.parseInt(_uuid.substring(count, |
423 count + 1))); | |
165 | 424 } |
425 } catch (Exception _e) { | |
426 } | |
176 | 427 |
165 | 428 JungleTreeEditor editor = tree.getTreeEditor(); |
429 NodeEditor e = new NodeEditor() { | |
176 | 430 String str; |
431 | |
190 | 432 public Either<Error,LoggingNode> edit(TreeNode node) { |
433 LoggingNode logNode = wrap(node , new DefaultOperationLog()); | |
176 | 434 str = "0"; |
166 | 435 int count = 0; |
179 | 436 for (; logNode.getAttributes().get("mes" + String.valueOf(count)) != null; count++) { |
176 | 437 } |
168 | 438 str = String.valueOf(count); |
179 | 439 logNode = logNode.getAttributes().put("mes" + str,ByteBuffer.wrap(_message.getBytes())).b(); |
440 logNode = logNode.getAttributes().put("timestamp" + str, tBuffer).b(); | |
441 return DefaultEither.newB(logNode); | |
442 } | |
443 | |
444 @Override | |
190 | 445 public LoggingNode wrap(TreeNode node, OperationLog op) { |
179 | 446 return new LoggingNode(node, op); |
447 } | |
448 | |
449 @Override | |
180 | 450 public TreeMap<String, TreeMap<String, List<Pair<TreeNode, NodePath>>>> getIndex() { |
179 | 451 // TODO Auto-generated method stub |
452 return null; | |
176 | 453 } |
454 | |
165 | 455 }; |
456 either = editor.edit(path, e); | |
457 if (either.isA()) { | |
458 throw new IllegalStateException(); | |
459 } | |
460 editor = either.b(); | |
461 either = editor.success(); | |
462 } while (either.isA()); | |
463 } | |
166 | 464 |
173 | 465 public void editAttribute(String boardName, String _path, final String id, final String _message) { |
168 | 466 requestCounter.incrementAndGet(); |
467 final long timestamp = System.currentTimeMillis(); | |
468 final ByteBuffer tBuffer = ByteBuffer.allocate(16); | |
469 tBuffer.putLong(timestamp); | |
470 JungleTree tree = jungle.getTreeByName(boardName); | |
471 Either<Error, JungleTreeEditor> either = null; | |
472 DefaultNodePath path = new DefaultNodePath(); | |
473 do { | |
474 try { | |
475 for (int count = 0; _path.substring(count, count + 1) != null; count++) { | |
476 if (!_path.substring(count, count + 1).equals("/")) | |
176 | 477 path = path.add(Integer.parseInt(_path.substring(count, |
478 count + 1))); | |
168 | 479 } |
480 } catch (Exception _e) { | |
481 } | |
176 | 482 |
168 | 483 JungleTreeEditor editor = tree.getTreeEditor(); |
484 NodeEditor e = new NodeEditor() { | |
190 | 485 public Either<Error,LoggingNode> edit(TreeNode node) { |
486 LoggingNode logNode = wrap(node , new DefaultOperationLog()); | |
168 | 487 // EnableNodeWrapper<T> node = _e.getWrap(); |
179 | 488 logNode = logNode.getAttributes().put("mes" + id,ByteBuffer.wrap(_message.getBytes())).b(); |
489 logNode = logNode.getAttributes().put("timestamp" + id, tBuffer).b(); | |
490 return DefaultEither.newB(logNode); | |
491 } | |
492 | |
493 @Override | |
190 | 494 public LoggingNode wrap(TreeNode node, OperationLog op) { |
179 | 495 return new LoggingNode(node, op); |
496 } | |
497 | |
498 @Override | |
180 | 499 public TreeMap<String, TreeMap<String, List<Pair<TreeNode, NodePath>>>> getIndex() { |
179 | 500 // TODO Auto-generated method stub |
501 return null; | |
176 | 502 } |
503 | |
168 | 504 }; |
505 either = editor.edit(path, e); | |
506 if (either.isA()) { | |
507 throw new IllegalStateException(); | |
508 } | |
509 editor = either.b(); | |
510 either = editor.success(); | |
511 } while (either.isA()); | |
512 } | |
176 | 513 |
170 | 514 public void deleteNode(String _board, String _path, String _id) { |
515 requestCounter.incrementAndGet(); | |
516 int id = Integer.parseInt(_id); | |
517 final long timestamp = System.currentTimeMillis(); | |
518 final ByteBuffer tBuffer = ByteBuffer.allocate(16); | |
519 tBuffer.putLong(timestamp); | |
520 JungleTree tree = jungle.getTreeByName(_board); | |
521 Either<Error, JungleTreeEditor> either = null; | |
522 DefaultNodePath path = new DefaultNodePath(); | |
523 do { | |
524 try { | |
525 for (int count = 0; _path.substring(count, count + 1) != null; count++) { | |
526 if (!_path.substring(count, count + 1).equals("/")) | |
176 | 527 path = path.add(Integer.parseInt(_path.substring(count,count + 1))); |
170 | 528 } |
529 } catch (Exception _e) { | |
530 } | |
176 | 531 |
170 | 532 JungleTreeEditor editor = tree.getTreeEditor(); |
168 | 533 |
170 | 534 either = editor.deleteChildAt(path, id); |
535 if (either.isA()) { | |
536 throw new IllegalStateException(); | |
537 } | |
538 editor = either.b(); | |
539 either = editor.success(); | |
540 } while (either.isA()); | |
176 | 541 |
170 | 542 } |
176 | 543 |
544 public void deleteAttribute(String _board, String _path, final String id) { | |
169 | 545 requestCounter.incrementAndGet(); |
546 final long timestamp = System.currentTimeMillis(); | |
547 final ByteBuffer tBuffer = ByteBuffer.allocate(16); | |
548 tBuffer.putLong(timestamp); | |
549 JungleTree tree = jungle.getTreeByName(_board); | |
550 Either<Error, JungleTreeEditor> either = null; | |
551 DefaultNodePath path = new DefaultNodePath(); | |
552 do { | |
553 try { | |
554 for (int count = 0; _path.substring(count, count + 1) != null; count++) { | |
555 if (!_path.substring(count, count + 1).equals("/")) | |
176 | 556 path = path.add(Integer.parseInt(_path.substring(count, |
557 count + 1))); | |
169 | 558 } |
559 } catch (Exception _e) { | |
175 | 560 System.out.println("屑"); |
169 | 561 } |
176 | 562 |
169 | 563 JungleTreeEditor editor = tree.getTreeEditor(); |
564 NodeEditor e = new NodeEditor() { | |
190 | 565 public Either<Error,LoggingNode> edit(TreeNode node) { |
566 LoggingNode logNode = wrap(node , new DefaultOperationLog()); | |
179 | 567 logNode = logNode.getAttributes().delete("mes" + id).b(); |
568 logNode = logNode.getAttributes().delete("timestamp" + id).b(); | |
169 | 569 int count = Integer.parseInt(id); |
179 | 570 for (; logNode.getAttributes().get("mes" + String.valueOf(count + 1)) != null;) { |
571 logNode = logNode.getAttributes().put("mes" + count,node.getAttributes().get("mes"+ String.valueOf(count + 1))).b(); | |
572 logNode = logNode.getAttributes().put("timestamp" + count, tBuffer).b(); | |
176 | 573 count++; |
574 } | |
575 if (count != Integer.parseInt(id)) { | |
179 | 576 logNode = logNode.getAttributes().delete("timestamp" + count).b(); |
577 logNode = logNode.getAttributes().delete("mes" + count).b(); | |
171 | 578 } |
579 | |
179 | 580 return DefaultEither.newB(logNode); |
581 } | |
582 | |
583 @Override | |
190 | 584 public LoggingNode wrap(TreeNode node, OperationLog op) { |
179 | 585 return new LoggingNode(node, op); |
586 } | |
587 | |
588 @Override | |
180 | 589 public TreeMap<String, TreeMap<String, List<Pair<TreeNode, NodePath>>>> getIndex() { |
179 | 590 // TODO Auto-generated method stub |
591 return null; | |
176 | 592 } |
593 | |
169 | 594 }; |
595 either = editor.edit(path, e); | |
596 if (either.isA()) { | |
597 throw new IllegalStateException(); | |
598 } | |
599 editor = either.b(); | |
600 either = editor.success(); | |
601 } while (either.isA()); | |
602 } | |
603 | |
176 | 604 public void editMatrixMessage(String _board, String _uuid, |
605 final String _author, final String _message, final String _editKey) { | |
165 | 606 requestCounter.incrementAndGet(); |
607 final long timestamp = System.currentTimeMillis(); | |
608 final ByteBuffer tBuffer = ByteBuffer.allocate(16); | |
609 tBuffer.putLong(timestamp); | |
610 JungleTree tree = jungle.getTreeByName(_board); | |
611 Either<Error, JungleTreeEditor> either = null; | |
612 do { | |
613 DefaultNodePath path = new DefaultNodePath(); | |
614 path = path.add(Integer.parseInt(_uuid)); | |
615 | |
616 JungleTreeEditor editor = tree.getTreeEditor(); | |
617 NodeEditor e = new NodeEditor() { | |
190 | 618 public Either<Error,LoggingNode> edit(TreeNode node) { |
619 LoggingNode logNode = wrap(node , new DefaultOperationLog()); | |
179 | 620 logNode = logNode.getAttributes().put("author", ByteBuffer.wrap(_author.getBytes())).b(); |
621 logNode = logNode.getAttributes().put("mes", ByteBuffer.wrap(_message.getBytes())).b(); | |
622 logNode = logNode.getAttributes().put("key", ByteBuffer.wrap(_editKey.getBytes())).b(); | |
623 logNode = logNode.getAttributes().put("timestamp", tBuffer).b(); | |
624 return DefaultEither.newB(logNode); | |
625 } | |
626 | |
627 @Override | |
190 | 628 public LoggingNode wrap(TreeNode node, OperationLog op) { |
179 | 629 return new LoggingNode(node, op); |
630 } | |
631 | |
632 @Override | |
180 | 633 public TreeMap<String, TreeMap<String, List<Pair<TreeNode, NodePath>>>> getIndex() { |
179 | 634 // TODO Auto-generated method stub |
635 return null; | |
176 | 636 } |
165 | 637 }; |
638 either = editor.edit(path, e); | |
639 if (either.isA()) { | |
640 throw new IllegalStateException(); | |
641 } | |
642 editor = either.b(); | |
643 either = editor.success(); | |
644 } while (either.isA()); | |
150
eef85b5faa15
Removed renew atribute
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
149
diff
changeset
|
645 renewTime = timestamp; |
38 | 646 } |
647 | |
165 | 648 public Iterable<BoardMessage> getMessages(String _boardName) { |
143
7a7bac51a3cc
Added RequestNumCheckServlet
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
139
diff
changeset
|
649 requestCounter.incrementAndGet(); |
38 | 650 JungleTree tree = jungle.getTreeByName(_boardName); |
176 | 651 TreeNode node = tree.getRootNode(); |
178 | 652 Children chs = node.getChildren(); |
38 | 653 final AtomicInteger counter = new AtomicInteger(0); |
176 | 654 IterableConverter.Converter<BoardMessage, TreeNode> converter = new IterableConverter.Converter<BoardMessage, TreeNode>() { |
655 public BoardMessage conv(TreeNode _b) { | |
165 | 656 String uuid = Integer.toString(counter.get()); |
176 | 657 String author = new String(_b.getAttributes().get("author").array()); |
167 | 658 String message = new String(_b.getAttributes().get("mes").array()); |
165 | 659 counter.incrementAndGet(); |
660 return new BoardMessageImpl(author, message, uuid); | |
661 } | |
662 }; | |
176 | 663 return new IterableConverter<BoardMessage, TreeNode>(chs, converter); |
165 | 664 } |
665 | |
666 public Iterable<BoardMessage> getFolder(String _boardName, String _nodeNum) { | |
166 | 667 |
165 | 668 DefaultNodePath path = new DefaultNodePath(); |
669 try { | |
670 for (int count = 0; _nodeNum.substring(count, count + 1) != null; count++) { | |
671 if (!_nodeNum.substring(count, count + 1).equals("/")) | |
167 | 672 path = path.add(Integer.parseInt(_nodeNum.substring(count,count + 1))); |
165 | 673 } |
674 } catch (Exception _e) { | |
675 } | |
676 requestCounter.incrementAndGet(); | |
677 JungleTree tree = jungle.getTreeByName(_boardName); | |
176 | 678 TreeNode node = tree.getRootNode(); |
165 | 679 |
680 DefaultTraverser traverser = new DefaultTraverser(); | |
176 | 681 // TraversableNodeWrapper<Node> traversable = new |
682 // TraversableNodeWrapper<Node>(node); | |
165 | 683 DefaultEvaluator evaluator = new DefaultEvaluator(path); |
178 | 684 Either<Error, Traversal> ret = traverser.traverse(node, |
176 | 685 evaluator); |
165 | 686 if (ret.isA()) { |
687 Assert.fail(); | |
688 } | |
689 | |
178 | 690 Traversal traversal = ret.b(); |
176 | 691 TreeNode target = traversal.destination(); |
178 | 692 Children chs = target.getChildren(); |
165 | 693 |
694 final AtomicInteger counter = new AtomicInteger(0); | |
176 | 695 IterableConverter.Converter<BoardMessage, TreeNode> converter = new IterableConverter.Converter<BoardMessage, TreeNode>() { |
696 public BoardMessage conv(TreeNode _b) { | |
38 | 697 String uuid = Integer.toString(counter.get()); |
176 | 698 String message = new String(_b.getAttributes().get("mes") |
699 .array()); | |
38 | 700 counter.incrementAndGet(); |
167 | 701 return new BoardMessageImpl(null, message, uuid); |
38 | 702 } |
703 }; | |
176 | 704 return new IterableConverter<BoardMessage, TreeNode>(chs, converter); |
38 | 705 } |
166 | 706 |
707 public getAttributeImp getAttribute(String _boardName, String _nodeNum) { | |
708 | |
709 DefaultNodePath path = new DefaultNodePath(); | |
710 try { | |
711 for (int count = 0; _nodeNum.substring(count, count + 1) != null; count++) { | |
712 if (!_nodeNum.substring(count, count + 1).equals("/")) | |
176 | 713 path = path.add(Integer.parseInt(_nodeNum.substring(count, |
714 count + 1))); | |
166 | 715 } |
716 } catch (Exception _e) { | |
717 } | |
718 requestCounter.incrementAndGet(); | |
719 JungleTree tree = jungle.getTreeByName(_boardName); | |
176 | 720 TreeNode node = tree.getRootNode(); |
166 | 721 |
722 DefaultTraverser traverser = new DefaultTraverser(); | |
190 | 723 // TraversableNodeWrapper<Node> traversable = new |
724 // TraversableNodeWrapper<Node>(node); | |
166 | 725 DefaultEvaluator evaluator = new DefaultEvaluator(path); |
178 | 726 Either<Error, Traversal> ret = traverser.traverse(node, |
176 | 727 evaluator); |
166 | 728 if (ret.isA()) { |
729 Assert.fail(); | |
730 } | |
731 | |
178 | 732 Traversal traversal = ret.b(); |
176 | 733 TreeNode target = traversal.destination(); |
734 return new getAttributeImp(target); | |
166 | 735 } |
165 | 736 |
190 | 737 |
186 | 738 |
739 public boolean compare(TreeNode compareNode, String compareAttribute) { | |
740 String labName = compareNode.getAttributes().getString("mes"); | |
741 if (labName.equals(compareAttribute)) | |
742 return true; | |
743 | |
744 int loopCount = 0; | |
745 for (loopCount = 0 ;compareNode.getAttributes().getString("mes" + loopCount) != null; loopCount++ ) { | |
746 labName = compareNode.getAttributes().getString("mes" + loopCount); | |
747 if (labName.equals(compareAttribute)) | |
748 return true; | |
749 } | |
750 | |
751 return false; | |
752 } | |
187 | 753 |
143
7a7bac51a3cc
Added RequestNumCheckServlet
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
139
diff
changeset
|
754 public int getRequestNum() { |
7a7bac51a3cc
Added RequestNumCheckServlet
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
139
diff
changeset
|
755 return requestCounter.get(); |
7a7bac51a3cc
Added RequestNumCheckServlet
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
139
diff
changeset
|
756 } |
146
29734d7d6521
Added ShowMessageWithTimeStampServlet
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
143
diff
changeset
|
757 |
165 | 758 private static class BoardMessageImpl implements BoardMessage { |
38 | 759 private final String author; |
760 private final String message; | |
761 private final String uuid; | |
165 | 762 |
763 public BoardMessageImpl(String _author, String _message, String _uuid) { | |
38 | 764 author = _author; |
765 message = _message; | |
766 uuid = _uuid; | |
767 } | |
768 | |
165 | 769 public String getAuthor() { |
38 | 770 return author; |
771 } | |
772 | |
165 | 773 public String getMessage() { |
38 | 774 return message; |
775 } | |
776 | |
165 | 777 public String getUUID() { |
38 | 778 return uuid; |
779 } | |
143
7a7bac51a3cc
Added RequestNumCheckServlet
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
139
diff
changeset
|
780 |
38 | 781 } |
124 | 782 |
176 | 783 public String sanitize(String str) { |
784 if (str == null) { | |
785 return str; | |
786 } | |
787 str = str.replaceAll("&", "&"); | |
788 str = str.replaceAll("<", "<"); | |
789 str = str.replaceAll(">", ">"); | |
790 str = str.replaceAll("\"", """); | |
791 str = str.replaceAll("'", "'"); | |
792 return str; | |
793 } | |
170 | 794 |
190 | 795 @Override |
796 public String searchJungle(String requestName, String permmitName) { | |
797 // TODO Auto-generated method stub | |
798 return null; | |
799 } | |
800 | |
38 | 801 } |