Return-Path: Delivered-To: apmail-activemq-commits-archive@www.apache.org Received: (qmail 58657 invoked from network); 16 Feb 2007 00:56:16 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 16 Feb 2007 00:56:16 -0000 Received: (qmail 10768 invoked by uid 500); 16 Feb 2007 00:56:24 -0000 Delivered-To: apmail-activemq-commits-archive@activemq.apache.org Received: (qmail 10749 invoked by uid 500); 16 Feb 2007 00:56:24 -0000 Mailing-List: contact commits-help@activemq.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@activemq.apache.org Delivered-To: mailing list commits@activemq.apache.org Received: (qmail 10740 invoked by uid 99); 16 Feb 2007 00:56:24 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 15 Feb 2007 16:56:24 -0800 X-ASF-Spam-Status: No, hits=-9.4 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 15 Feb 2007 16:56:15 -0800 Received: by eris.apache.org (Postfix, from userid 65534) id 851DD1A981A; Thu, 15 Feb 2007 16:55:55 -0800 (PST) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r508257 - in /activemq/activemq-cpp/trunk/activemq-cpp/src: main/ main/activemq/connector/openwire/ main/activemq/connector/stomp/ main/activemq/transport/ test/activemq/transport/ Date: Fri, 16 Feb 2007 00:55:55 -0000 To: commits@activemq.apache.org From: nmittler@apache.org X-Mailer: svnmailer-1.1.0 Message-Id: <20070216005555.851DD1A981A@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: nmittler Date: Thu Feb 15 16:55:54 2007 New Revision: 508257 URL: http://svn.apache.org/viewvc?view=rev&rev=508257 Log: [AMQCPP-30] Adding destruction of sessionInfo and added proper exception handling in the syncRequest method Removed: activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/transport/BrokerError.h activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/transport/ExceptionResponse.h Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/Makefile.am activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/connector/openwire/BrokerException.h activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/connector/openwire/OpenWireConnector.cpp activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/connector/stomp/StompConnector.cpp activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/transport/ResponseCorrelator.cpp activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/transport/ResponseCorrelator.h activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/transport/ResponseCorrelatorTest.h Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/Makefile.am URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/Makefile.am?view=diff&rev=508257&r1=508256&r2=508257 ============================================================================== --- activemq/activemq-cpp/trunk/activemq-cpp/src/main/Makefile.am (original) +++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/Makefile.am Thu Feb 15 16:55:54 2007 @@ -236,12 +236,10 @@ activemq/transport/Transport.h \ activemq/transport/TransportFactory.h \ activemq/transport/CommandListener.h \ - activemq/transport/ExceptionResponse.h \ activemq/transport/ResponseCorrelator.h \ activemq/transport/IOTransport.h \ activemq/transport/TcpTransport.h \ activemq/transport/TransportExceptionListener.h \ - activemq/transport/BrokerError.h \ activemq/transport/CommandReader.h \ activemq/transport/TcpTransportFactory.h \ activemq/transport/Command.h \ Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/connector/openwire/BrokerException.h URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/connector/openwire/BrokerException.h?view=diff&rev=508257&r1=508256&r2=508257 ============================================================================== --- activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/connector/openwire/BrokerException.h (original) +++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/connector/openwire/BrokerException.h Thu Feb 15 16:55:54 2007 @@ -27,7 +27,8 @@ namespace openwire{ class BrokerException : public OpenWireConnectorException { - + public: + BrokerException() throw(){} BrokerException( const exceptions::ActiveMQException& ex ) throw() : OpenWireConnectorException(){ Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/connector/openwire/OpenWireConnector.cpp URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/connector/openwire/OpenWireConnector.cpp?view=diff&rev=508257&r1=508256&r2=508257 ============================================================================== --- activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/connector/openwire/OpenWireConnector.cpp (original) +++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/connector/openwire/OpenWireConnector.cpp Thu Feb 15 16:55:54 2007 @@ -18,9 +18,7 @@ #include #include -#include #include -#include #include #include #include @@ -42,6 +40,8 @@ #include #include #include +#include +#include using namespace std; using namespace activemq; @@ -100,10 +100,25 @@ { close(); - delete transport; - delete wireFormat; - delete brokerInfo; - delete brokerWireFormatInfo; + if( transport != NULL ) { + delete transport; + transport = NULL; + } + + if( wireFormat != NULL ) { + delete wireFormat; + wireFormat = NULL; + } + + if( brokerInfo != NULL ) { + delete brokerInfo; + brokerInfo = NULL; + } + + if( brokerWireFormatInfo != NULL ) { + delete brokerWireFormatInfo; + brokerWireFormatInfo = NULL; + } } AMQ_CATCH_NOTHROW( ActiveMQException ) AMQ_CATCHALL_NOTHROW( ) @@ -317,7 +332,7 @@ } } AMQ_CATCH_RETHROW( ConnectorException ) - AMQ_CATCHALL_THROW( ConnectorException ) + AMQ_CATCHALL_THROW( OpenWireConnectorException ) } //////////////////////////////////////////////////////////////////////////////// @@ -368,7 +383,7 @@ return consumer; } AMQ_CATCH_RETHROW( ConnectorException ) - AMQ_CATCHALL_THROW( ConnectorException ) + AMQ_CATCHALL_THROW( OpenWireConnectorException ) } //////////////////////////////////////////////////////////////////////////////// @@ -388,7 +403,7 @@ return NULL; } AMQ_CATCH_RETHROW( ConnectorException ) - AMQ_CATCHALL_THROW( ConnectorException ) + AMQ_CATCHALL_THROW( OpenWireConnectorException ) } //////////////////////////////////////////////////////////////////////////////// @@ -432,7 +447,7 @@ return producer; } AMQ_CATCH_RETHROW( ConnectorException ) - AMQ_CATCHALL_THROW( ConnectorException ) + AMQ_CATCHALL_THROW( OpenWireConnectorException ) } //////////////////////////////////////////////////////////////////////////////// @@ -447,7 +462,7 @@ return new commands::ActiveMQTopic( name ); } AMQ_CATCH_RETHROW( ConnectorException ) - AMQ_CATCHALL_THROW( ConnectorException ) + AMQ_CATCHALL_THROW( OpenWireConnectorException ) } //////////////////////////////////////////////////////////////////////////////// @@ -462,7 +477,7 @@ return new commands::ActiveMQQueue( name ); } AMQ_CATCH_RETHROW( ConnectorException ) - AMQ_CATCHALL_THROW( ConnectorException ) + AMQ_CATCHALL_THROW( OpenWireConnectorException ) } //////////////////////////////////////////////////////////////////////////////// @@ -478,7 +493,7 @@ return NULL; } AMQ_CATCH_RETHROW( ConnectorException ) - AMQ_CATCHALL_THROW( ConnectorException ) + AMQ_CATCHALL_THROW( OpenWireConnectorException ) } //////////////////////////////////////////////////////////////////////////////// @@ -494,7 +509,7 @@ return NULL; } AMQ_CATCH_RETHROW( ConnectorException ) - AMQ_CATCHALL_THROW( ConnectorException ) + AMQ_CATCHALL_THROW( OpenWireConnectorException ) } //////////////////////////////////////////////////////////////////////////////// @@ -546,7 +561,7 @@ ex.what() ); } AMQ_CATCH_RETHROW( ConnectorException ) - AMQ_CATCHALL_THROW( ConnectorException ) + AMQ_CATCHALL_THROW( OpenWireConnectorException ) } //////////////////////////////////////////////////////////////////////////////// @@ -566,7 +581,7 @@ } } AMQ_CATCH_RETHROW( ConnectorException ) - AMQ_CATCHALL_THROW( ConnectorException ) + AMQ_CATCHALL_THROW( OpenWireConnectorException ) } //////////////////////////////////////////////////////////////////////////////// @@ -610,7 +625,7 @@ ex.what() ); } AMQ_CATCH_RETHROW( ConnectorException ) - AMQ_CATCHALL_THROW( ConnectorException ) + AMQ_CATCHALL_THROW( OpenWireConnectorException ) } //////////////////////////////////////////////////////////////////////////////// @@ -645,7 +660,7 @@ ex.what() ); } AMQ_CATCH_RETHROW( ConnectorException ) - AMQ_CATCHALL_THROW( ConnectorException ) + AMQ_CATCHALL_THROW( OpenWireConnectorException ) return NULL; } @@ -671,7 +686,7 @@ ex.what() ); } AMQ_CATCH_RETHROW( ConnectorException ) - AMQ_CATCHALL_THROW( ConnectorException ) + AMQ_CATCHALL_THROW( OpenWireConnectorException ) } //////////////////////////////////////////////////////////////////////////////// @@ -696,7 +711,7 @@ ex.what() ); } AMQ_CATCH_RETHROW( ConnectorException ) - AMQ_CATCHALL_THROW( ConnectorException ) + AMQ_CATCHALL_THROW( OpenWireConnectorException ) } //////////////////////////////////////////////////////////////////////////////// @@ -714,7 +729,7 @@ return NULL; } AMQ_CATCH_RETHROW( ConnectorException ) - AMQ_CATCHALL_THROW( ConnectorException ) + AMQ_CATCHALL_THROW( OpenWireConnectorException ) } //////////////////////////////////////////////////////////////////////////////// @@ -732,7 +747,7 @@ return NULL; } AMQ_CATCH_RETHROW( ConnectorException ) - AMQ_CATCHALL_THROW( ConnectorException ) + AMQ_CATCHALL_THROW( OpenWireConnectorException ) } //////////////////////////////////////////////////////////////////////////////// @@ -750,7 +765,7 @@ return NULL; } AMQ_CATCH_RETHROW( ConnectorException ) - AMQ_CATCHALL_THROW( ConnectorException ) + AMQ_CATCHALL_THROW( OpenWireConnectorException ) } //////////////////////////////////////////////////////////////////////////////// @@ -768,7 +783,7 @@ return NULL; } AMQ_CATCH_RETHROW( ConnectorException ) - AMQ_CATCHALL_THROW( ConnectorException ) + AMQ_CATCHALL_THROW( OpenWireConnectorException ) } //////////////////////////////////////////////////////////////////////////////// @@ -782,7 +797,7 @@ // TODO } AMQ_CATCH_RETHROW( ConnectorException ) - AMQ_CATCHALL_THROW( ConnectorException ) + AMQ_CATCHALL_THROW( OpenWireConnectorException ) } //////////////////////////////////////////////////////////////////////////////// @@ -791,18 +806,40 @@ { try { - connector::ConsumerInfo* consumer = - dynamic_cast(resource); - connector::SessionInfo* session = - dynamic_cast(resource); - - // TODO + if( resource == NULL ) { + return; + } + + commands::DataStructure* dataStructure = NULL; + + OpenWireConsumerInfo* consumer = + dynamic_cast(resource); + OpenWireSessionInfo* session = + dynamic_cast(resource); + + if( consumer != NULL ) { + dataStructure = consumer->getConsumerInfo(); + } else if( session != NULL ) { + dataStructure = session->getSessionInfo(); + } + + if( dataStructure == NULL ) { + throw OpenWireConnectorException(__FILE__,__LINE__, + "attempting to destroy an invalid resource"); + } + + // Dispose of this data structure at the broker. + disposeOf( dataStructure ); // No matter what we end it here. delete resource; } - AMQ_CATCH_RETHROW( ConnectorException ) - AMQ_CATCHALL_THROW( ConnectorException ) + catch( ConnectorException& ex ) { + delete resource; + ex.setMark(__FILE__, __LINE__ ); + throw ex; + } + AMQ_CATCHALL_THROW( OpenWireConnectorException ) } //////////////////////////////////////////////////////////////////////////////// @@ -858,7 +895,7 @@ } } AMQ_CATCH_RETHROW( ConnectorException ) - AMQ_CATCHALL_THROW( ConnectorException ) + AMQ_CATCHALL_THROW( OpenWireConnectorException ) } //////////////////////////////////////////////////////////////////////////////// @@ -880,7 +917,7 @@ fire( ex ); } AMQ_CATCH_RETHROW( ConnectorException ) - AMQ_CATCHALL_THROW( ConnectorException ) + AMQ_CATCHALL_THROW( OpenWireConnectorException ) } //////////////////////////////////////////////////////////////////////////////// @@ -906,14 +943,13 @@ { enforceConnected(); Response* response = transport->request(command); - ExceptionResponse* exceptionResponse = dynamic_cast(response); + + commands::ExceptionResponse* exceptionResponse = dynamic_cast(response); if( exceptionResponse != NULL ) { // Create an exception to hold the error information. - /*commands::BrokerError* brokerError = dynamic_cast(exceptionResponse->getException()); - BrokerException exception( __FILE__, __LINE__, brokerError );*/ - /* TODO: Bridge between transport::BrokerError and openwire::commands::BrokerError */ - OpenWireConnectorException exception( __FILE__, __LINE__, "An error occurred at the broker" ); + commands::BrokerError* brokerError = dynamic_cast(exceptionResponse->getException()); + BrokerException exception( __FILE__, __LINE__, brokerError ); // Free the response command. delete response; Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/connector/stomp/StompConnector.cpp URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/connector/stomp/StompConnector.cpp?view=diff&rev=508257&r1=508256&r2=508257 ============================================================================== --- activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/connector/stomp/StompConnector.cpp (original) +++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/connector/stomp/StompConnector.cpp Thu Feb 15 16:55:54 2007 @@ -17,9 +17,7 @@ #include #include -#include #include -#include #include #include #include @@ -217,15 +215,6 @@ Response* response = transport->request( &cmd ); - if( dynamic_cast< ExceptionResponse* >( response ) != NULL ) - { - delete response; - - throw StompConnectorException( - __FILE__, __LINE__, - "StompConnector::connect - Failed on Connect Request" ); - } - ConnectedCommand* connected = dynamic_cast< ConnectedCommand* >( response ); @@ -265,7 +254,6 @@ // Clean up delete response; } - AMQ_CATCH_RETHROW( BrokerError ) AMQ_CATCH_RETHROW( ActiveMQException ) AMQ_CATCHALL_THROW( ActiveMQException ) } Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/transport/ResponseCorrelator.cpp URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/transport/ResponseCorrelator.cpp?view=diff&rev=508257&r1=508256&r2=508257 ============================================================================== --- activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/transport/ResponseCorrelator.cpp (original) +++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/transport/ResponseCorrelator.cpp Thu Feb 15 16:55:54 2007 @@ -186,14 +186,6 @@ FutureResponse* futureResponse = NULL; futureResponse = iter->second; - // If it's an exception response, notify the exception listener. - ExceptionResponse* exResp = - dynamic_cast( response ); - if( exResp != NULL ){ - const BrokerError* error = exResp->getException(); - fire( *error ); - } - synchronized( futureResponse ){ // Set the response property in the future response. Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/transport/ResponseCorrelator.h URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/transport/ResponseCorrelator.h?view=diff&rev=508257&r1=508256&r2=508257 ============================================================================== --- activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/transport/ResponseCorrelator.h (original) +++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/transport/ResponseCorrelator.h Thu Feb 15 16:55:54 2007 @@ -21,7 +21,6 @@ #include #include #include -#include #include #include #include @@ -115,8 +114,7 @@ /** * Sends the given request to the server and waits for the response. * @param command The request to send. - * @return the response from the server. This may be of type ExceptionResponse - * in the case of a distributed error that occurs at the broker. + * @return the response from the server. * @throws CommandIOException if an error occurs with the request. */ virtual Response* request( Command* command ) Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/transport/ResponseCorrelatorTest.h URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/transport/ResponseCorrelatorTest.h?view=diff&rev=508257&r1=508256&r2=508257 ============================================================================== --- activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/transport/ResponseCorrelatorTest.h (original) +++ activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/transport/ResponseCorrelatorTest.h Thu Feb 15 16:55:54 2007 @@ -22,7 +22,6 @@ #include #include -#include #include #include #include @@ -37,7 +36,6 @@ CPPUNIT_TEST_SUITE( ResponseCorrelatorTest ); CPPUNIT_TEST( testBasics ); CPPUNIT_TEST( testOneway ); - CPPUNIT_TEST( testExceptionResponse ); CPPUNIT_TEST( testTransportException ); CPPUNIT_TEST( testMultiRequests ); CPPUNIT_TEST_SUITE_END(); @@ -102,43 +100,6 @@ virtual std::string toString() const{ return ""; } }; - class MyExceptionResponse : public ExceptionResponse{ - public: - - unsigned int commandId; - bool responseRequired; - unsigned int corrId; - BrokerError error; - - public: - - virtual void setCommandId( int id ){ - commandId = id; - } - virtual int getCommandId() const{ - return commandId; - } - - virtual void setResponseRequired( const bool required ){ - responseRequired = required; - } - virtual bool isResponseRequired() const{ - return responseRequired; - } - - virtual int getCorrelationId() const{ - return corrId; - } - virtual void setCorrelationId( int corrId ){ - this->corrId = corrId; - } - virtual const BrokerError* getException() const{ - return &error; - } - - virtual std::string toString() const{ return ""; } - }; - class MyTransport : public Transport, @@ -292,23 +253,6 @@ } }; - class MyExceptionResponseTransport : public MyTransport{ - public: - - MyExceptionResponseTransport(){} - virtual ~MyExceptionResponseTransport(){} - - virtual Response* createResponse( Command* command ){ - - MyExceptionResponse* resp = new MyExceptionResponse(); - resp->setCorrelationId( command->getCommandId() ); - resp->setResponseRequired( false ); - resp->error = BrokerError( __FILE__, __LINE__, - "some bad broker stuff" ); - return resp; - } - }; - class MyBrokenTransport : public MyTransport{ public: @@ -420,7 +364,6 @@ MyCommand cmd; Response* resp = correlator.request( &cmd ); CPPUNIT_ASSERT( resp != NULL ); - CPPUNIT_ASSERT( dynamic_cast(resp) == NULL ); CPPUNIT_ASSERT( resp->getCorrelationId() == cmd.getCommandId() ); // Wait to get the message back asynchronously. @@ -477,52 +420,6 @@ CPPUNIT_ASSERT( listener.exCount == 0 ); correlator.close(); - } - AMQ_CATCH_RETHROW( exceptions::ActiveMQException ) - AMQ_CATCHALL_THROW( exceptions::ActiveMQException ) - } - - void testExceptionResponse(){ - - try{ - - MyListener listener; - MyExceptionResponseTransport transport; - ResponseCorrelator correlator( &transport, false ); - correlator.setCommandListener( &listener ); - correlator.setTransportExceptionListener( &listener ); - CPPUNIT_ASSERT( transport.listener == &correlator ); - CPPUNIT_ASSERT( transport.exListener == &correlator ); - - // Give the thread a little time to get up and running. - synchronized(&transport.startedMutex) - { - // Start the transport. - correlator.start(); - - transport.startedMutex.wait(); - } - - // Send one request. - MyCommand cmd; - Response* resp = correlator.request( &cmd ); - CPPUNIT_ASSERT( resp != NULL ); - CPPUNIT_ASSERT( dynamic_cast(resp) != NULL ); - CPPUNIT_ASSERT( resp->getCorrelationId() == cmd.getCommandId() ); - - // Wait to make sure we get the exception. - concurrent::Thread::sleep( 100 ); - - // Since our transport relays our original command back at us as a - // non-response message, check to make sure we received it and that - // it is the original command. - CPPUNIT_ASSERT( listener.commands.size() == 1 ); - CPPUNIT_ASSERT( listener.exCount == 1 ); - - correlator.close(); - - // Destroy the response. - delete resp; } AMQ_CATCH_RETHROW( exceptions::ActiveMQException ) AMQ_CATCHALL_THROW( exceptions::ActiveMQException )