Author: aidan
Date: Mon Apr 21 10:03:43 2008
New Revision: 650205

URL: http://svn.apache.org/viewvc?rev=650205&view=rev
Log:
QPID-832 handle multiple brokers properly

Modified:
    
incubator/qpid/branches/thegreatmerge/qpid/java/client/src/main/java/org/apache/qpid/client/AMQConnection.java

Modified: 
incubator/qpid/branches/thegreatmerge/qpid/java/client/src/main/java/org/apache/qpid/client/AMQConnection.java
URL: 
http://svn.apache.org/viewvc/incubator/qpid/branches/thegreatmerge/qpid/java/client/src/main/java/org/apache/qpid/client/AMQConnection.java?rev=650205&r1=650204&r2=650205&view=diff
==============================================================================
--- 
incubator/qpid/branches/thegreatmerge/qpid/java/client/src/main/java/org/apache/qpid/client/AMQConnection.java
 (original)
+++ 
incubator/qpid/branches/thegreatmerge/qpid/java/client/src/main/java/org/apache/qpid/client/AMQConnection.java
 Mon Apr 21 10:03:43 2008
@@ -369,7 +369,8 @@
         }
 
         _failoverPolicy = new FailoverPolicy(connectionURL);
-        if 
(_failoverPolicy.getNextBrokerDetails().getTransport().equals(BrokerDetails.VM))
+        BrokerDetails brokerDetails = _failoverPolicy.getNextBrokerDetails();
+        if (brokerDetails.getTransport().equals(BrokerDetails.VM))
         {
             _delegate = new AMQConnectionDelegate_0_8(this);
         }
@@ -450,11 +451,15 @@
         Exception lastException = new Exception();
         lastException.initCause(new ConnectException());
 
-        while (!_connected && _failoverPolicy.failoverAllowed())
+        // TMG FIXME this seems... wrong...
+        boolean retryAllowed = true;
+        while (!_connected && retryAllowed )
         {
             try
             {
-                makeBrokerConnection(_failoverPolicy.getNextBrokerDetails());
+                makeBrokerConnection(brokerDetails);
+                lastException = null;
+                _connected = true;
             }
             catch (AMQProtocolException pe)
             {
@@ -472,16 +477,13 @@
             {
                 lastException = e;
 
-                //We need to change protocol handler here as an error during 
the connect will not
-                // cause the StateManager to be replaced. So the state is out 
of sync on reconnect
-                // This can be seen when a exception occurs during connection. 
i.e. log4j NoSuchMethod. (using < 1.2.12)
-                _protocolHandler.setStateManager(new AMQStateManager());
-
                 if (_logger.isInfoEnabled())
                 {
                     _logger.info("Unable to connect to broker at " + 
_failoverPolicy.getCurrentBrokerDetails(),
-                                 e.getCause());
+                            e.getCause());
                 }
+                retryAllowed = _failoverPolicy.failoverAllowed();
+                brokerDetails = _failoverPolicy.getNextBrokerDetails();
             }
         }
 


Reply via email to