activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nmitt...@apache.org
Subject svn commit: r497282 - in /incubator/activemq/activemq-cpp/trunk/activemq-cpp/src: main/activemq/core/ test/activemq/connector/stomp/ test/activemq/core/
Date Thu, 18 Jan 2007 01:38:26 GMT
Author: nmittler
Date: Wed Jan 17 17:38:25 2007
New Revision: 497282

URL: http://svn.apache.org/viewvc?view=rev&rev=497282
Log:
[AMQCPP-46] - Adding fix in for receiving exceptions from ActiveMQConnection

Modified:
    incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/core/ActiveMQConnection.cpp
    incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/core/ActiveMQConnection.h
    incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/connector/stomp/StompConnectorTest.h
    incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/core/ActiveMQConnectionTest.h

Modified: incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/core/ActiveMQConnection.cpp
URL: http://svn.apache.org/viewvc/incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/core/ActiveMQConnection.cpp?view=diff&rev=497282&r1=497281&r2=497282
==============================================================================
--- incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/core/ActiveMQConnection.cpp
(original)
+++ incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/core/ActiveMQConnection.cpp
Wed Jan 17 17:38:25 2007
@@ -37,12 +37,14 @@
     this->closed = false;
     this->exceptionListener = NULL;
 
-    // We want to be the sink for all messages from the Connector
-    connectionData->getConnector()->setConsumerMessageListener( this );
+    // Register for messages and exceptions from the connector.
+    Connector* connector = connectionData->getConnector();
+    connector->setConsumerMessageListener( this );
+    connector->setExceptionListener( this );
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-ActiveMQConnection::~ActiveMQConnection(void)
+ActiveMQConnection::~ActiveMQConnection()
 {
     try
     {
@@ -53,7 +55,7 @@
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-cms::Session* ActiveMQConnection::createSession(void) 
+cms::Session* ActiveMQConnection::createSession() 
     throw ( cms::CMSException )
 {
     try
@@ -81,13 +83,13 @@
 }
    
 ////////////////////////////////////////////////////////////////////////////////
-std::string ActiveMQConnection::getClientId(void) const
+std::string ActiveMQConnection::getClientId() const
 {
    return connectionData->getConnector()->getClientId();
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-void ActiveMQConnection::close(void) throw ( cms::CMSException )
+void ActiveMQConnection::close() throw ( cms::CMSException )
 {
     try
     {
@@ -113,7 +115,7 @@
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-void ActiveMQConnection::start(void) throw ( cms::CMSException )
+void ActiveMQConnection::start() throw ( cms::CMSException )
 {
     // This starts or restarts the delivery of all incomming messages
     // messages delivered while this connection is stopped are dropped
@@ -122,7 +124,7 @@
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-void ActiveMQConnection::stop(void) throw ( cms::CMSException )
+void ActiveMQConnection::stop() throw ( cms::CMSException )
 {
     // Once current deliveries are done this stops the delivery of any
     // new messages.
@@ -207,5 +209,13 @@
         fire( ex );            
     }
 
-}                                             
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ActiveMQConnection::onException( const CMSException& ex ){
+    
+    if( exceptionListener != NULL ){
+        exceptionListener->onException( ex );
+    }
+}                                        
 

Modified: incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/core/ActiveMQConnection.h
URL: http://svn.apache.org/viewvc/incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/core/ActiveMQConnection.h?view=diff&rev=497282&r1=497281&r2=497282
==============================================================================
--- incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/core/ActiveMQConnection.h
(original)
+++ incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/core/ActiveMQConnection.h
Wed Jan 17 17:38:25 2007
@@ -37,7 +37,8 @@
 
     class ActiveMQConnection : 
         public cms::Connection,
-        public connector::ConsumerMessageListener
+        public connector::ConsumerMessageListener,
+        public cms::ExceptionListener
     {
     private:
    
@@ -68,7 +69,7 @@
          */       
         ActiveMQConnection( ActiveMQConnectionData* connectionData );
 
-        virtual ~ActiveMQConnection(void);
+        virtual ~ActiveMQConnection();
    
     public:   // Connection Interface Methods
    
@@ -76,7 +77,7 @@
          * Creates a new Session to work for this Connection
          * @throws CMSException
          */
-        virtual cms::Session* createSession(void) throw ( cms::CMSException );
+        virtual cms::Session* createSession() throw ( cms::CMSException );
       
         /**
          * Creates a new Session to work for this Connection using the
@@ -91,13 +92,13 @@
          * Get the Client Id for this session
          * @return string version of Client Id
          */
-        virtual std::string getClientId(void) const;
+        virtual std::string getClientId() const;
       
         /**
          * Retrieves the Connection Data object for this object.
          * @return pointer to a connection data object.
          */
-        virtual ActiveMQConnectionData* getConnectionData(void){
+        virtual ActiveMQConnectionData* getConnectionData(){
             return connectionData;
         } 
          
@@ -105,7 +106,7 @@
          * Gets the registered Exception Listener for this connection
          * @return pointer to an exception listnener or NULL
          */
-        virtual cms::ExceptionListener* getExceptionListener(void) const{
+        virtual cms::ExceptionListener* getExceptionListener() const{
             return exceptionListener; };
       
         /**
@@ -113,25 +114,26 @@
          * @param listener pointer to and <code>ExceptionListener</code>
          */
         virtual void setExceptionListener( cms::ExceptionListener* listener ){
-            exceptionListener = listener; };
+            exceptionListener = listener; 
+        };
          
         /**
          * Close the currently open connection
          * @throws CMSException
          */
-        virtual void close(void) throw ( cms::CMSException );
+        virtual void close() throw ( cms::CMSException );
       
         /**
          * Starts or (restarts) a connections delivery of incoming messages
          * @throws CMSException
          */
-        virtual void start(void) throw ( cms::CMSException );
+        virtual void start() throw ( cms::CMSException );
       
         /**
          * Stop the flow of incoming messages
          * @throws CMSException
          */
-        virtual void stop(void) throw ( cms::CMSException );
+        virtual void stop() throw ( cms::CMSException );
 
     public:   // ActiveMQConnection Methods
    
@@ -151,6 +153,26 @@
          */
         virtual void removeMessageListener( const unsigned int consumerId );
 
+    public:     // ExceptionListener interface methods
+    
+        /**
+         * Called when an exception occurs.  Once notified of an exception
+         * the caller should no longer use the resource that generated the
+         * exception.
+         * @param Exception Object that occurred.
+         */
+        virtual void onException( const cms::CMSException& ex );
+        
+    public:     // ConsumerMessageListener interface methods
+    
+        /**
+         * Called to dispatch a message to a particular consumer.
+         * @param consumer the target consumer of the dispatch.
+         * @param message the message to be dispatched.
+         */
+        virtual void onConsumerMessage( connector::ConsumerInfo* consumer,
+                                        core::ActiveMQMessage* message );
+                                                                                
     private:
    
         /**
@@ -167,15 +189,7 @@
                 }
                 catch(...){}
             }
-        }
-
-        /**
-         * Called to dispatch a message to a particular consumer.
-         * @param consumer the target consumer of the dispatch.
-         * @param message the message to be dispatched.
-         */
-        virtual void onConsumerMessage( connector::ConsumerInfo* consumer,
-                                        core::ActiveMQMessage* message );
+        }        
    
     };
 

Modified: incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/connector/stomp/StompConnectorTest.h
URL: http://svn.apache.org/viewvc/incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/connector/stomp/StompConnectorTest.h?view=diff&rev=497282&r1=497281&r2=497282
==============================================================================
--- incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/connector/stomp/StompConnectorTest.h
(original)
+++ incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/connector/stomp/StompConnectorTest.h
Wed Jan 17 17:38:25 2007
@@ -46,12 +46,23 @@
         CPPUNIT_TEST( testProducers );
         CPPUNIT_TEST( testCommand );
         CPPUNIT_TEST( testSendingCommands );
+        CPPUNIT_TEST( testException );
         CPPUNIT_TEST_SUITE_END();
 
     public:
     
-    	StompConnectorTest() {}
-    	virtual ~StompConnectorTest() {}
+        StompConnectorTest() {}
+        virtual ~StompConnectorTest() {}
+        
+        class MyExceptionListener : public cms::ExceptionListener{
+            public:
+                int num;
+                MyExceptionListener(){ num=0;}
+                virtual ~MyExceptionListener(){}
+                virtual void onException( const cms::CMSException& ex ){
+                    num++;
+                }
+        };        
         
         class MyCommandListener : public transport::CommandListener{
         public:
@@ -362,7 +373,32 @@
             CPPUNIT_ASSERT( cmdListener.cmd != NULL );
         }
 
-    };
+        void testException()
+        {
+            std::string connectionId = "testConnectionId";
+            StompResponseBuilder responseBuilder("testConnectionId");
+            transport::DummyTransport transport( &responseBuilder );
+            MyExceptionListener exListener;
+            util::SimpleProperties properties;
+            
+            // Using a pointer for the connector so we ensure the proper destruction
+            // order of objects - connector before the transport.
+            StompConnector* connector = new StompConnector( &transport, properties );
+            
+            connector->setExceptionListener(&exListener);
+            
+            connector->start();
+            
+            // Initiate an exception from the transport.
+            transport.fireException( exceptions::ActiveMQException(__FILE__, __LINE__, "test")
);
+            
+            CPPUNIT_ASSERT( exListener.num == 1 );
+
+            // Delete the connector here - this assures the propery order
+            // of destruction.
+            delete connector;
+        }
+    };    
 
 }}}
 

Modified: incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/core/ActiveMQConnectionTest.h
URL: http://svn.apache.org/viewvc/incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/core/ActiveMQConnectionTest.h?view=diff&rev=497282&r1=497281&r2=497282
==============================================================================
--- incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/core/ActiveMQConnectionTest.h
(original)
+++ incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/core/ActiveMQConnectionTest.h
Wed Jan 17 17:38:25 2007
@@ -165,13 +165,17 @@
                     new connector::stomp::StompConnector( 
                         transport, *properties );
 
-                connector->start();
+                connector->start();                
                 
                 ActiveMQConnection connection( 
                     new ActiveMQConnectionData(
                         connector, transport, properties) );
 
+                // First - make sure exceptions are working.
                 connection.setExceptionListener( &exListener );
+                CPPUNIT_ASSERT( exListener.caughtOne == false );
+                dTransport->fireException( exceptions::ActiveMQException( __FILE__, __LINE__,
"test" ) );
+                CPPUNIT_ASSERT( exListener.caughtOne == true );                         
      
                         
                 cms::Session* session1 = connection.createSession();
                 cms::Session* session2 = connection.createSession();
@@ -242,6 +246,7 @@
                 session3->close();
                 connection.close();
 
+                exListener.caughtOne = false;
                 consumerListener->onConsumerMessage( &consumer, cmd );
                 CPPUNIT_ASSERT( exListener.caughtOne == true );
 



Mime
View raw message