You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by nm...@apache.org on 2007/02/16 01:55:55 UTC
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/
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 <activemq/connector/openwire/OpenWireConnector.h>
#include <activemq/concurrent/Concurrent.h>
-#include <activemq/transport/BrokerError.h>
#include <activemq/transport/Transport.h>
-#include <activemq/transport/ExceptionResponse.h>
#include <activemq/exceptions/UnsupportedOperationException.h>
#include <activemq/util/Integer.h>
#include <activemq/util/Guid.h>
@@ -42,6 +40,8 @@
#include <activemq/connector/openwire/commands/BrokerError.h>
#include <activemq/connector/openwire/commands/ActiveMQTopic.h>
#include <activemq/connector/openwire/commands/ActiveMQQueue.h>
+#include <activemq/connector/openwire/commands/ExceptionResponse.h>
+#include <activemq/connector/openwire/commands/BrokerError.h>
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<connector::ConsumerInfo*>(resource);
- connector::SessionInfo* session =
- dynamic_cast<connector::SessionInfo*>(resource);
-
- // TODO
+ if( resource == NULL ) {
+ return;
+ }
+
+ commands::DataStructure* dataStructure = NULL;
+
+ OpenWireConsumerInfo* consumer =
+ dynamic_cast<OpenWireConsumerInfo*>(resource);
+ OpenWireSessionInfo* session =
+ dynamic_cast<OpenWireSessionInfo*>(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<ExceptionResponse*>(response);
+
+ commands::ExceptionResponse* exceptionResponse = dynamic_cast<commands::ExceptionResponse*>(response);
if( exceptionResponse != NULL )
{
// Create an exception to hold the error information.
- /*commands::BrokerError* brokerError = dynamic_cast<commands::BrokerError*>(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<commands::BrokerError*>(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 <activemq/connector/stomp/StompConnector.h>
#include <activemq/concurrent/Concurrent.h>
-#include <activemq/transport/BrokerError.h>
#include <activemq/transport/Transport.h>
-#include <activemq/transport/ExceptionResponse.h>
#include <activemq/connector/stomp/StompTopic.h>
#include <activemq/connector/stomp/StompQueue.h>
#include <activemq/connector/stomp/commands/ConnectCommand.h>
@@ -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<ExceptionResponse*>( 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 <activemq/transport/TransportFilter.h>
#include <activemq/transport/FutureResponse.h>
#include <activemq/transport/Command.h>
-#include <activemq/transport/ExceptionResponse.h>
#include <activemq/concurrent/Mutex.h>
#include <activemq/concurrent/Concurrent.h>
#include <map>
@@ -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 <cppunit/extensions/HelperMacros.h>
#include <activemq/transport/ResponseCorrelator.h>
-#include <activemq/transport/ExceptionResponse.h>
#include <activemq/concurrent/Thread.h>
#include <activemq/concurrent/Concurrent.h>
#include <activemq/exceptions/UnsupportedOperationException.h>
@@ -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<ExceptionResponse*>(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<ExceptionResponse*>(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 )