public Object sendRequest(Object request) throws Exception {
if (PHPDebugPlugin.DEBUG) {
System.out.println("Sending syncrhonic request: " + request); //$NON-NLS-1$
}
try {
IDebugRequestMessage theMsg = (IDebugRequestMessage) request;
synchronized (byteArrayOutputStream) {
byteArrayOutputStream.reset();
theMsg.setID(lastRequestID++);
theMsg.serialize(dataOutputStream);
int messageSize = byteArrayOutputStream.size();
synchronized (connectionOut) {
requestsTable.put(theMsg.getID(), theMsg);
connectionOut.writeInt(messageSize);
byteArrayOutputStream.writeTo(connectionOut);
connectionOut.flush();
}
}
IDebugResponseMessage response = null;
int timeoutTick = 500; // 0.5 of second
int waitedTime = 0;
while (response == null && isConnected()) {
synchronized (request) {
response = (IDebugResponseMessage) responseTable
.remove(theMsg.getID());
if (response == null) {
if (PHPDebugPlugin.DEBUG) {
System.out
.println("Response is null. Waiting " + waitedTime + " milliseconds"); //$NON-NLS-1$ //$NON-NLS-2$
}
if (waitedTime > debugResponseTimeout / 4) { // Display
// a
// progress
// dialog
// after
// a
// quarter
// of
// the
// assigned
// time
// have
// passed.
// Display a message that we are waiting for the
// server response.
// In case that the response finally arrives, remove
// the message.
// In case we have a timeout, close the connection
// and display a different message.
PHPLaunchUtilities.showWaitForDebuggerMessage(this);
}
request.wait(timeoutTick);
}
}
if (response == null) {
response = (IDebugResponseMessage) responseTable
.remove(theMsg.getID());
}
// if the response is null. it means that there is no answer
// from the server.
// This can be because on the peerResponseTimeout.