diff --git a/Mage.Common/src/mage/interfaces/callback/CallbackClientDaemon.java b/Mage.Common/src/mage/interfaces/callback/CallbackClientDaemon.java index 25b2ca56622..8e427f466e3 100644 --- a/Mage.Common/src/mage/interfaces/callback/CallbackClientDaemon.java +++ b/Mage.Common/src/mage/interfaces/callback/CallbackClientDaemon.java @@ -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); } diff --git a/Mage.Common/src/mage/remote/RemoteMethodCallQueue.java b/Mage.Common/src/mage/remote/RemoteMethodCallQueue.java index 54a316dc1bd..ef55d90e75e 100644 --- a/Mage.Common/src/mage/remote/RemoteMethodCallQueue.java +++ b/Mage.Common/src/mage/remote/RemoteMethodCallQueue.java @@ -40,7 +40,7 @@ public class RemoteMethodCallQueue extends LinkedBlockingQueue 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 } } + public void clearCalls() { + RemoteMethodCall call = null; + while (true) { + call = poll(); + if (call == null) + return; + synchronized (call) { + call.notify(); + } + } + } + } diff --git a/Mage.Common/src/mage/remote/Session.java b/Mage.Common/src/mage/remote/Session.java index 5199b38642e..0dbaea52493 100644 --- a/Mage.Common/src/mage/remote/Session.java +++ b/Mage.Common/src/mage/remote/Session.java @@ -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);