fixed an issue with client freezing

This commit is contained in:
BetaSteward 2011-06-05 09:08:45 -04:00
parent 1ed3f1f4f8
commit 6048ee6538
3 changed files with 18 additions and 8 deletions

View file

@ -31,11 +31,9 @@ package mage.interfaces.callback;
import java.util.UUID;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import mage.remote.Connection;
import mage.MageException;
import mage.remote.ServerUnavailable;
import mage.remote.Session;
import mage.remote.method.Ack;
import mage.remote.method.Callback;
import org.apache.log4j.Logger;
/**
@ -88,8 +86,8 @@ public class CallbackClientDaemon extends Thread {
}
}
} catch (ServerUnavailable ex) {
session.disconnect(true);
} catch(Exception ex) {
session.handleServerUnavailable(ex);
} catch(MageException ex) {
logger.fatal("CallbackClientDaemon error ", ex);
session.disconnect(true);
}

View file

@ -40,7 +40,7 @@ public class RemoteMethodCallQueue extends LinkedBlockingQueue<RemoteMethodCall>
public void callMethod(RemoteMethodCall call) throws ServerUnavailable, MageException {
synchronized (call) {
try {
this.put(call);
this.offer(call);
call.wait();
if (call.isException()) {
if (call.getException() != null)
@ -54,4 +54,16 @@ public class RemoteMethodCallQueue extends LinkedBlockingQueue<RemoteMethodCall>
}
}
public void clearCalls() {
RemoteMethodCall call = null;
while (true) {
call = poll();
if (call == null)
return;
synchronized (call) {
call.notify();
}
}
}
}

View file

@ -159,7 +159,7 @@ public class Session {
}
private void cleanupSession() {
q.clear();
q.clearCalls();
if (future != null && !future.isDone())
future.cancel(true);
if (callbackDaemon != null)
@ -497,7 +497,7 @@ public class Session {
return handleCall(method);
}
private void handleServerUnavailable(ServerUnavailable ex) {
public void handleServerUnavailable(ServerUnavailable ex) {
sessionState = SessionState.SERVER_UNAVAILABLE;
logger.fatal("server unavailable - ", ex);
disconnect(true);