activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject svn commit: r1419580 - in /activemq/activemq-cpp/trunk/activemq-cpp/src/examples/cmstemplate-stress: Receiver.cpp Receiver.h TestSenderAndReceiver.cpp TestSenderAndReceiver.h
Date Mon, 10 Dec 2012 16:48:28 GMT
Author: tabish
Date: Mon Dec 10 16:48:27 2012
New Revision: 1419580

URL: http://svn.apache.org/viewvc?rev=1419580&view=rev
Log:
Clean up example code in preparation for next release. 

Modified:
    activemq/activemq-cpp/trunk/activemq-cpp/src/examples/cmstemplate-stress/Receiver.cpp
    activemq/activemq-cpp/trunk/activemq-cpp/src/examples/cmstemplate-stress/Receiver.h
    activemq/activemq-cpp/trunk/activemq-cpp/src/examples/cmstemplate-stress/TestSenderAndReceiver.cpp
    activemq/activemq-cpp/trunk/activemq-cpp/src/examples/cmstemplate-stress/TestSenderAndReceiver.h

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/examples/cmstemplate-stress/Receiver.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/examples/cmstemplate-stress/Receiver.cpp?rev=1419580&r1=1419579&r2=1419580&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/examples/cmstemplate-stress/Receiver.cpp
(original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/examples/cmstemplate-stress/Receiver.cpp
Mon Dec 10 16:48:27 2012
@@ -170,7 +170,7 @@ void Receiver::WaitUntilReady() {
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-void Receiver::RegisterMessageListener(const RecvMessageListener messageListener, ErrorCode&
errorCode) {
+void Receiver::RegisterMessageListener(ReceiverListener* messageListener, ErrorCode&
errorCode) {
     errorCode = CMS_SUCCESS;
 
     mutexGeneral.lock();
@@ -238,10 +238,10 @@ void Receiver::QueueMessagingTask(const 
 void Receiver::ExecuteMessagingTask(const string& message, bool bDecreaseNumOfMessagingTasks/*=true*/)
{
     if ((!closing)) {
         mutexGeneral.lock();
-        RecvMessageListener copy = messageListener;
+        ReceiverListener* copy = this->messageListener;
         mutexGeneral.unlock();
         if (copy) {
-            (*copy)(message); //listener will release the message and make reference count
0
+            copy->onMessage(message);
         }
     }
 

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/examples/cmstemplate-stress/Receiver.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/examples/cmstemplate-stress/Receiver.h?rev=1419580&r1=1419579&r2=1419580&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/examples/cmstemplate-stress/Receiver.h (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/examples/cmstemplate-stress/Receiver.h Mon
Dec 10 16:48:27 2012
@@ -31,11 +31,16 @@
 
 namespace cmstemplate {
 
-    class Receiver : public decaf::lang::Runnable {
+    class ReceiverListener {
     public:
 
-        typedef void (DECAF_STDCALL *RecvMessageListener)( const std::string& message);
+        virtual ~ReceiverListener() {}
+
+        virtual void onMessage(const std::string& message) = 0;
 
+    };
+
+    class Receiver : public decaf::lang::Runnable {
     private:
 
         std::string url;
@@ -43,7 +48,7 @@ namespace cmstemplate {
         decaf::util::concurrent::Mutex mutexGeneral;
         bool closing;
         decaf::util::concurrent::CountDownLatch ready;
-        RecvMessageListener messageListener;
+        ReceiverListener* messageListener;
         activemq::cmsutil::CmsTemplate* cmsTemplate;
         decaf::lang::Thread* asyncReceiverThread;
         long long receiveTimeout;
@@ -78,7 +83,7 @@ namespace cmstemplate {
 
         virtual void run();
 
-        void RegisterMessageListener(const RecvMessageListener m_messageListener, ErrorCode&
errorCode);
+        void RegisterMessageListener(ReceiverListener* messageListener, ErrorCode& errorCode);
 
         void ReceiveMessage(std::string& message, ErrorCode& errorCode, bool retryOnError
= true);
 

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/examples/cmstemplate-stress/TestSenderAndReceiver.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/examples/cmstemplate-stress/TestSenderAndReceiver.cpp?rev=1419580&r1=1419579&r2=1419580&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/examples/cmstemplate-stress/TestSenderAndReceiver.cpp
(original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/examples/cmstemplate-stress/TestSenderAndReceiver.cpp
Mon Dec 10 16:48:27 2012
@@ -48,7 +48,7 @@ TestSenderAndReceiver::TestSenderAndRece
     sender = new Sender(url, queueOrTopicName, isTopic, isDeliveryPersistent, timeToLive);
     receiver = new Receiver(url, queueOrTopicName, isTopic, receiveTimeout, true);
     ErrorCode errorCode = CMS_SUCCESS;
-    receiver->RegisterMessageListener(onMessage, errorCode);
+    receiver->RegisterMessageListener(this, errorCode);
 }
 
 ////////////////////////////////////////////////////////////////////////////////
@@ -111,8 +111,10 @@ void TestSenderAndReceiver::close() {
             senderThread = NULL;
         }
 
-        delete sender;
-        sender = NULL;
+        try {
+            delete sender;
+            sender = NULL;
+        } catch(Exception& ex) {}
 
         try {
             receiver->Close();

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/examples/cmstemplate-stress/TestSenderAndReceiver.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/examples/cmstemplate-stress/TestSenderAndReceiver.h?rev=1419580&r1=1419579&r2=1419580&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/examples/cmstemplate-stress/TestSenderAndReceiver.h
(original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/examples/cmstemplate-stress/TestSenderAndReceiver.h
Mon Dec 10 16:48:27 2012
@@ -28,7 +28,8 @@
 
 namespace cmstemplate {
 
-    class TestSenderAndReceiver : public decaf::lang::Runnable {
+    class TestSenderAndReceiver : public decaf::lang::Runnable,
+                                  public ReceiverListener {
     private:
 
         Sender* sender;
@@ -38,8 +39,6 @@ namespace cmstemplate {
         int sendIndex;
         int receiveIndex;
 
-        static void DECAF_STDCALL onMessage(const std::string& message);
-
     private:
 
         TestSenderAndReceiver(const TestSenderAndReceiver&);
@@ -60,6 +59,10 @@ namespace cmstemplate {
 
         void waitUntilReady();
 
+    public:
+
+        virtual void onMessage(const std::string& message);
+
     };
 }
 



Mime
View raw message