Author: nmittler Date: Fri Dec 1 07:37:22 2006 New Revision: 481264 URL: http://svn.apache.org/viewvc?view=rev&rev=481264 Log: [AMQCPP-20] - Fixing deadlock in asynchronous close
Modified: incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/connector/stomp/StompConnector.cpp incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/connector/stomp/StompConnector.h incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/exceptions/ActiveMQException.cpp incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/transport/IOTransport.cpp incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/transport/IOTransport.h Modified: incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/connector/stomp/StompConnector.cpp URL: http://svn.apache.org/viewvc/incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/connector/stomp/StompConnector.cpp?view=diff&rev=481264&r1=481263&r2=481264 ============================================================================== --- incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/connector/stomp/StompConnector.cpp (original) +++ incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/connector/stomp/StompConnector.cpp Fri Dec 1 07:37:22 2006 @@ -81,7 +81,7 @@ } //////////////////////////////////////////////////////////////////////////////// -StompConnector::~StompConnector(void) +StompConnector::~StompConnector() { try { @@ -94,7 +94,7 @@ } //////////////////////////////////////////////////////////////////////////////// -unsigned int StompConnector::getNextProducerId(void) +unsigned int StompConnector::getNextProducerId() { synchronized( &mutex ) { @@ -105,7 +105,7 @@ } //////////////////////////////////////////////////////////////////////////////// -unsigned int StompConnector::getNextTransactionId(void) +unsigned int StompConnector::getNextTransactionId() { synchronized( &mutex ) { @@ -116,7 +116,7 @@ } //////////////////////////////////////////////////////////////////////////////// -void StompConnector::enforceConnected( void ) throw ( ConnectorException ) +void StompConnector::enforceConnected() throw ( ConnectorException ) { if( state != CONNECTED ) { @@ -142,7 +142,7 @@ } //////////////////////////////////////////////////////////////////////////////// -void StompConnector::start(void) throw( cms::CMSException ) +void StompConnector::start() throw( cms::CMSException ) { try { @@ -167,20 +167,22 @@ } //////////////////////////////////////////////////////////////////////////////// -void StompConnector::close(void) throw( cms::CMSException ){ +void StompConnector::close() throw( cms::CMSException ){ try { + if( state == DISCONNECTED ){ + return; + } + synchronized( &mutex ) - { - if( state == this->CONNECTED ) - { - // Send the disconnect message to the broker. - disconnect(); + { + // Send the disconnect message to the broker. + disconnect(); - // Close the transport. - transport->close(); - } + // Close the transport. + printf("StompConnector::close - about to close the transport\n"); + transport->close(); } } AMQ_CATCH_RETHROW( ActiveMQException ) @@ -188,12 +190,12 @@ } //////////////////////////////////////////////////////////////////////////////// -void StompConnector::connect(void) +void StompConnector::connect() { try { // Mark this connector as started. - state = this->CONNECTING; + state = CONNECTING; // Send the connect command to the broker ConnectCommand cmd; @@ -268,12 +270,12 @@ } //////////////////////////////////////////////////////////////////////////////// -void StompConnector::disconnect(void) +void StompConnector::disconnect() { try { // Mark state as no longer connected. - state = this->DISCONNECTED; + state = DISCONNECTED; // Send the disconnect command to the broker. DisconnectCommand cmd; @@ -771,8 +773,11 @@ // Inform the user. fire( ex ); + // NOT closing here ... let the user close it through the connection + // class! + // Close down. - close(); + //close(); } AMQ_CATCH_RETHROW( ConnectorException ) AMQ_CATCHALL_THROW( ConnectorException ); Modified: incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/connector/stomp/StompConnector.h URL: http://svn.apache.org/viewvc/incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/connector/stomp/StompConnector.h?view=diff&rev=481264&r1=481263&r2=481264 ============================================================================== --- incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/connector/stomp/StompConnector.h (original) +++ incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/connector/stomp/StompConnector.h Fri Dec 1 07:37:22 2006 @@ -129,12 +129,12 @@ * Sends the connect message to the broker and * waits for the response. */ - void connect(void); + void connect(); /** * Sends a oneway disconnect message to the broker. */ - void disconnect(void); + void disconnect(); /** * Fires a consumer message to the observer. @@ -175,26 +175,26 @@ const util::Properties& properties ) throw ( exceptions::IllegalArgumentException ); - virtual ~StompConnector(void); + virtual ~StompConnector(); /** * Starts the service. * @throws CMSException */ - virtual void start(void) throw( cms::CMSException ); + virtual void start() throw( cms::CMSException ); /** * Closes this object and deallocates the appropriate resources. * @throws CMSException */ - virtual void close(void) throw( cms::CMSException ); + virtual void close() throw( cms::CMSException ); /** * Gets the Client Id for this connection, if this * connection has been closed, then this method returns "" * @return Client Id String */ - virtual std::string getClientId(void) const { + virtual std::string getClientId() const { return properties.getProperty( core::ActiveMQConstants::toString( core::ActiveMQConstants::PARAM_CLIENTID ), "" ); @@ -205,7 +205,7 @@ * connection has been closed, then this method returns "" * @return Username String */ - virtual std::string getUsername(void) const { + virtual std::string getUsername() const { return properties.getProperty( core::ActiveMQConstants::toString( core::ActiveMQConstants::PARAM_USERNAME ), "" ); @@ -216,7 +216,7 @@ * connection has been closed, then this method returns "" * @return Password String */ - virtual std::string getPassword(void) const { + virtual std::string getPassword() const { return properties.getProperty( core::ActiveMQConstants::toString( core::ActiveMQConstants::PARAM_PASSWORD ), "" ); @@ -228,7 +228,7 @@ * @return reference to a transport * @throws InvalidStateException if the Transport is not set */ - virtual transport::Transport& getTransport(void) const + virtual transport::Transport& getTransport() const throw ( exceptions::InvalidStateException ) { if( transport == NULL ) { @@ -535,11 +535,11 @@ private: - unsigned int getNextProducerId(void); - unsigned int getNextTransactionId(void); + unsigned int getNextProducerId(); + unsigned int getNextTransactionId(); // Check for Connected State and Throw an exception if not. - void enforceConnected( void ) throw ( ConnectorException ); + void enforceConnected() throw ( ConnectorException ); }; Modified: incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/exceptions/ActiveMQException.cpp URL: http://svn.apache.org/viewvc/incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/exceptions/ActiveMQException.cpp?view=diff&rev=481264&r1=481263&r2=481264 ============================================================================== --- incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/exceptions/ActiveMQException.cpp (original) +++ incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/exceptions/ActiveMQException.cpp Fri Dec 1 07:37:22 2006 @@ -53,8 +53,8 @@ size *= 2; } - activemq::logger::SimpleLogger logger("com.yadda1"); - logger.log( message ); + //activemq::logger::SimpleLogger logger("com.yadda1"); + //logger.log( message ); } //////////////////////////////////////////////////////////////////////////////// @@ -67,8 +67,8 @@ stream << "\tFILE: " << stackTrace[stackTrace.size()-1].first; stream << ", LINE: " << stackTrace[stackTrace.size()-1].second; - activemq::logger::SimpleLogger logger("com.yadda2"); - logger.log( stream.str() ); + //activemq::logger::SimpleLogger logger("com.yadda2"); + //logger.log( stream.str() ); } Modified: incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/transport/IOTransport.cpp URL: http://svn.apache.org/viewvc/incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/transport/IOTransport.cpp?view=diff&rev=481264&r1=481263&r2=481264 ============================================================================== --- incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/transport/IOTransport.cpp (original) +++ incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/transport/IOTransport.cpp Fri Dec 1 07:37:22 2006 @@ -26,6 +26,8 @@ using namespace activemq::transport; using namespace activemq::concurrent; +LOGCMS_INITIALIZE(logger, IOTransport, "activemq.transport.IOTransport" ) + //////////////////////////////////////////////////////////////////////////////// IOTransport::IOTransport(){ @@ -146,34 +148,45 @@ //////////////////////////////////////////////////////////////////////////////// void IOTransport::run(){ - try{ + try{ - while( !closed ){ + while( !closed ){ - // Read the next command from the input stream. - Command* command = reader->readCommand(); + // Read the next command from the input stream. + Command* command = reader->readCommand(); - // Notify the listener. - fire( command ); - } - - }catch( exceptions::ActiveMQException& ex ){ - - ex.setMark( __FILE__, __LINE__ ); - - if( !closed ) { - fire( ex ); - } - } - catch( ... ){ + // Notify the listener. + fire( command ); + } - if( !closed ) { - exceptions::ActiveMQException ex( - __FILE__, __LINE__, - "IOTransport::run - caught unknown exception" ); + } + catch( activemq::io::IOException& ex ){ + + // This is expected for your typical broken socket - this + // is an error to be handled by the user, so let's not bother + // logging it - just inform the user through a callback. + ex.setMark( __FILE__, __LINE__ ); + fire( ex ); + } + catch( exceptions::ActiveMQException& ex ){ - fire( ex ); - } - } + ex.setMark( __FILE__, __LINE__ ); + + LOGCMS_WARN(logger, ex.getStackTraceString().c_str() ) + + fire( ex ); + } + catch( ... ){ + + if( !closed ) { + exceptions::ActiveMQException ex( + __FILE__, __LINE__, + "IOTransport::run - caught unknown exception" ); + + LOGCMS_WARN(logger, ex.getStackTraceString().c_str() ) + + fire( ex ); + } + } } Modified: incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/transport/IOTransport.h URL: http://svn.apache.org/viewvc/incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/transport/IOTransport.h?view=diff&rev=481264&r1=481263&r2=481264 ============================================================================== --- incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/transport/IOTransport.h (original) +++ incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/transport/IOTransport.h Fri Dec 1 07:37:22 2006 @@ -25,6 +25,7 @@ #include <activemq/concurrent/Thread.h> #include <activemq/exceptions/ActiveMQException.h> #include <activemq/transport/Command.h> +#include <activemq/logger/LoggerDefines.h> namespace activemq{ namespace transport{ @@ -46,6 +47,9 @@ public Transport, public concurrent::Runnable { + + LOGCMS_DECLARE( logger ) + private: /**