Mercurial > hg > FederatedLinda
comparison src/fdl/FederatedLinda.java @ 24:35375016b2f0 simple-test-passed
cleanup.
author | kono |
---|---|
date | Wed, 20 Aug 2008 10:18:05 +0900 |
parents | b4fd7fb9135a |
children | 330fa49bc4fd |
comparison
equal
deleted
inserted
replaced
23:b4fd7fb9135a | 24:35375016b2f0 |
---|---|
67 } | 67 } |
68 | 68 |
69 public PSXLindaInterface open(String _host,int _port) | 69 public PSXLindaInterface open(String _host,int _port) |
70 throws IOException { | 70 throws IOException { |
71 tid++; | 71 tid++; |
72 // System.out.print("Tid = "); | |
73 // System.out.println(tid); | |
74 PSXLindaInterface newlinda = new PSXLinda(this,tid,_host,_port); | 72 PSXLindaInterface newlinda = new PSXLinda(this,tid,_host,_port); |
75 linda = newlinda.add(linda); | 73 linda = newlinda.add(linda); |
76 return linda; | 74 return linda; |
77 } | 75 } |
78 | |
79 /** | |
80 psx_queue (unsigned int tspace_id, unsigned int id, | |
81 unsigned int size, unsigned char *data, char mode, | |
82 void(*callback)(char*,void*), void * obj): | |
83 */ | |
84 | 76 |
85 public PSXReply psx_queue(PSXLinda linda, int id, ByteBuffer s, int mode, PSXCallback callback) { | 77 public PSXReply psx_queue(PSXLinda linda, int id, ByteBuffer s, int mode, PSXCallback callback) { |
86 PSXQueue c = new PSXQueue(linda,id,mode,s,callback); | 78 PSXQueue c = new PSXQueue(linda,id,mode,s,callback); |
87 | 79 |
88 if (q_top == null) { | 80 if (q_top == null) { |
95 | 87 |
96 if (mode != PSX.PSX_OUT) { | 88 if (mode != PSX.PSX_OUT) { |
97 PSXReply p = new PSXReply(PSX.PSX_REPLY,callback); | 89 PSXReply p = new PSXReply(PSX.PSX_REPLY,callback); |
98 p.seq = seq(p); | 90 p.seq = seq(p); |
99 c.setSeq(p.seq); | 91 c.setSeq(p.seq); |
100 if (debug) { | |
101 System.out.print("Integer compare="); | |
102 System.out.println((new Integer(2)).equals(new Integer(2))); | |
103 System.out.print("Sedning seq="); | |
104 System.out.println(p.seq); | |
105 } | |
106 if (r_top == null){ | 92 if (r_top == null){ |
107 r_end = r_top = p; | 93 r_end = r_top = p; |
108 } else { | 94 } else { |
109 r_end.next = p; | 95 r_end.next = p; |
110 r_end = p; | 96 r_end = p; |
147 | 133 |
148 while (q_top != null){ | 134 while (q_top != null){ |
149 PSXQueue c = q_top; | 135 PSXQueue c = q_top; |
150 c.send(); | 136 c.send(); |
151 q_top = c.next; | 137 q_top = c.next; |
152 // psx_free(c); | |
153 // q_top = c = t; | |
154 qsize--; | 138 qsize--; |
155 } | 139 } |
156 | 140 |
157 try { | 141 try { |
158 key_num = selector.select(mtimeout); | 142 key_num = selector.select(mtimeout); |
159 keys = selector.selectedKeys(); | 143 keys = selector.selectedKeys(); |
160 for (SelectionKey key : keys) { | 144 for (SelectionKey key : keys) { |
161 // System.out.println("selecting"); | |
162 SocketChannel sock = (SocketChannel)key.channel(); | 145 SocketChannel sock = (SocketChannel)key.channel(); |
163 chkServe(sock); | 146 chkServe(sock); |
164 } | 147 } |
165 } catch (IOException e) { | 148 } catch (IOException e) { |
166 e.printStackTrace(); | 149 e.printStackTrace(); |
195 data.rewind(); | 178 data.rewind(); |
196 | 179 |
197 if (debug) { | 180 if (debug) { |
198 PSX.printCommand(command, data); | 181 PSX.printCommand(command, data); |
199 } | 182 } |
200 /***if (debug) { | |
201 System.out.print("header:"); | |
202 for(int i=0;i<LINDA_HEADER_SIZE;i++) { | |
203 System.out.println(command.get(i)); | |
204 } | |
205 System.out.print("data:"); | |
206 for(int i=0;i<length;i++) { | |
207 System.out.println(data.get(i)); | |
208 } | |
209 data.rewind(); | |
210 }***/ | |
211 | 183 |
212 int rseq = command.getInt(PSX.LINDA_SEQ_OFFSET); | 184 int rseq = command.getInt(PSX.LINDA_SEQ_OFFSET); |
213 int mode = command.get(PSX.LINDA_MODE_OFFSET); | 185 int mode = command.get(PSX.LINDA_MODE_OFFSET); |
214 Integer a; | 186 PSXReply r = getReply(rseq); |
215 /*** | 187 r.setAnswer(mode,command,data); |
216 if (debug) { | 188 |
217 System.out.print("mode = "); | 189 if (r.callback != null ) { |
218 System.out.println(mode); | 190 r.callback.callback(data); |
219 System.out.print("seq = "); | 191 } |
220 System.out.println(rseq); | 192 } |
221 }***/ | 193 } |
222 try { | 194 |
223 PSXReply r = seqHash.get((a = new Integer(rseq))); | 195 private PSXReply getReply(int rseq) { |
224 seqHash.remove(a); | 196 Integer a; |
225 if (debug) { | 197 |
226 System.out.print("hash value = "); | 198 PSXReply r = seqHash.get((a = new Integer(rseq))); |
227 System.out.println(a.hashCode()); | 199 if (r==null) { |
228 } | 200 System.out.println("hashed reply not found"); |
229 | 201 } |
230 r.setAnswer(mode,command,data); | 202 seqHash.remove(a); |
231 | 203 return r; |
232 if (r.callback != null ) { | |
233 r.callback.callback(data); | |
234 } | |
235 } catch (NullPointerException e ) { | |
236 if (debug) { | |
237 System.out.println("hashed reply not found"); | |
238 } | |
239 // can't happen | |
240 return ; | |
241 } | |
242 } | |
243 } | 204 } |
244 } | 205 } |
245 | 206 |
246 /* end */ | 207 /* end */ |