You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by ta...@apache.org on 2009/06/17 16:53:19 UTC

svn commit: r785638 - in /activemq/activemq-cpp/trunk/activemq-cpp/src/main: activemq/transport/failover/FailoverTransport.cpp decaf/net/TcpSocket.cpp

Author: tabish
Date: Wed Jun 17 14:53:19 2009
New Revision: 785638

URL: http://svn.apache.org/viewvc?rev=785638&view=rev
Log:
Fix for: https://issues.apache.org/activemq/browse/AMQCPP-248

Modified:
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/transport/failover/FailoverTransport.cpp
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/TcpSocket.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=785638&r1=785637&r2=785638&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 Wed Jun 17 14:53:19 2009
@@ -430,6 +430,8 @@
 
     if( transport != NULL ) {
 
+        //std::cout << "Failover: Connection to has been unexpectedly terminated." << std::endl;
+
         if( this->disposedListener != NULL ) {
             transport->setTransportListener( disposedListener.get() );
         }
@@ -509,7 +511,21 @@
                         }
 
                     } catch( Exception& e ) {
-                        transport.reset( NULL );
+
+                        if( transport != NULL ) {
+                            if( this->disposedListener != NULL ) {
+                                transport->setTransportListener( disposedListener.get() );
+                            }
+
+                            // Hand off to the close task so it gets done in a different thread
+                            // this prevents a deadlock from occurring if the Transport happens
+                            // to call back through our onException method or locks in some other
+                            // way.
+                            closeTask->add( transport );
+                            taskRunner->wakeup();
+                            transport.reset( NULL );
+                        }
+
                         this->uris->addURI( uri );
                     }
                 }
@@ -525,6 +541,9 @@
 
                 try {
 
+                    //std::cout << "Failover: Attempting to connect to: "
+                    //          << uri.toString() << std::endl;
+
                     transport = createTransport( uri );
                     transport->setTransportListener( myTransportListener.get() );
                     transport->start();
@@ -535,7 +554,23 @@
 
                 } catch( Exception& e ) {
                     e.setMark( __FILE__, __LINE__ );
-                    transport.reset( NULL );
+                    //std::cout << "Failover: Failed while attempting to connect to: "
+                    //          << uri.toString() << std::endl;
+
+                    if( transport != NULL ) {
+                        if( this->disposedListener != NULL ) {
+                            transport->setTransportListener( disposedListener.get() );
+                        }
+
+                        // Hand off to the close task so it gets done in a different thread
+                        // this prevents a deadlock from occurring if the Transport happens
+                        // to call back through our onException method or locks in some other
+                        // way.
+                        closeTask->add( transport );
+                        taskRunner->wakeup();
+                        transport.reset( NULL );
+                    }
+
                     failures.add( uri );
                     failure.reset( e.clone() );
                 }
@@ -565,6 +600,9 @@
                     transportListener->transportResumed();
                 }
 
+                //std::cout << "Failover: Successfully connected to Broker at: "
+                //          << connectedTransportURI->toString() << std::endl;
+
                 return false;
             }
         }
@@ -603,6 +641,8 @@
     if( !closed ) {
 
         synchronized( &sleepMutex ) {
+            //std::cout << "Failover: Trying again in "
+            //          << reconnectDelay << "Milliseconds." << std::endl;
             sleepMutex.wait( (unsigned int)reconnectDelay );
         }
 

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/TcpSocket.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/TcpSocket.cpp?rev=785638&r1=785637&r2=785638&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/TcpSocket.cpp (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/TcpSocket.cpp Wed Jun 17 14:53:19 2009
@@ -99,12 +99,13 @@
 
         // Create the actual socket.
         checkResult( apr_socket_create(
-            &socketHandle, socketAddress->family, SOCK_STREAM, APR_PROTO_TCP, apr_pool.getAprPool() ) );
+            &socketHandle, socketAddress->family, SOCK_STREAM,
+            APR_PROTO_TCP, apr_pool.getAprPool() ) );
 
         // To make blocking-with-timeout sockets, we have to set it to
         // 'APR_SO_NONBLOCK==1(on) and timeout>0'. On Unix, we have no
         // problem to specify 'APR_SO_NONBLOCK==0(off) and timeout>0'.
-        // Unfortunatelly, we have a problem on Windows. Setting the
+        // Unfortunately, we have a problem on Windows. Setting the
         // mode to 'APR_SO_NONBLOCK==0(off) and timeout>0' causes
         // blocking-with-system-timeout sockets on Windows.
         //
@@ -116,7 +117,7 @@
         apr_socket_opt_set( socketHandle, APR_SO_NONBLOCK, (timeout>0)?1:0 );
         apr_socket_timeout_set( socketHandle, timeout );
 
-        // Connect to the broker.
+        // try to Connect to the provided address.
         checkResult(apr_socket_connect( socketHandle, socketAddress ));
 
         // Now that we are connected, we want to go back to blocking.