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/05/23 15:23:44 UTC

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

Author: tabish
Date: Wed May 23 06:23:43 2007
New Revision: 540948

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

Fixed typos amd sync'd send count with receive count.  Also removed the startup sleep and replaced it with a CountDownLatch in the Consumer, the main thread calls waitUntilReady on the Consumer and when the run method is finished setting up, it ticks the latch.

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=540948&r1=540947&r2=540948
==============================================================================
--- activemq/activemq-cpp/trunk/src/examples/main.cpp (original)
+++ activemq/activemq-cpp/trunk/src/examples/main.cpp Wed May 23 06:23:43 2007
@@ -19,6 +19,7 @@
 
 #include <activemq/concurrent/Thread.h>
 #include <activemq/concurrent/Runnable.h>
+#include <activemq/concurrent/CountDownLatch.h>
 #include <activemq/core/ActiveMQConnectionFactory.h>
 #include <activemq/util/Integer.h>
 #include <activemq/util/Config.h>
@@ -105,7 +106,7 @@
                 message->setIntProperty( "Integer", ix );
 
                 // Tell the producer to send the message
-                printf( "Sent message #%d from thread %s\n", ix, threadIdStr.c_str() );
+                printf( "Sent message #%d from thread %s\n", ix+1, threadIdStr.c_str() );
                 producer->send( message );
 
                 delete message;
@@ -155,6 +156,7 @@
 
 private:
 
+    CountDownLatch latch;
     Connection* connection;
     Session* session;
     Destination* destination;
@@ -166,7 +168,7 @@
 public:
 
     HelloWorldConsumer( const std::string& brokerURI,
-                        long waitMillis, bool useTopic = false ){
+                        long waitMillis, bool useTopic = false ) : latch(1){
         connection = NULL;
         session = NULL;
         destination = NULL;
@@ -179,6 +181,10 @@
         cleanup();
     }
 
+    void waitUnitlReady() {
+        latch.await();
+    }
+
     virtual void run() {
 
         try {
@@ -212,6 +218,9 @@
             std::cout.flush();
             std::cerr.flush();
 
+            // Indicate we are ready for messages.
+            latch.countDown();
+
             // Sleep while asynchronous messages come in.
             Thread::sleep( waitMillis );
 
@@ -320,8 +329,8 @@
     Thread consumerThread( &consumer );
     consumerThread.start();
 
-    // Give the consumer a but to start up.
-    Thread::sleep( 75 );
+    // Wait for the consumer to indicate that its ready to go.
+    consumer.waitUnitlReady();
 
     // Start the producer thread.
     Thread producerThread( &producer );