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 2007/06/18 20:10:36 UTC

svn commit: r548427 - /activemq/activemq-cpp/trunk/src/examples/main.cpp

Author: tabish
Date: Mon Jun 18 11:10:34 2007
New Revision: 548427

URL: http://svn.apache.org/viewvc?view=rev&rev=548427
Log:
Updating example to use a latch in the consumer to wait for the number of messages that the producer was told to send.

Modified:
    activemq/activemq-cpp/trunk/src/examples/main.cpp

Modified: activemq/activemq-cpp/trunk/src/examples/main.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/examples/main.cpp?view=diff&rev=548427&r1=548426&r2=548427
==============================================================================
--- activemq/activemq-cpp/trunk/src/examples/main.cpp (original)
+++ activemq/activemq-cpp/trunk/src/examples/main.cpp Mon Jun 18 11:10:34 2007
@@ -157,6 +157,7 @@
 private:
 
     CountDownLatch latch;
+    CountDownLatch doneLatch;
     Connection* connection;
     Session* session;
     Destination* destination;
@@ -168,7 +169,10 @@
 public:
 
     HelloWorldConsumer( const std::string& brokerURI,
-                        long waitMillis, bool useTopic = false ) : latch(1){
+                        long numMessages,
+                        bool useTopic = false,
+                        long waitMillis = 30000 )
+                         : latch(1), doneLatch(numMessages){
         connection = NULL;
         session = NULL;
         destination = NULL;
@@ -221,8 +225,8 @@
             // Indicate we are ready for messages.
             latch.countDown();
 
-            // Sleep while asynchronous messages come in.
-            Thread::sleep( waitMillis );
+            // Wait while asynchronous messages come in.
+            doneLatch.await( waitMillis );
 
         } catch (CMSException& e) {
             e.printStackTrace();
@@ -251,6 +255,9 @@
         } catch (CMSException& e) {
             e.printStackTrace();
         }
+
+        // No matter what, tag the count down latch until done.
+        doneLatch.countDown();
     }
 
     // If something bad happens you see it here as this class is also been
@@ -334,9 +341,10 @@
     // createQueue to be used in both consumer an producer.
     //============================================================
     bool useTopics = true;
+    int numMessages = 2000;
 
-    HelloWorldProducer producer( brokerURI, 2000, useTopics );
-    HelloWorldConsumer consumer( brokerURI, 12000, useTopics );
+    HelloWorldProducer producer( brokerURI, numMessages, useTopics );
+    HelloWorldConsumer consumer( brokerURI, numMessages, useTopics );
 
     // Start the consumer thread.
     Thread consumerThread( &consumer );