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/12/05 21:52:27 UTC

svn commit: r887588 - in /activemq/activemq-cpp/branches/activemq-cpp-3.1.x/activemq-cpp/src: examples/consumers/SimpleAsyncConsumer.cpp examples/main.cpp examples/producers/SimpleProducer.cpp main/activemq/core/ActiveMQSession.cpp

Author: tabish
Date: Sat Dec  5 20:52:26 2009
New Revision: 887588

URL: http://svn.apache.org/viewvc?rev=887588&view=rev
Log:
http://issues.apache.org/activemq/browse/AMQCPP-271

Change the example code so that the shutdown is performed properly.

Modified:
    activemq/activemq-cpp/branches/activemq-cpp-3.1.x/activemq-cpp/src/examples/consumers/SimpleAsyncConsumer.cpp
    activemq/activemq-cpp/branches/activemq-cpp-3.1.x/activemq-cpp/src/examples/main.cpp
    activemq/activemq-cpp/branches/activemq-cpp-3.1.x/activemq-cpp/src/examples/producers/SimpleProducer.cpp
    activemq/activemq-cpp/branches/activemq-cpp-3.1.x/activemq-cpp/src/main/activemq/core/ActiveMQSession.cpp

Modified: activemq/activemq-cpp/branches/activemq-cpp-3.1.x/activemq-cpp/src/examples/consumers/SimpleAsyncConsumer.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/branches/activemq-cpp-3.1.x/activemq-cpp/src/examples/consumers/SimpleAsyncConsumer.cpp?rev=887588&r1=887587&r2=887588&view=diff
==============================================================================
--- activemq/activemq-cpp/branches/activemq-cpp-3.1.x/activemq-cpp/src/examples/consumers/SimpleAsyncConsumer.cpp (original)
+++ activemq/activemq-cpp/branches/activemq-cpp-3.1.x/activemq-cpp/src/examples/consumers/SimpleAsyncConsumer.cpp Sat Dec  5 20:52:26 2009
@@ -77,7 +77,11 @@
     }
 
     virtual ~SimpleAsyncConsumer(){
-        cleanup();
+        this->cleanup();
+    }
+
+    void close() {
+        this->cleanup();
     }
 
     void runConsumer() {
@@ -156,7 +160,7 @@
     // registered as an ExceptionListener with the connection.
     virtual void onException( const CMSException& ex AMQCPP_UNUSED ) {
         printf("CMS Exception occurred.  Shutting down client.\n");
-        exit(1);
+        //exit(1);
     }
 
     virtual void transportInterrupted() {
@@ -179,29 +183,29 @@
         // Destroy resources.
         try{
             if( destination != NULL ) delete destination;
-        }catch (CMSException& e) { e.printStackTrace(); }
+        }catch (CMSException& e) {}
         destination = NULL;
 
         try{
             if( consumer != NULL ) delete consumer;
-        }catch (CMSException& e) { e.printStackTrace(); }
+        }catch (CMSException& e) {}
         consumer = NULL;
 
         // Close open resources.
         try{
             if( session != NULL ) session->close();
             if( connection != NULL ) connection->close();
-        }catch (CMSException& e) { e.printStackTrace(); }
+        }catch (CMSException& e) {}
 
         // Now Destroy them
         try{
             if( session != NULL ) delete session;
-        }catch (CMSException& e) { e.printStackTrace(); }
+        }catch (CMSException& e) {}
         session = NULL;
 
         try{
             if( connection != NULL ) delete connection;
-        }catch (CMSException& e) { e.printStackTrace(); }
+        }catch (CMSException& e) {}
         connection = NULL;
     }
 };
@@ -270,6 +274,9 @@
     std::cout << "Press 'q' to quit" << std::endl;
     while( std::cin.get() != 'q') {}
 
+    // All CMS resources should be closed before the library is shutdown.
+    consumer.close();
+
     std::cout << "-----------------------------------------------------\n";
     std::cout << "Finished with the example." << std::endl;
     std::cout << "=====================================================\n";

Modified: activemq/activemq-cpp/branches/activemq-cpp-3.1.x/activemq-cpp/src/examples/main.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/branches/activemq-cpp-3.1.x/activemq-cpp/src/examples/main.cpp?rev=887588&r1=887587&r2=887588&view=diff
==============================================================================
--- activemq/activemq-cpp/branches/activemq-cpp-3.1.x/activemq-cpp/src/examples/main.cpp (original)
+++ activemq/activemq-cpp/branches/activemq-cpp-3.1.x/activemq-cpp/src/examples/main.cpp Sat Dec  5 20:52:26 2009
@@ -76,6 +76,10 @@
         cleanup();
     }
 
+    void close() {
+        this->cleanup();
+    }
+
     virtual void run() {
 
         try {
@@ -199,6 +203,10 @@
         cleanup();
     }
 
+    void close() {
+        this->cleanup();
+    }
+
     void waitUntilReady() {
         latch.await();
     }
@@ -400,6 +408,9 @@
     long long endTime = System::currentTimeMillis();
     double totalTime = (endTime - startTime) / 1000.0;
 
+    consumer.close();
+    producer.close();
+
     std::cout << "Time to completion = " << totalTime << " seconds." << std::endl;
     std::cout << "-----------------------------------------------------\n";
     std::cout << "Finished with the example." << std::endl;

Modified: activemq/activemq-cpp/branches/activemq-cpp-3.1.x/activemq-cpp/src/examples/producers/SimpleProducer.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/branches/activemq-cpp-3.1.x/activemq-cpp/src/examples/producers/SimpleProducer.cpp?rev=887588&r1=887587&r2=887588&view=diff
==============================================================================
--- activemq/activemq-cpp/branches/activemq-cpp-3.1.x/activemq-cpp/src/examples/producers/SimpleProducer.cpp (original)
+++ activemq/activemq-cpp/branches/activemq-cpp-3.1.x/activemq-cpp/src/examples/producers/SimpleProducer.cpp Sat Dec  5 20:52:26 2009
@@ -81,6 +81,10 @@
         cleanup();
     }
 
+    void close() {
+        this->cleanup();
+    }
+
     virtual void run() {
         try {
             // Create a ConnectionFactory
@@ -226,6 +230,7 @@
     // Create the producer and run it.
     SimpleProducer producer( brokerURI, numMessages, destURI, useTopics );
     producer.run();
+    producer.close();
 
     std::cout << "-----------------------------------------------------\n";
     std::cout << "Finished with the example." << std::endl;

Modified: activemq/activemq-cpp/branches/activemq-cpp-3.1.x/activemq-cpp/src/main/activemq/core/ActiveMQSession.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/branches/activemq-cpp-3.1.x/activemq-cpp/src/main/activemq/core/ActiveMQSession.cpp?rev=887588&r1=887587&r2=887588&view=diff
==============================================================================
--- activemq/activemq-cpp/branches/activemq-cpp-3.1.x/activemq-cpp/src/main/activemq/core/ActiveMQSession.cpp (original)
+++ activemq/activemq-cpp/branches/activemq-cpp-3.1.x/activemq-cpp/src/main/activemq/core/ActiveMQSession.cpp Sat Dec  5 20:52:26 2009
@@ -118,6 +118,9 @@
 
     try {
 
+        // Now indicate that this session is closed.
+        closed = true;
+
         // Stop the dispatch executor.
         stop();
 
@@ -163,9 +166,6 @@
         info->setObjectId( this->sessionInfo->getSessionId() );
         info->setLastDeliveredSequenceId( this->lastDeliveredSequenceId );
         this->connection->oneway( info );
-
-        // Now indicate that this session is closed.
-        closed = true;
     }
     AMQ_CATCH_ALL_THROW_CMSEXCEPTION()
 }