Lines 14-19
Link Here
|
14 |
import java.io.InterruptedIOException; |
14 |
import java.io.InterruptedIOException; |
15 |
import java.text.MessageFormat; |
15 |
import java.text.MessageFormat; |
16 |
import java.util.ArrayList; |
16 |
import java.util.ArrayList; |
|
|
17 |
import java.util.Iterator; |
17 |
import java.util.LinkedList; |
18 |
import java.util.LinkedList; |
18 |
import java.util.ListIterator; |
19 |
import java.util.ListIterator; |
19 |
|
20 |
|
Lines 50-55
Link Here
|
50 |
private ArrayList fTimedOutPackets; |
51 |
private ArrayList fTimedOutPackets; |
51 |
|
52 |
|
52 |
private VirtualMachineImpl fVM; |
53 |
private VirtualMachineImpl fVM; |
|
|
54 |
|
55 |
private int fRequestCount = 0; |
56 |
private long fTotalTime = 0L; |
57 |
private LinkedList fRequestsProcessed = new LinkedList(); |
53 |
|
58 |
|
54 |
/** |
59 |
/** |
55 |
* Create a new thread that receives packets from the Virtual Machine. |
60 |
* Create a new thread that receives packets from the Virtual Machine. |
Lines 133-140
Link Here
|
133 |
/** |
138 |
/** |
134 |
* @return Returns a specified Reply Packet from the Virtual Machine. |
139 |
* @return Returns a specified Reply Packet from the Virtual Machine. |
135 |
*/ |
140 |
*/ |
136 |
public JdwpReplyPacket getReply(int id, long timeToWait) { |
141 |
public JdwpReplyPacket getReply(JdwpCommandPacket request, long timeToWait) { |
137 |
JdwpReplyPacket packet = null; |
142 |
JdwpReplyPacket packet = null; |
|
|
143 |
int id = request.getId(); |
138 |
|
144 |
|
139 |
long remainingTime = timeToWait; |
145 |
long remainingTime = timeToWait; |
140 |
synchronized (fReplyPackets) { |
146 |
synchronized (fReplyPackets) { |
Lines 159-164
Link Here
|
159 |
if (packet == null) { |
165 |
if (packet == null) { |
160 |
synchronized (fReplyPackets) { |
166 |
synchronized (fReplyPackets) { |
161 |
packet = removeReplyPacket(id); |
167 |
packet = removeReplyPacket(id); |
|
|
168 |
if (packet == null) { |
169 |
handleTimeout(request); |
170 |
} |
162 |
} |
171 |
} |
163 |
} |
172 |
} |
164 |
|
173 |
|
Lines 169-179
Link Here
|
169 |
// Check for a timeout. |
178 |
// Check for a timeout. |
170 |
if (packet == null) { |
179 |
if (packet == null) { |
171 |
synchronized (fTimedOutPackets) { |
180 |
synchronized (fTimedOutPackets) { |
172 |
fTimedOutPackets.add(new Integer(id)); |
181 |
fTimedOutPackets.add(request); |
173 |
} |
182 |
} |
174 |
throw new TimeoutException(MessageFormat.format(ConnectMessages.PacketReceiveManager_0, new String[] {id+""})); //$NON-NLS-1$ |
183 |
throw new TimeoutException(MessageFormat.format(ConnectMessages.PacketReceiveManager_0, new String[] {id+""})); //$NON-NLS-1$ |
|
|
184 |
|
175 |
} |
185 |
} |
176 |
|
186 |
|
|
|
187 |
request.setReply(packet); |
188 |
fRequestCount++; |
189 |
fTotalTime += packet.getTimestamp() - request.getTimestamp(); |
177 |
return packet; |
190 |
return packet; |
178 |
} |
191 |
} |
179 |
|
192 |
|
Lines 181-187
Link Here
|
181 |
* @return Returns a specified Reply Packet from the Virtual Machine. |
194 |
* @return Returns a specified Reply Packet from the Virtual Machine. |
182 |
*/ |
195 |
*/ |
183 |
public JdwpReplyPacket getReply(JdwpCommandPacket commandPacket) { |
196 |
public JdwpReplyPacket getReply(JdwpCommandPacket commandPacket) { |
184 |
return getReply(commandPacket.getId(), fVM.getRequestTimeout()); |
197 |
synchronized (fRequestsProcessed) { |
|
|
198 |
fRequestsProcessed.add(commandPacket); |
199 |
} |
200 |
return getReply(commandPacket, fVM.getRequestTimeout()); |
185 |
} |
201 |
} |
186 |
|
202 |
|
187 |
/** |
203 |
/** |
Lines 231-239
Link Here
|
231 |
* Add a command packet to the command packet list. |
247 |
* Add a command packet to the command packet list. |
232 |
*/ |
248 |
*/ |
233 |
private void addCommandPacket(JdwpCommandPacket packet) { |
249 |
private void addCommandPacket(JdwpCommandPacket packet) { |
234 |
if (isTimedOut(packet)) { |
|
|
235 |
return; // already timed out. No need to keep this one |
236 |
} |
237 |
synchronized (fCommandPackets) { |
250 |
synchronized (fCommandPackets) { |
238 |
fCommandPackets.add(packet); |
251 |
fCommandPackets.add(packet); |
239 |
fCommandPackets.notifyAll(); |
252 |
fCommandPackets.notifyAll(); |
Lines 246-259
Link Here
|
246 |
* @param packet response packet |
259 |
* @param packet response packet |
247 |
* @return whether the request for the given packet has already timed out |
260 |
* @return whether the request for the given packet has already timed out |
248 |
*/ |
261 |
*/ |
249 |
private boolean isTimedOut(JdwpPacket packet) { |
262 |
private boolean isTimedOut(JdwpReplyPacket packet) { |
250 |
synchronized (fTimedOutPackets) { |
263 |
synchronized (fTimedOutPackets) { |
251 |
if (fTimedOutPackets.isEmpty()) { |
264 |
if (fTimedOutPackets.isEmpty()) { |
252 |
return false; |
265 |
return false; |
253 |
} |
266 |
} |
254 |
Integer id = new Integer(packet.getId()); |
267 |
Iterator iterator = fTimedOutPackets.listIterator(); |
255 |
return fTimedOutPackets.remove(id); |
268 |
while (iterator.hasNext()) { |
256 |
} |
269 |
JdwpCommandPacket request = (JdwpCommandPacket) iterator.next(); |
|
|
270 |
if (request.getId() == packet.getId()) { |
271 |
iterator.remove(); |
272 |
request.setReply(packet); |
273 |
// |
274 |
timeoutResponseReceived(request); |
275 |
// |
276 |
return true; |
277 |
} |
278 |
} |
279 |
} |
280 |
return false; |
281 |
} |
282 |
|
283 |
/** |
284 |
* A request has timed out |
285 |
* |
286 |
* @param request |
287 |
*/ |
288 |
private void handleTimeout(JdwpCommandPacket request) { |
289 |
System.out.println("Timeout: " + request.toString()); |
290 |
int index = fRequestsProcessed.indexOf(request); |
291 |
for (int i = 0; i < 100; i++) { |
292 |
index--; |
293 |
if (i >= 0) { |
294 |
JdwpCommandPacket prevRequest = (JdwpCommandPacket) fRequestsProcessed.get(index); |
295 |
System.out.println("\t -" + (i + 1) + ": " + prevRequest.toString()); |
296 |
} |
297 |
} |
298 |
|
299 |
|
300 |
} |
301 |
|
302 |
/** |
303 |
* A request has timed out and a response was later received |
304 |
* @param request |
305 |
*/ |
306 |
private void timeoutResponseReceived(JdwpCommandPacket request) { |
307 |
|
257 |
} |
308 |
} |
258 |
|
309 |
|
259 |
/** |
310 |
/** |
Lines 277-282
Link Here
|
277 |
// Read a packet from the Input Stream. |
328 |
// Read a packet from the Input Stream. |
278 |
byte[] bytes = getConnection().readPacket(); |
329 |
byte[] bytes = getConnection().readPacket(); |
279 |
JdwpPacket packet = JdwpPacket.build(bytes); |
330 |
JdwpPacket packet = JdwpPacket.build(bytes); |
|
|
331 |
packet.timestamp(); |
280 |
// Add packet to command or reply queue. |
332 |
// Add packet to command or reply queue. |
281 |
if (packet instanceof JdwpCommandPacket) |
333 |
if (packet instanceof JdwpCommandPacket) |
282 |
addCommandPacket((JdwpCommandPacket) packet); |
334 |
addCommandPacket((JdwpCommandPacket) packet); |