activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject svn commit: r990948 - /activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/transport/failover/FailoverTransport.cpp
Date Mon, 30 Aug 2010 21:25:09 GMT
Author: tabish
Date: Mon Aug 30 21:25:09 2010
New Revision: 990948

URL: http://svn.apache.org/viewvc?rev=990948&view=rev
Log:
Ensure that a URI that's not in the list of URIs to remove from the URI list isn't lost if
its the active connection when removeURI is called.

Modified:
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/transport/failover/FailoverTransport.cpp

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/transport/failover/FailoverTransport.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/transport/failover/FailoverTransport.cpp?rev=990948&r1=990947&r2=990948&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/transport/failover/FailoverTransport.cpp
(original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/transport/failover/FailoverTransport.cpp
Mon Aug 30 21:25:09 2010
@@ -130,11 +130,18 @@ void FailoverTransport::removeURI( bool 
 
     std::auto_ptr< Iterator<URI> > iter( uris.iterator() );
 
-    while( iter->hasNext() ) {
-        this->uris->removeURI( iter->next() );
-    }
+    synchronized( &reconnectMutex ) {
+
+        // We need to lock so that the reconnect doesn't get kicked off until
+        // we have a chance to remove the URIs in case one of them was the one
+        // we had a connection to and it gets reinserted into the URI pool.
+
+        reconnect( rebalance );
 
-    reconnect( rebalance );
+        while( iter->hasNext() ) {
+            this->uris->removeURI( iter->next() );
+        }
+    }
 }
 
 ////////////////////////////////////////////////////////////////////////////////
@@ -419,6 +426,11 @@ void FailoverTransport::reconnect( bool 
 
                     // Hand off to the close task so it gets done in a different thread.
                     closeTask->add( transport );
+
+                    if( this->connectedTransportURI != NULL ) {
+                        this->uris->addURI( *this->connectedTransportURI );
+                        this->connectedTransportURI.reset( NULL );
+                    }
                 }
             }
 
@@ -505,7 +517,7 @@ void FailoverTransport::handleConnection
         std::string reconnectStr = ctrlCommand->getReconnectTo();
         if( !reconnectStr.empty() ) {
 
-            std::remove(reconnectStr.begin(), reconnectStr.end(), ' ');
+            std::remove( reconnectStr.begin(), reconnectStr.end(), ' ' );
 
             if( reconnectStr.length() > 0 ) {
                 try {
@@ -677,7 +689,7 @@ bool FailoverTransport::iterate() {
                 try{
                     uri = uris->getURI();
                 } catch( NoSuchElementException& ex ) {
-                    break;
+                    throw IOException( __FILE__, __LINE__, "No URIs to reconnect to." );
                 }
 
                 try {



Mime
View raw message