From 3a28fb01257c97208de6858245e616256c7c06f5 Mon Sep 17 00:00:00 2001 From: Martin Ritchie Date: Mon, 19 Oct 2009 11:10:33 +0000 Subject: QPID-1816 : When client fails over due to an error, that error is still held bt the StateManager and will prvent the connection from working. During failover check and see if the Connection had been marked closed if so remove any set exception. git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@826638 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/qpid/client/failover/FailoverHandler.java | 17 +++++++++++++++++ .../org/apache/qpid/client/state/AMQStateManager.java | 5 +++++ 2 files changed, 22 insertions(+) (limited to 'qpid/java') diff --git a/qpid/java/client/src/main/java/org/apache/qpid/client/failover/FailoverHandler.java b/qpid/java/client/src/main/java/org/apache/qpid/client/failover/FailoverHandler.java index f312f3c0ec..190776891e 100644 --- a/qpid/java/client/src/main/java/org/apache/qpid/client/failover/FailoverHandler.java +++ b/qpid/java/client/src/main/java/org/apache/qpid/client/failover/FailoverHandler.java @@ -24,6 +24,7 @@ import org.apache.qpid.AMQDisconnectedException; import org.apache.qpid.AMQException; import org.apache.qpid.client.protocol.AMQProtocolHandler; import org.apache.qpid.client.state.AMQStateManager; +import org.apache.qpid.client.state.AMQState; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -192,6 +193,22 @@ public class FailoverHandler implements Runnable // Set the new Protocol Session in the StateManager. existingStateManager.setProtocolSession(_amqProtocolHandler.getProtocolSession()); + // Now that the ProtocolHandler has been reconnected clean up + // the state of the old state manager. As if we simply reinstate + // it any old exception that had occured prior to failover may + // prohibit reconnection. + // e.g. During testing when the broker is shutdown gracefully. + // The broker + // Clear any exceptions we gathered + if (existingStateManager.getCurrentState() != AMQState.CONNECTION_OPEN) + { + // Clear the state of the previous state manager as it may + // have received an exception + existingStateManager.clearLastException(); + existingStateManager.changeState(AMQState.CONNECTION_OPEN); + } + + //Restore Existing State Manager _amqProtocolHandler.setStateManager(existingStateManager); try diff --git a/qpid/java/client/src/main/java/org/apache/qpid/client/state/AMQStateManager.java b/qpid/java/client/src/main/java/org/apache/qpid/client/state/AMQStateManager.java index 70d4697f2c..9c7d62670c 100644 --- a/qpid/java/client/src/main/java/org/apache/qpid/client/state/AMQStateManager.java +++ b/qpid/java/client/src/main/java/org/apache/qpid/client/state/AMQStateManager.java @@ -213,4 +213,9 @@ public class AMQStateManager implements AMQMethodListener { return _lastException; } + + public void clearLastException() + { + _lastException = null; + } } -- cgit v1.2.1