annotate src/fdl/FederatedLinda.java @ 17:609b288f47f9

*** empty log message ***
author kono
date Mon, 18 Aug 2008 07:28:29 +0900
parents aced4bfc15af
children 0243987383b7
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
17
609b288f47f9 *** empty log message ***
kono
parents: 15
diff changeset
40 public class FederatedLinda {
0
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
17
609b288f47f9 *** empty log message ***
kono
parents: 15
diff changeset
98 if (mode != PSX.PSX_OUT) {
609b288f47f9 *** empty log message ***
kono
parents: 15
diff changeset
99 PSXReply p = new PSXReply(PSX.PSX_REPLY,callback);
11
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;
17
609b288f47f9 *** empty log message ***
kono
parents: 15
diff changeset
211 ByteBuffer command = ByteBuffer.allocate(PSX.LINDA_HEADER_SIZE);
11
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();
17
609b288f47f9 *** empty log message ***
kono
parents: 15
diff changeset
217 length = command.getInt(PSX.LINDA_DATA_LENGTH_OFFSET);
11
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) {
17
609b288f47f9 *** empty log message ***
kono
parents: 15
diff changeset
233 PSX.printCommand(command, data);
11
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
234 }
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
235 //if (debug_com) {
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
236 String comdata ="";
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
237 CharBuffer chardata = data.asCharBuffer();
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
238 comdata = chardata.toString();
2
b49e593b2502 Add ComDebug_Client
fuchita
parents: 0
diff changeset
239
11
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
240 //System.out.println("Com_data =>");
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
241 System.out.println(comdata);
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
242 //}
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
243 /***if (debug) {
2
b49e593b2502 Add ComDebug_Client
fuchita
parents: 0
diff changeset
244 System.out.print("header:");
b49e593b2502 Add ComDebug_Client
fuchita
parents: 0
diff changeset
245 for(int i=0;i<LINDA_HEADER_SIZE;i++) {
b49e593b2502 Add ComDebug_Client
fuchita
parents: 0
diff changeset
246 System.out.println(command.get(i));
b49e593b2502 Add ComDebug_Client
fuchita
parents: 0
diff changeset
247 }
b49e593b2502 Add ComDebug_Client
fuchita
parents: 0
diff changeset
248 System.out.print("data:");
b49e593b2502 Add ComDebug_Client
fuchita
parents: 0
diff changeset
249 for(int i=0;i<length;i++) {
b49e593b2502 Add ComDebug_Client
fuchita
parents: 0
diff changeset
250 System.out.println(data.get(i));
b49e593b2502 Add ComDebug_Client
fuchita
parents: 0
diff changeset
251 }
b49e593b2502 Add ComDebug_Client
fuchita
parents: 0
diff changeset
252 data.rewind();
b49e593b2502 Add ComDebug_Client
fuchita
parents: 0
diff changeset
253 }***/
11
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
254
17
609b288f47f9 *** empty log message ***
kono
parents: 15
diff changeset
255 int rseq = command.getInt(PSX.LINDA_SEQ_OFFSET);
609b288f47f9 *** empty log message ***
kono
parents: 15
diff changeset
256 int mode = command.get(PSX.LINDA_MODE_OFFSET);
11
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
257 Integer a;
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
258 /***
2
b49e593b2502 Add ComDebug_Client
fuchita
parents: 0
diff changeset
259 if (debug) {
b49e593b2502 Add ComDebug_Client
fuchita
parents: 0
diff changeset
260 System.out.print("mode = ");
b49e593b2502 Add ComDebug_Client
fuchita
parents: 0
diff changeset
261 System.out.println(mode);
b49e593b2502 Add ComDebug_Client
fuchita
parents: 0
diff changeset
262 System.out.print("seq = ");
b49e593b2502 Add ComDebug_Client
fuchita
parents: 0
diff changeset
263 System.out.println(rseq);
b49e593b2502 Add ComDebug_Client
fuchita
parents: 0
diff changeset
264 }***/
11
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
265 try {
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
266 PSXReply r = seqHash.get((a = new Integer(rseq)));
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
267 seqHash.put(a, null);
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
268 if (debug) {
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
269 System.out.print("hash value = ");
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
270 System.out.println(a.hashCode());
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
271 }
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
272
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
273 r.setAnswer(mode,command,data);
2
b49e593b2502 Add ComDebug_Client
fuchita
parents: 0
diff changeset
274
11
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
275 if (r.callback != null ) {
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
276 r.callback.callback(data);
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
277 }
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
278 } catch (NullPointerException e ) {
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
279 if (debug) {
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
280 System.out.println("hashed reply not found");
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
281 }
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
282 // can't happen
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
283 return ;
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
284 }
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
285 }
2
b49e593b2502 Add ComDebug_Client
fuchita
parents: 0
diff changeset
286 }
b49e593b2502 Add ComDebug_Client
fuchita
parents: 0
diff changeset
287
b49e593b2502 Add ComDebug_Client
fuchita
parents: 0
diff changeset
288 private void chkServe(SocketChannel sock)
11
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
289 throws IOException {
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
290 int length;
17
609b288f47f9 *** empty log message ***
kono
parents: 15
diff changeset
291 ByteBuffer command = ByteBuffer.allocate(PSX.LINDA_HEADER_SIZE);
11
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
292 command.order(ByteOrder.BIG_ENDIAN);
0
083a0b5e12cc Apply Debug Interface version start
fuchita
parents:
diff changeset
293
11
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
294 sock.read(command);
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
295 command.rewind();
17
609b288f47f9 *** empty log message ***
kono
parents: 15
diff changeset
296 length = command.getInt(PSX.LINDA_DATA_LENGTH_OFFSET);
11
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
297 if (length>0) {
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
298 ByteBuffer data = ByteBuffer.allocate(length);
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
299 int read = length;
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
300 if (debug) {
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
301 System.out.print("reading:");
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
302 System.out.println(length);
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
303 }
0
083a0b5e12cc Apply Debug Interface version start
fuchita
parents:
diff changeset
304
11
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
305 data.order(ByteOrder.BIG_ENDIAN);
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
306 while(read>0) {
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
307 read -= sock.read(data);
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
308 }
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
309 data.rewind();
2
b49e593b2502 Add ComDebug_Client
fuchita
parents: 0
diff changeset
310
11
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
311 if (debug) {
17
609b288f47f9 *** empty log message ***
kono
parents: 15
diff changeset
312 PSX.printCommand(command, data);
11
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
313 }
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
314 /***if (debug) {
0
083a0b5e12cc Apply Debug Interface version start
fuchita
parents:
diff changeset
315 System.out.print("header:");
083a0b5e12cc Apply Debug Interface version start
fuchita
parents:
diff changeset
316 for(int i=0;i<LINDA_HEADER_SIZE;i++) {
083a0b5e12cc Apply Debug Interface version start
fuchita
parents:
diff changeset
317 System.out.println(command.get(i));
083a0b5e12cc Apply Debug Interface version start
fuchita
parents:
diff changeset
318 }
083a0b5e12cc Apply Debug Interface version start
fuchita
parents:
diff changeset
319 System.out.print("data:");
083a0b5e12cc Apply Debug Interface version start
fuchita
parents:
diff changeset
320 for(int i=0;i<length;i++) {
083a0b5e12cc Apply Debug Interface version start
fuchita
parents:
diff changeset
321 System.out.println(data.get(i));
083a0b5e12cc Apply Debug Interface version start
fuchita
parents:
diff changeset
322 }
083a0b5e12cc Apply Debug Interface version start
fuchita
parents:
diff changeset
323 data.rewind();
2
b49e593b2502 Add ComDebug_Client
fuchita
parents: 0
diff changeset
324 }***/
11
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
325
17
609b288f47f9 *** empty log message ***
kono
parents: 15
diff changeset
326 int rseq = command.getInt(PSX.LINDA_SEQ_OFFSET);
609b288f47f9 *** empty log message ***
kono
parents: 15
diff changeset
327 int mode = command.get(PSX.LINDA_MODE_OFFSET);
11
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
328 Integer a;
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
329 /***
0
083a0b5e12cc Apply Debug Interface version start
fuchita
parents:
diff changeset
330 if (debug) {
083a0b5e12cc Apply Debug Interface version start
fuchita
parents:
diff changeset
331 System.out.print("mode = ");
083a0b5e12cc Apply Debug Interface version start
fuchita
parents:
diff changeset
332 System.out.println(mode);
083a0b5e12cc Apply Debug Interface version start
fuchita
parents:
diff changeset
333 System.out.print("seq = ");
083a0b5e12cc Apply Debug Interface version start
fuchita
parents:
diff changeset
334 System.out.println(rseq);
2
b49e593b2502 Add ComDebug_Client
fuchita
parents: 0
diff changeset
335 }***/
11
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
336 try {
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
337 PSXReply r = seqHash.get((a = new Integer(rseq)));
15
aced4bfc15af add Meta Linda Interface for debugger.
kono
parents: 11
diff changeset
338 seqHash.put(a, null); // should be clear or delete
11
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
339 if (debug) {
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
340 System.out.print("hash value = ");
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
341 System.out.println(a.hashCode());
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
342 }
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
343
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
344 r.setAnswer(mode,command,data);
0
083a0b5e12cc Apply Debug Interface version start
fuchita
parents:
diff changeset
345
11
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
346 if (r.callback != null ) {
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
347 r.callback.callback(data);
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
348 }
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
349 } catch (NullPointerException e ) {
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
350 if (debug) {
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
351 System.out.println("hashed reply not found");
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
352 }
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
353 // can't happen
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
354 return ;
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
355 }
0
083a0b5e12cc Apply Debug Interface version start
fuchita
parents:
diff changeset
356 }
11
1355eb28e41d fix seqHash removal on checkServe.
kono
parents: 2
diff changeset
357 }
0
083a0b5e12cc Apply Debug Interface version start
fuchita
parents:
diff changeset
358 }
083a0b5e12cc Apply Debug Interface version start
fuchita
parents:
diff changeset
359
083a0b5e12cc Apply Debug Interface version start
fuchita
parents:
diff changeset
360 /* end */