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.UUID;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
import mage.remote.Connection; import mage.MageException;
import mage.remote.ServerUnavailable; import mage.remote.ServerUnavailable;
import mage.remote.Session; import mage.remote.Session;
import mage.remote.method.Ack;
import mage.remote.method.Callback;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
/** /**
@ -88,8 +86,8 @@ public class CallbackClientDaemon extends Thread {
} }
} }
} catch (ServerUnavailable ex) { } catch (ServerUnavailable ex) {
session.disconnect(true); session.handleServerUnavailable(ex);
} catch(Exception ex) { } catch(MageException ex) {
logger.fatal("CallbackClientDaemon error ", ex); logger.fatal("CallbackClientDaemon error ", ex);
session.disconnect(true); session.disconnect(true);
} }

View file

@ -40,7 +40,7 @@ public class RemoteMethodCallQueue extends LinkedBlockingQueue<RemoteMethodCall>
public void callMethod(RemoteMethodCall call) throws ServerUnavailable, MageException { public void callMethod(RemoteMethodCall call) throws ServerUnavailable, MageException {
synchronized (call) { synchronized (call) {
try { try {
this.put(call); this.offer(call);
call.wait(); call.wait();
if (call.isException()) { if (call.isException()) {
if (call.getException() != null) 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() { private void cleanupSession() {
q.clear(); q.clearCalls();
if (future != null && !future.isDone()) if (future != null && !future.isDone())
future.cancel(true); future.cancel(true);
if (callbackDaemon != null) if (callbackDaemon != null)
@ -497,7 +497,7 @@ public class Session {
return handleCall(method); return handleCall(method);
} }
private void handleServerUnavailable(ServerUnavailable ex) { public void handleServerUnavailable(ServerUnavailable ex) {
sessionState = SessionState.SERVER_UNAVAILABLE; sessionState = SessionState.SERVER_UNAVAILABLE;
logger.fatal("server unavailable - ", ex); logger.fatal("server unavailable - ", ex);
disconnect(true); disconnect(true);