annotate src/fdl/FederatedLinda.java @ 11:1355eb28e41d

fix seqHash removal on checkServe.
author kono
date Sat, 09 Aug 2008 19:06:32 +0900
parents b49e593b2502
children aced4bfc15af
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
083a0b5e12cc Apply Debug Interface version start
fuchita
parents:
diff changeset
1
083a0b5e12cc Apply Debug Interface version start
fuchita
parents:
diff changeset
2 /*
083a0b5e12cc Apply Debug Interface version start
fuchita
parents:
diff changeset
3 * @(#)FederatedLinda.java 1.1 06/04/01
083a0b5e12cc Apply Debug Interface version start
fuchita
parents:
diff changeset
4 *
083a0b5e12cc Apply Debug Interface version start
fuchita
parents:
diff changeset
5 * Copyright 2006 Shinji KONO
083a0b5e12cc Apply Debug Interface version start
fuchita
parents:
diff changeset
6 *
083a0b5e12cc Apply Debug Interface version start
fuchita
parents:
diff changeset
7
083a0b5e12cc Apply Debug Interface version start
fuchita
parents:
diff changeset
8 PSX Lidna
083a0b5e12cc Apply Debug Interface version start
fuchita
parents:
diff changeset
9 Trasport layer of PSX Linda library
083a0b5e12cc Apply Debug Interface version start
fuchita
parents:
diff changeset
10
083a0b5e12cc Apply Debug Interface version start
fuchita
parents:
diff changeset
11 */
083a0b5e12cc Apply Debug Interface version start
fuchita
parents:
diff changeset
12
083a0b5e12cc Apply Debug Interface version start
fuchita
parents:
diff changeset
13 package fdl;
083a0b5e12cc Apply Debug Interface version start
fuchita
parents:
diff changeset
14
083a0b5e12cc Apply Debug Interface version start
fuchita
parents:
diff changeset
15 import java.io.IOException;
083a0b5e12cc Apply Debug Interface version start
fuchita
parents:
diff changeset
16 import java.nio.ByteBuffer;
083a0b5e12cc Apply Debug Interface version start
fuchita
parents:
diff changeset
17 import java.nio.ByteOrder;
2
b49e593b2502 Add ComDebug_Client
fuchita
parents: 0
diff changeset
18 import java.nio.CharBuffer;
0
083a0b5e12cc Apply Debug Interface version start
fuchita
parents:
diff changeset
19 import java.nio.channels.ClosedSelectorException;
083a0b5e12cc Apply Debug Interface version start
fuchita
parents:
diff changeset
20 import java.nio.channels.SelectionKey;
083a0b5e12cc Apply Debug Interface version start
fuchita
parents:
diff changeset
21 import java.nio.channels.Selector;
083a0b5e12cc Apply Debug Interface version start
fuchita
parents:
diff changeset
22 import java.nio.channels.SocketChannel;
083a0b5e12cc Apply Debug Interface version start
fuchita
parents:
diff changeset
23 import java.util.Hashtable;
083a0b5e12cc Apply Debug Interface version start
fuchita
parents:
diff changeset
24 import java.util.Set;
083a0b5e12cc Apply Debug Interface version start
fuchita
parents:
diff changeset
25
083a0b5e12cc Apply Debug Interface version start
fuchita
parents:
diff changeset
26
083a0b5e12cc Apply Debug Interface version start
fuchita
parents:
diff changeset
27 /**
083a0b5e12cc Apply Debug Interface version start
fuchita
parents:
diff changeset
28 FederatedLinda
083a0b5e12cc Apply Debug Interface version start
fuchita
parents:
diff changeset
29 *
083a0b5e12cc Apply Debug Interface version start
fuchita
parents:
diff changeset
30 * @author Shinji Kono
083a0b5e12cc Apply Debug Interface version start
fuchita
parents:
diff changeset
31 *
083a0b5e12cc Apply Debug Interface version start
fuchita
parents:
diff changeset
32 * @param mytsid Tuple Space ID
083a0b5e12cc Apply Debug Interface version start
fuchita
parents:
diff changeset
33
083a0b5e12cc Apply Debug Interface version start
fuchita
parents:
diff changeset
34 Initialize connection channel for a tuple space
083a0b5e12cc Apply Debug Interface version start
fuchita
parents:
diff changeset
35
083a0b5e12cc Apply Debug Interface version start
fuchita
parents:
diff changeset
36 one instance for each Tuple space connection
083a0b5e12cc Apply Debug Interface version start
fuchita
parents:
diff changeset
37
083a0b5e12cc Apply Debug Interface version start
fuchita
parents:
diff changeset
38 */
083a0b5e12cc Apply Debug Interface version start
fuchita
parents:
diff changeset
39
083a0b5e12cc Apply Debug Interface version start
fuchita
parents:
diff changeset
40 public class FederatedLinda implements PSXQueueInterface {
083a0b5e12cc Apply Debug Interface version start
fuchita
parents:
diff changeset
41
11
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
42 static FederatedLinda fdl;
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
43 static int MAX_SEQUENCE = 2048;
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
44 static boolean debug = true;
0
083a0b5e12cc Apply Debug Interface version start
fuchita
parents:
diff changeset
45
11
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
46 public int tid;
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
47 public int seq;
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
48 public int qsize;
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
49 public PSXLinda linda;
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
50
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
51 public Selector selector;
0
083a0b5e12cc Apply Debug Interface version start
fuchita
parents:
diff changeset
52
11
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
53 public PSXQueue q_top,q_end;
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
54 public PSXReply r_top,r_end;
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
55 public Hashtable<Integer,PSXReply> seqHash;
0
083a0b5e12cc Apply Debug Interface version start
fuchita
parents:
diff changeset
56
11
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
57 static FederatedLinda init()
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
58 throws IOException {
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
59 if (fdl==null) {
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
60 fdl = new FederatedLinda();
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
61 }
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
62 return fdl;
0
083a0b5e12cc Apply Debug Interface version start
fuchita
parents:
diff changeset
63 }
083a0b5e12cc Apply Debug Interface version start
fuchita
parents:
diff changeset
64
11
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
65 private FederatedLinda()
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
66 throws IOException {
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
67 selector = Selector.open();
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
68 seqHash = new Hashtable<Integer, PSXReply>();
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
69 }
0
083a0b5e12cc Apply Debug Interface version start
fuchita
parents:
diff changeset
70
11
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
71 public PSXLinda open(String _host,int _port)
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
72 throws IOException {
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
73 tid++;
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
74 // System.out.print("Tid = ");
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
75 // System.out.println(tid);
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
76 PSXLinda newlinda = new PSXLinda(this,tid,_host,_port);
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
77 linda = newlinda.add(linda);
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
78 return linda;
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
79 }
0
083a0b5e12cc Apply Debug Interface version start
fuchita
parents:
diff changeset
80
11
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
81 /**
0
083a0b5e12cc Apply Debug Interface version start
fuchita
parents:
diff changeset
82 psx_queue (unsigned int tspace_id, unsigned int id,
083a0b5e12cc Apply Debug Interface version start
fuchita
parents:
diff changeset
83 unsigned int size, unsigned char *data, char mode,
083a0b5e12cc Apply Debug Interface version start
fuchita
parents:
diff changeset
84 void(*callback)(char*,void*), void * obj):
11
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
85 */
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
86
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
87 public PSXReply psx_queue(PSXLinda linda, int id, ByteBuffer s, int length, int mode, PSXCallback callback) {
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
88 PSXQueue c = new PSXQueue(linda,id,mode,s,length,callback);
0
083a0b5e12cc Apply Debug Interface version start
fuchita
parents:
diff changeset
89
11
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
90 if (q_top == null) {
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
91 c = q_end = q_top = c;
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
92 } else {
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
93 q_end.next = c;
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
94 q_end = c;
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
95 }
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
96 qsize++;
0
083a0b5e12cc Apply Debug Interface version start
fuchita
parents:
diff changeset
97
11
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
98 if (mode != PSX_OUT) {
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
99 PSXReply p = new PSXReply(PSX_REPLY,callback);
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
100 p.seq = seq(p);
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
101 c.setSeq(p.seq);
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
102 if (debug) {
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
103 System.out.print("Integer compare=");
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
104 System.out.println((new Integer(2)).equals(new Integer(2)));
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
105 System.out.print("Seding seq=");
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
106 System.out.println(p.seq);
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
107 }
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
108 if (r_top == null){
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
109 r_end = r_top = p;
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
110 } else {
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
111 r_end.next = p;
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
112 r_end = p;
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
113 }
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
114 return p;
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
115 }
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
116 return null;
0
083a0b5e12cc Apply Debug Interface version start
fuchita
parents:
diff changeset
117 }
083a0b5e12cc Apply Debug Interface version start
fuchita
parents:
diff changeset
118
11
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
119 public int seq(PSXReply reply) {
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
120 Integer s;
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
121 do {
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
122 seq++;
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
123 if (seq>MAX_SEQUENCE) {
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
124 seq = 0;
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
125 }
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
126 s = new Integer(seq);
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
127 } while (seqHash.containsKey(s));
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
128 if (debug) {
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
129 System.out.print("hash value = ");
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
130 System.out.println(s.hashCode());
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
131 }
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
132 seqHash.put(s,reply);
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
133 seq++;
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
134 return seq-1;
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
135 }
0
083a0b5e12cc Apply Debug Interface version start
fuchita
parents:
diff changeset
136
11
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
137 public Selector selector() {
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
138 return selector;
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
139 }
0
083a0b5e12cc Apply Debug Interface version start
fuchita
parents:
diff changeset
140
11
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
141 public int sync() throws IOException {
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
142 return sync(0);
0
083a0b5e12cc Apply Debug Interface version start
fuchita
parents:
diff changeset
143 }
083a0b5e12cc Apply Debug Interface version start
fuchita
parents:
diff changeset
144
11
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
145 public int sync(long mtimeout)
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
146 throws IOException {
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
147 int key_num = 0;
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
148 Set<SelectionKey> keys;
0
083a0b5e12cc Apply Debug Interface version start
fuchita
parents:
diff changeset
149
11
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
150 while (q_top != null){
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
151 PSXQueue c = q_top;
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
152 c.Send();
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
153 q_top = c.next;
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
154 // psx_free(c);
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
155 // q_top = c = t;
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
156 qsize--;
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
157 }
2
b49e593b2502 Add ComDebug_Client
fuchita
parents: 0
diff changeset
158
11
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
159 try {
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
160 key_num = selector.select(mtimeout);
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
161 keys = selector.selectedKeys();
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
162 for (SelectionKey key : keys) {
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
163 // System.out.println("selecting");
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
164 SocketChannel sock = (SocketChannel)key.channel();
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
165 chkServe(sock);
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
166 }
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
167 } catch (IOException e) {
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
168 e.printStackTrace();
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
169 } catch (ClosedSelectorException e) {
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
170 e.printStackTrace();
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
171 }
2
b49e593b2502 Add ComDebug_Client
fuchita
parents: 0
diff changeset
172
11
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
173 return key_num;
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
174 }
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
175
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
176 public int sync_com(long mtimeout)
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
177 throws IOException {
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
178 int key_num = 0;
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
179 Set<SelectionKey> keys;
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
180
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
181 while (q_top != null){
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
182 PSXQueue c = q_top;
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
183 c.Send();
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
184 q_top = c.next;
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
185 // psx_free(c);
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
186 // q_top = c = t;
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
187 qsize--;
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
188 }
2
b49e593b2502 Add ComDebug_Client
fuchita
parents: 0
diff changeset
189
11
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
190 try {
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
191 key_num = selector.select(mtimeout);
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
192 keys = selector.selectedKeys();
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
193 for (SelectionKey key : keys) {
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
194 SocketChannel sock = (SocketChannel)key.channel();
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
195 chkCom(sock);
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
196 }
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
197 } catch (IOException e) {
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
198 e.printStackTrace();
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
199 } catch (ClosedSelectorException e) {
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
200 e.printStackTrace();
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
201 }
2
b49e593b2502 Add ComDebug_Client
fuchita
parents: 0
diff changeset
202
11
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
203 return key_num;
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
204 }
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
205
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
206 // should be in PSXLinda, but sock->linda is unknown here
2
b49e593b2502 Add ComDebug_Client
fuchita
parents: 0
diff changeset
207
11
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
208 private void chkCom(SocketChannel sock) throws IOException {
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
209
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
210 int length;
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
211 ByteBuffer command = ByteBuffer.allocate(LINDA_HEADER_SIZE);
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
212 command.order(ByteOrder.BIG_ENDIAN);
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
213 debug = false;
2
b49e593b2502 Add ComDebug_Client
fuchita
parents: 0
diff changeset
214
11
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
215 sock.read(command);
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
216 command.rewind();
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
217 length = command.getInt(LINDA_DATA_LENGTH_OFFSET);
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
218 if (length>0) {
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
219 ByteBuffer data = ByteBuffer.allocate(length);
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
220 int read = length;
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
221 if (debug) {
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
222 System.out.print("reading:");
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
223 System.out.println(length);
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
224 }
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
225
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
226 data.order(ByteOrder.BIG_ENDIAN);
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
227 while(read>0) {
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
228 read -= sock.read(data);
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
229 }
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
230 data.rewind();
2
b49e593b2502 Add ComDebug_Client
fuchita
parents: 0
diff changeset
231
11
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
232 if (debug) {
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
233 char id = (char)command.getShort(LINDA_ID_OFFSET);
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
234 System.out.println("LENGTH:"+command.getInt(LINDA_PACKET_LENGTH_OFFSET)+" "+
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
235 "MODE:"+(char)command.get(LINDA_MODE_OFFSET)+" "+
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
236 "ID:"+(int)id+" "+
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
237 "SEQ:"+command.getInt(LINDA_SEQ_OFFSET)+" "+
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
238 "DATA LENGTH:"+command.getInt(LINDA_DATA_LENGTH_OFFSET)+" ");
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
239 System.out.println("DATA:"+data);
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
240 command.rewind();
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
241 }
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
242 //if (debug_com) {
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
243 String comdata ="";
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
244 CharBuffer chardata = data.asCharBuffer();
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
245 comdata = chardata.toString();
2
b49e593b2502 Add ComDebug_Client
fuchita
parents: 0
diff changeset
246
11
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
247 //System.out.println("Com_data =>");
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
248 System.out.println(comdata);
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
249 //}
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
250 /***if (debug) {
2
b49e593b2502 Add ComDebug_Client
fuchita
parents: 0
diff changeset
251 System.out.print("header:");
b49e593b2502 Add ComDebug_Client
fuchita
parents: 0
diff changeset
252 for(int i=0;i<LINDA_HEADER_SIZE;i++) {
b49e593b2502 Add ComDebug_Client
fuchita
parents: 0
diff changeset
253 System.out.println(command.get(i));
b49e593b2502 Add ComDebug_Client
fuchita
parents: 0
diff changeset
254 }
b49e593b2502 Add ComDebug_Client
fuchita
parents: 0
diff changeset
255 System.out.print("data:");
b49e593b2502 Add ComDebug_Client
fuchita
parents: 0
diff changeset
256 for(int i=0;i<length;i++) {
b49e593b2502 Add ComDebug_Client
fuchita
parents: 0
diff changeset
257 System.out.println(data.get(i));
b49e593b2502 Add ComDebug_Client
fuchita
parents: 0
diff changeset
258 }
b49e593b2502 Add ComDebug_Client
fuchita
parents: 0
diff changeset
259 data.rewind();
b49e593b2502 Add ComDebug_Client
fuchita
parents: 0
diff changeset
260 }***/
11
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
261
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
262 int rseq = command.getInt(LINDA_SEQ_OFFSET);
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
263 int mode = command.get(LINDA_MODE_OFFSET);
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
264 Integer a;
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
265 /***
2
b49e593b2502 Add ComDebug_Client
fuchita
parents: 0
diff changeset
266 if (debug) {
b49e593b2502 Add ComDebug_Client
fuchita
parents: 0
diff changeset
267 System.out.print("mode = ");
b49e593b2502 Add ComDebug_Client
fuchita
parents: 0
diff changeset
268 System.out.println(mode);
b49e593b2502 Add ComDebug_Client
fuchita
parents: 0
diff changeset
269 System.out.print("seq = ");
b49e593b2502 Add ComDebug_Client
fuchita
parents: 0
diff changeset
270 System.out.println(rseq);
b49e593b2502 Add ComDebug_Client
fuchita
parents: 0
diff changeset
271 }***/
11
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
272 try {
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
273 PSXReply r = seqHash.get((a = new Integer(rseq)));
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
274 seqHash.put(a, null);
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
275 if (debug) {
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
276 System.out.print("hash value = ");
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
277 System.out.println(a.hashCode());
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
278 }
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
279
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
280 r.setAnswer(mode,command,data);
2
b49e593b2502 Add ComDebug_Client
fuchita
parents: 0
diff changeset
281
11
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
282 if (r.callback != null ) {
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
283 r.callback.callback(data);
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
284 }
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
285 } catch (NullPointerException e ) {
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
286 if (debug) {
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
287 System.out.println("hashed reply not found");
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
288 }
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
289 // can't happen
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
290 return ;
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
291 }
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
292 }
2
b49e593b2502 Add ComDebug_Client
fuchita
parents: 0
diff changeset
293 }
b49e593b2502 Add ComDebug_Client
fuchita
parents: 0
diff changeset
294
b49e593b2502 Add ComDebug_Client
fuchita
parents: 0
diff changeset
295 private void chkServe(SocketChannel sock)
11
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
296 throws IOException {
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
297 int length;
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
298 ByteBuffer command = ByteBuffer.allocate(LINDA_HEADER_SIZE);
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
299 command.order(ByteOrder.BIG_ENDIAN);
0
083a0b5e12cc Apply Debug Interface version start
fuchita
parents:
diff changeset
300
11
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
301 sock.read(command);
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
302 command.rewind();
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
303 length = command.getInt(LINDA_DATA_LENGTH_OFFSET);
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
304 if (length>0) {
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
305 ByteBuffer data = ByteBuffer.allocate(length);
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
306 int read = length;
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
307 if (debug) {
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
308 System.out.print("reading:");
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
309 System.out.println(length);
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
310 }
0
083a0b5e12cc Apply Debug Interface version start
fuchita
parents:
diff changeset
311
11
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
312 data.order(ByteOrder.BIG_ENDIAN);
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
313 while(read>0) {
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
314 read -= sock.read(data);
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
315 }
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
316 data.rewind();
2
b49e593b2502 Add ComDebug_Client
fuchita
parents: 0
diff changeset
317
11
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
318 if (debug) {
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
319 char id = (char)command.getShort(LINDA_ID_OFFSET);
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
320 System.out.println("LENGTH:"+command.getInt(LINDA_PACKET_LENGTH_OFFSET)+" "+
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
321 "MODE:"+(char)command.get(LINDA_MODE_OFFSET)+" "+
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
322 "ID:"+(int)id+" "+
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
323 "SEQ:"+command.getInt(LINDA_SEQ_OFFSET)+" "+
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
324 "DATA LENGTH:"+command.getInt(LINDA_DATA_LENGTH_OFFSET)+" ");
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
325 System.out.println("DATA:"+data);
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
326 command.rewind();
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
327 }
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
328 /***if (debug) {
0
083a0b5e12cc Apply Debug Interface version start
fuchita
parents:
diff changeset
329 System.out.print("header:");
083a0b5e12cc Apply Debug Interface version start
fuchita
parents:
diff changeset
330 for(int i=0;i<LINDA_HEADER_SIZE;i++) {
083a0b5e12cc Apply Debug Interface version start
fuchita
parents:
diff changeset
331 System.out.println(command.get(i));
083a0b5e12cc Apply Debug Interface version start
fuchita
parents:
diff changeset
332 }
083a0b5e12cc Apply Debug Interface version start
fuchita
parents:
diff changeset
333 System.out.print("data:");
083a0b5e12cc Apply Debug Interface version start
fuchita
parents:
diff changeset
334 for(int i=0;i<length;i++) {
083a0b5e12cc Apply Debug Interface version start
fuchita
parents:
diff changeset
335 System.out.println(data.get(i));
083a0b5e12cc Apply Debug Interface version start
fuchita
parents:
diff changeset
336 }
083a0b5e12cc Apply Debug Interface version start
fuchita
parents:
diff changeset
337 data.rewind();
2
b49e593b2502 Add ComDebug_Client
fuchita
parents: 0
diff changeset
338 }***/
11
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
339
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
340 int rseq = command.getInt(LINDA_SEQ_OFFSET);
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
341 int mode = command.get(LINDA_MODE_OFFSET);
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
342 Integer a;
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
343 /***
0
083a0b5e12cc Apply Debug Interface version start
fuchita
parents:
diff changeset
344 if (debug) {
083a0b5e12cc Apply Debug Interface version start
fuchita
parents:
diff changeset
345 System.out.print("mode = ");
083a0b5e12cc Apply Debug Interface version start
fuchita
parents:
diff changeset
346 System.out.println(mode);
083a0b5e12cc Apply Debug Interface version start
fuchita
parents:
diff changeset
347 System.out.print("seq = ");
083a0b5e12cc Apply Debug Interface version start
fuchita
parents:
diff changeset
348 System.out.println(rseq);
2
b49e593b2502 Add ComDebug_Client
fuchita
parents: 0
diff changeset
349 }***/
11
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
350 try {
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
351 PSXReply r = seqHash.get((a = new Integer(rseq)));
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
352 seqHash.put(a, null);
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
353 if (debug) {
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
354 System.out.print("hash value = ");
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
355 System.out.println(a.hashCode());
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
356 }
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
357
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
358 r.setAnswer(mode,command,data);
0
083a0b5e12cc Apply Debug Interface version start
fuchita
parents:
diff changeset
359
11
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
360 if (r.callback != null ) {
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
361 r.callback.callback(data);
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
362 }
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
363 } catch (NullPointerException e ) {
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
364 if (debug) {
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
365 System.out.println("hashed reply not found");
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
366 }
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
367 // can't happen
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
368 return ;
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
369 }
0
083a0b5e12cc Apply Debug Interface version start
fuchita
parents:
diff changeset
370 }
11
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
371 }
0
083a0b5e12cc Apply Debug Interface version start
fuchita
parents:
diff changeset
372 }
083a0b5e12cc Apply Debug Interface version start
fuchita
parents:
diff changeset
373
083a0b5e12cc Apply Debug Interface version start
fuchita
parents:
diff changeset
374 /* end */