annotate src/jungle/app/bbs/NetworkJungleBulletinBoard.java @ 91:2c7b3f2b2ee1

Removed serverName field
author one
date Mon, 11 Nov 2013 19:22:47 +0900
parents eef737ab3b2c
children e95faa202b4f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
66
29127ac788a6 move some files
one
parents: 65
diff changeset
1 package jungle.app.bbs;
38
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
2
46
fd3643699f83 modified pom.xml. fix conflict log4j libraries
one
parents: 45
diff changeset
3 import java.io.IOException;
38
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
4 import java.nio.ByteBuffer;
56
ccfe9b5e8f11 bug LogUpdateCodeSegment
one
parents: 52
diff changeset
5 import java.util.Date;
38
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
6 import java.util.concurrent.atomic.AtomicInteger;
39
10359a815068 add alice.jungle.codesegment.remote
one
parents: 38
diff changeset
7
10359a815068 add alice.jungle.codesegment.remote
one
parents: 38
diff changeset
8 import alice.jungle.core.NetworkDefaultJungle;
75
87ec5dd0dc27 Rename from alice.jungle.datasegment.store.operation to alice.jungle.datasegment.store.container
one
parents: 66
diff changeset
9 import alice.jungle.datasegment.store.container.DefaultTreeOperationLogContainer;
83
b3ccefdf2b43 Added PersistentExample
one
parents: 75
diff changeset
10 import alice.jungle.persistence.AliceJournal;
46
fd3643699f83 modified pom.xml. fix conflict log4j libraries
one
parents: 45
diff changeset
11 import alice.jungle.transaction.NetworkDefaultJungleTreeEditor;
38
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
12 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.Jungle;
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
13 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.JungleTree;
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
14 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.JungleTreeEditor;
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
15 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.core.Children;
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
16 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.core.Node;
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
17 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.DefaultNodePath;
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
18 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.DefaultTreeEditor;
46
fd3643699f83 modified pom.xml. fix conflict log4j libraries
one
parents: 45
diff changeset
19 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.TreeOperation;
38
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
20 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.trasnformer.EditableNode;
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
21 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.trasnformer.NodeEditor;
65
ebf42371454b remove warning
one
parents: 64
diff changeset
22 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.transaction.DefaultTreeNode;
38
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
23 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.traverser.DefaultTraverser;
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
24 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.DefaultEither;
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
25 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Either;
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
26 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Error;
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
27 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.IterableConverter;
66
29127ac788a6 move some files
one
parents: 65
diff changeset
28 import jungle.app.bbs.codesegment.HashLogUpdateCodeSegment;
38
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
29
39
10359a815068 add alice.jungle.codesegment.remote
one
parents: 38
diff changeset
30 public class NetworkJungleBulletinBoard implements BulletinBoard
38
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
31 {
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
32 private final Jungle jungle;
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
33
91
2c7b3f2b2ee1 Removed serverName field
one
parents: 90
diff changeset
34 public NetworkJungleBulletinBoard(String _uuid)
38
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
35 {
91
2c7b3f2b2ee1 Removed serverName field
one
parents: 90
diff changeset
36 jungle = new NetworkDefaultJungle(new AliceJournal(), _uuid,new DefaultTreeEditor(new DefaultTraverser()));
38
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
37 jungle.createNewTree("boards");
51
9e782b4eb06e add HashSetConvertDataSegment
one
parents: 50
diff changeset
38 JungleManager.setJungle(jungle);
38
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
39 }
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
40
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
41 public Iterable<String> getBoards()
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
42 {
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
43 JungleTree tree = jungle.getTreeByName("boards");
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
44 Node node = tree.getRootNode();
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
45 Children<Node> chs = node.getChildren();
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
46
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
47 IterableConverter.Converter<String,Node> converter = new IterableConverter.Converter<String,Node>(){
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
48 public String conv(Node _b) {
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
49 ByteBuffer e = _b.getAttributes().get("name");
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
50 return new String(e.array());
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
51 }
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
52 };
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
53
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
54 return new IterableConverter<String,Node>(chs,converter);
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
55 }
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
56
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
57 public void createBoards(final String _name,final String _author,final String _initMessage,final String _editKey)
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
58 {
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
59 if(null == jungle.createNewTree(_name)){
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
60 throw new IllegalStateException();
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
61 }
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
62
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
63 JungleTree tree = jungle.getTreeByName("boards");
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
64 JungleTreeEditor editor = tree.getTreeEditor();
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
65 DefaultNodePath root = new DefaultNodePath();
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
66 Either<Error,JungleTreeEditor> either = editor.addNewChildAt(root,0);
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
67 if(either.isA()){
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
68 throw new IllegalStateException();
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
69 }
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
70 editor = either.b();
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
71
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
72 either = editor.putAttribute(root.add(0),"name",ByteBuffer.wrap(_name.getBytes()));
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
73 if(either.isA()){
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
74 throw new IllegalStateException();
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
75 }
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
76 editor = either.b();
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
77 Either<Error,JungleTreeEditor> result = editor.success();
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
78 if(result.isA()){
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
79 throw new IllegalStateException();
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
80 }
56
ccfe9b5e8f11 bug LogUpdateCodeSegment
one
parents: 52
diff changeset
81 final long timestamp = new Date().getTime();
46
fd3643699f83 modified pom.xml. fix conflict log4j libraries
one
parents: 45
diff changeset
82 /* Put DataSegment */
fd3643699f83 modified pom.xml. fix conflict log4j libraries
one
parents: 45
diff changeset
83 try {
90
eef737ab3b2c Modified JungleManager class
one
parents: 83
diff changeset
84 putTreeOperationLog((NetworkDefaultJungleTreeEditor)editor,timestamp);
46
fd3643699f83 modified pom.xml. fix conflict log4j libraries
one
parents: 45
diff changeset
85 } catch (IOException e1) {
fd3643699f83 modified pom.xml. fix conflict log4j libraries
one
parents: 45
diff changeset
86 e1.printStackTrace();
fd3643699f83 modified pom.xml. fix conflict log4j libraries
one
parents: 45
diff changeset
87 }
38
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
88
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
89 tree = jungle.getTreeByName(_name);
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
90 editor = tree.getTreeEditor();
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
91 either = editor.addNewChildAt(root,0);
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
92 if(either.isA()){
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
93 throw new IllegalStateException();
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
94 }
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
95 editor = either.b();
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
96
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
97 NodeEditor e = new NodeEditor(){
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
98 public <T extends EditableNode<T>> Either<Error, T> edit(T _e){
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
99 _e = _e.getAttributes().put("author",ByteBuffer.wrap(_author.getBytes())).b();
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
100 _e = _e.getAttributes().put("mes",ByteBuffer.wrap(_initMessage.getBytes())).b();
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
101 _e = _e.getAttributes().put("key",ByteBuffer.wrap(_editKey.getBytes())).b();
56
ccfe9b5e8f11 bug LogUpdateCodeSegment
one
parents: 52
diff changeset
102 ByteBuffer tBuffer = ByteBuffer.allocate(16);
ccfe9b5e8f11 bug LogUpdateCodeSegment
one
parents: 52
diff changeset
103 _e = _e.getAttributes().put("timestamp",tBuffer.putLong(timestamp)).b();
38
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
104 return DefaultEither.newB(_e);
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
105 }
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
106 };
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
107
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
108 either = editor.edit(root.add(0),e);
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
109 if(either.isA()){
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
110 throw new IllegalStateException();
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
111 }
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
112 editor = either.b();
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
113 editor.success();
46
fd3643699f83 modified pom.xml. fix conflict log4j libraries
one
parents: 45
diff changeset
114 /* Put DataSegment */
fd3643699f83 modified pom.xml. fix conflict log4j libraries
one
parents: 45
diff changeset
115 try {
90
eef737ab3b2c Modified JungleManager class
one
parents: 83
diff changeset
116 putTreeOperationLog((NetworkDefaultJungleTreeEditor)editor, timestamp);
46
fd3643699f83 modified pom.xml. fix conflict log4j libraries
one
parents: 45
diff changeset
117 } catch (IOException e1) {
fd3643699f83 modified pom.xml. fix conflict log4j libraries
one
parents: 45
diff changeset
118 e1.printStackTrace();
fd3643699f83 modified pom.xml. fix conflict log4j libraries
one
parents: 45
diff changeset
119 }
fd3643699f83 modified pom.xml. fix conflict log4j libraries
one
parents: 45
diff changeset
120
38
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
121 }
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
122
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
123 public void createBoardMessage(final String _board,final String _author,final String _message,final String _editKey)
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
124 {
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
125 JungleTree tree = jungle.getTreeByName(_board);
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
126 if(tree == null){
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
127 throw new IllegalStateException();
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
128 }
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
129
46
fd3643699f83 modified pom.xml. fix conflict log4j libraries
one
parents: 45
diff changeset
130 Either<Error, JungleTreeEditor> either;
38
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
131 do{
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
132 Node node = tree.getRootNode();
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
133 int size = node.getChildren().size();
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
134 DefaultNodePath path = new DefaultNodePath();
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
135
65
ebf42371454b remove warning
one
parents: 64
diff changeset
136 JungleTreeEditor editor = tree.getTreeEditor();
46
fd3643699f83 modified pom.xml. fix conflict log4j libraries
one
parents: 45
diff changeset
137 either = editor.addNewChildAt(path,size);
38
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
138 if(either.isA()){
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
139 throw new IllegalStateException();
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
140 }
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
141 editor = either.b();
56
ccfe9b5e8f11 bug LogUpdateCodeSegment
one
parents: 52
diff changeset
142 final long timestamp = new Date().getTime();
38
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
143 NodeEditor e = new NodeEditor(){
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
144 public <T extends EditableNode<T>> Either<Error, T> edit(T _e){
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
145 _e = _e.getAttributes().put("author",ByteBuffer.wrap(_author.getBytes())).b();
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
146 _e = _e.getAttributes().put("mes",ByteBuffer.wrap(_message.getBytes())).b();
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
147 _e = _e.getAttributes().put("key",ByteBuffer.wrap(_editKey.getBytes())).b();
56
ccfe9b5e8f11 bug LogUpdateCodeSegment
one
parents: 52
diff changeset
148 ByteBuffer tBuffer = ByteBuffer.allocate(16);
ccfe9b5e8f11 bug LogUpdateCodeSegment
one
parents: 52
diff changeset
149 _e = _e.getAttributes().put("timestamp",tBuffer.putLong(timestamp)).b();
38
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
150 return DefaultEither.newB(_e);
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
151 }
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
152 };
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
153 path = path.add(size);
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
154 either = editor.edit(path,e);
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
155 if(either.isA()){
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
156 throw new IllegalStateException();
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
157 }
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
158 editor = either.b();
46
fd3643699f83 modified pom.xml. fix conflict log4j libraries
one
parents: 45
diff changeset
159 either = editor.success();
fd3643699f83 modified pom.xml. fix conflict log4j libraries
one
parents: 45
diff changeset
160 try {
65
ebf42371454b remove warning
one
parents: 64
diff changeset
161 NetworkDefaultJungleTreeEditor<DefaultTreeNode> netEditor = (NetworkDefaultJungleTreeEditor<DefaultTreeNode>) editor;
90
eef737ab3b2c Modified JungleManager class
one
parents: 83
diff changeset
162 putTreeOperationLog(netEditor, timestamp);
46
fd3643699f83 modified pom.xml. fix conflict log4j libraries
one
parents: 45
diff changeset
163 } catch (IOException e1) {
fd3643699f83 modified pom.xml. fix conflict log4j libraries
one
parents: 45
diff changeset
164 e1.printStackTrace();
fd3643699f83 modified pom.xml. fix conflict log4j libraries
one
parents: 45
diff changeset
165 }
fd3643699f83 modified pom.xml. fix conflict log4j libraries
one
parents: 45
diff changeset
166 }while(either.isA());
51
9e782b4eb06e add HashSetConvertDataSegment
one
parents: 50
diff changeset
167 /* Put DataSegment */
38
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
168 }
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
169
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
170 public void editMessage(String _board,String _uuid,final String _author,final String _message,final String _editKey)
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
171 {
65
ebf42371454b remove warning
one
parents: 64
diff changeset
172 for(;;) {
38
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
173 DefaultNodePath path = new DefaultNodePath();
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
174 path = path.add(Integer.parseInt(_uuid));
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
175
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
176 JungleTree tree = jungle.getTreeByName(_board);
65
ebf42371454b remove warning
one
parents: 64
diff changeset
177 JungleTreeEditor editor = tree.getTreeEditor();
56
ccfe9b5e8f11 bug LogUpdateCodeSegment
one
parents: 52
diff changeset
178 final long timestamp = new Date().getTime();
38
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
179 NodeEditor e = new NodeEditor(){
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
180 public <T extends EditableNode<T>> Either<Error, T> edit(T _e){
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
181 _e = _e.getAttributes().put("author",ByteBuffer.wrap(_author.getBytes())).b();
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
182 _e = _e.getAttributes().put("mes",ByteBuffer.wrap(_message.getBytes())).b();
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
183 _e = _e.getAttributes().put("key",ByteBuffer.wrap(_editKey.getBytes())).b();
56
ccfe9b5e8f11 bug LogUpdateCodeSegment
one
parents: 52
diff changeset
184 ByteBuffer tBuffer = ByteBuffer.allocate(16);
ccfe9b5e8f11 bug LogUpdateCodeSegment
one
parents: 52
diff changeset
185 _e = _e.getAttributes().put("timestamp",tBuffer.putLong(timestamp)).b();
38
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
186 return DefaultEither.newB(_e);
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
187 }
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
188 };
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
189
65
ebf42371454b remove warning
one
parents: 64
diff changeset
190 Either<Error, JungleTreeEditor> either = editor.edit(path,e);
38
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
191 if(either.isA()){
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
192 throw new IllegalStateException();
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
193 }
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
194 editor = either.b();
46
fd3643699f83 modified pom.xml. fix conflict log4j libraries
one
parents: 45
diff changeset
195 either = editor.success();
fd3643699f83 modified pom.xml. fix conflict log4j libraries
one
parents: 45
diff changeset
196 try {
90
eef737ab3b2c Modified JungleManager class
one
parents: 83
diff changeset
197 putTreeOperationLog((NetworkDefaultJungleTreeEditor)editor, timestamp);
46
fd3643699f83 modified pom.xml. fix conflict log4j libraries
one
parents: 45
diff changeset
198 } catch (IOException e1) {
fd3643699f83 modified pom.xml. fix conflict log4j libraries
one
parents: 45
diff changeset
199 e1.printStackTrace();
fd3643699f83 modified pom.xml. fix conflict log4j libraries
one
parents: 45
diff changeset
200 }
65
ebf42371454b remove warning
one
parents: 64
diff changeset
201 if(!either.isA()) {
ebf42371454b remove warning
one
parents: 64
diff changeset
202 return;
ebf42371454b remove warning
one
parents: 64
diff changeset
203 }
ebf42371454b remove warning
one
parents: 64
diff changeset
204 }
ebf42371454b remove warning
one
parents: 64
diff changeset
205
38
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
206 }
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
207
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
208 public Iterable<BoardMessage> getMessages(String _boardName)
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
209 {
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
210 JungleTree tree = jungle.getTreeByName(_boardName);
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
211 Node node = tree.getRootNode();
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
212 Children<Node> chs = node.getChildren();
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
213
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
214 final AtomicInteger counter = new AtomicInteger(0);
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
215 IterableConverter.Converter<BoardMessage,Node> converter = new IterableConverter.Converter<BoardMessage,Node>(){
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
216 public BoardMessage conv(Node _b) {
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
217 String uuid = Integer.toString(counter.get());
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
218 String author = new String(_b.getAttributes().get("author").array());
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
219 String message = new String(_b.getAttributes().get("mes").array());
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
220 counter.incrementAndGet();
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
221 return new BoardMessageImpl(author,message,uuid);
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
222 }
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
223 };
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
224
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
225 return new IterableConverter<BoardMessage,Node>(chs,converter);
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
226 }
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
227
90
eef737ab3b2c Modified JungleManager class
one
parents: 83
diff changeset
228 private void putTreeOperationLog(NetworkDefaultJungleTreeEditor<DefaultTreeNode> editor, long timestamp) throws IOException {
46
fd3643699f83 modified pom.xml. fix conflict log4j libraries
one
parents: 45
diff changeset
229 String uuid = editor.getID();
fd3643699f83 modified pom.xml. fix conflict log4j libraries
one
parents: 45
diff changeset
230 String treeName = editor.getTreeName();
49
a89c3539bff2 modified LogUpdateCodeSegment
one
parents: 47
diff changeset
231 String updaterName = editor.getUpdaterName();
52
61b2de3f7730 add HashSetDataSegment and HashLogUpdateCodeSegment.
one
parents: 51
diff changeset
232 String revision = editor.getRevision();
46
fd3643699f83 modified pom.xml. fix conflict log4j libraries
one
parents: 45
diff changeset
233 Iterable<TreeOperation> log = editor.getTreeOperationLog();
90
eef737ab3b2c Modified JungleManager class
one
parents: 83
diff changeset
234 putDataSegment(uuid, treeName, updaterName, log, revision, timestamp);
46
fd3643699f83 modified pom.xml. fix conflict log4j libraries
one
parents: 45
diff changeset
235 }
fd3643699f83 modified pom.xml. fix conflict log4j libraries
one
parents: 45
diff changeset
236
90
eef737ab3b2c Modified JungleManager class
one
parents: 83
diff changeset
237 private void putDataSegment(String _uuid, String _treeName, String _updaterName, Iterable<TreeOperation> _log, String nextRevision,long timestamp) throws IOException {
46
fd3643699f83 modified pom.xml. fix conflict log4j libraries
one
parents: 45
diff changeset
238 DefaultTreeOperationLogContainer container = new DefaultTreeOperationLogContainer();
fd3643699f83 modified pom.xml. fix conflict log4j libraries
one
parents: 45
diff changeset
239 container.setTreeName(_treeName);
fd3643699f83 modified pom.xml. fix conflict log4j libraries
one
parents: 45
diff changeset
240 container.setUUID(_uuid);
49
a89c3539bff2 modified LogUpdateCodeSegment
one
parents: 47
diff changeset
241 container.setUpdaterName(_updaterName);
46
fd3643699f83 modified pom.xml. fix conflict log4j libraries
one
parents: 45
diff changeset
242 container.setRevision(nextRevision);
fd3643699f83 modified pom.xml. fix conflict log4j libraries
one
parents: 45
diff changeset
243 container.unconvert(_log);
56
ccfe9b5e8f11 bug LogUpdateCodeSegment
one
parents: 52
diff changeset
244 container.setTimeStamp(timestamp);
ccfe9b5e8f11 bug LogUpdateCodeSegment
one
parents: 52
diff changeset
245 HashLogUpdateCodeSegment cs = new HashLogUpdateCodeSegment();
47
686057add8a4 confirmed LogUpdateCodeSegment
one
parents: 46
diff changeset
246 cs.ods.put("log", container);
56
ccfe9b5e8f11 bug LogUpdateCodeSegment
one
parents: 52
diff changeset
247 cs.ods.put("logString", container.getHashLogString());
52
61b2de3f7730 add HashSetDataSegment and HashLogUpdateCodeSegment.
one
parents: 51
diff changeset
248 /* If this node is not Root node, push log to parent node's DS */
50
459b50f1a6ee add ChildLogCheckCodeSegment.
one
parents: 49
diff changeset
249 if(!_updaterName.equals("node0")) {
51
9e782b4eb06e add HashSetConvertDataSegment
one
parents: 50
diff changeset
250 cs.ods.put("parent", "childLog", container);
50
459b50f1a6ee add ChildLogCheckCodeSegment.
one
parents: 49
diff changeset
251 }
46
fd3643699f83 modified pom.xml. fix conflict log4j libraries
one
parents: 45
diff changeset
252 }
fd3643699f83 modified pom.xml. fix conflict log4j libraries
one
parents: 45
diff changeset
253
fd3643699f83 modified pom.xml. fix conflict log4j libraries
one
parents: 45
diff changeset
254
38
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
255 private static class BoardMessageImpl implements BoardMessage
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
256 {
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
257 private final String author;
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
258 private final String message;
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
259 private final String uuid;
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
260
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
261 public BoardMessageImpl(String _author,String _message,String _uuid)
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
262 {
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
263 author = _author;
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
264 message = _message;
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
265 uuid = _uuid;
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
266 }
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
267
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
268 public String getAuthor()
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
269 {
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
270 return author;
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
271 }
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
272
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
273 public String getMessage()
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
274 {
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
275 return message;
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
276 }
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
277
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
278 public String getUUID()
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
279 {
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
280 return uuid;
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
281 }
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
282 }
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
283 }