activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject svn commit: r1419764 - /activemq/activemq-cpp/trunk/activemq-cpp/src/examples/cmstemplate-stress/
Date Mon, 10 Dec 2012 21:01:39 GMT
Author: tabish
Date: Mon Dec 10 21:01:37 2012
New Revision: 1419764

URL: http://svn.apache.org/viewvc?rev=1419764&view=rev
Log:
Clean up example code in preparation for next release, fix all its memory leaks.

Modified:
    activemq/activemq-cpp/trunk/activemq-cpp/src/examples/cmstemplate-stress/CMSTestMultipleSendersReceivers.cpp
    activemq/activemq-cpp/trunk/activemq-cpp/src/examples/cmstemplate-stress/ConnectionFactoryMgr.cpp
    activemq/activemq-cpp/trunk/activemq-cpp/src/examples/cmstemplate-stress/ConnectionFactoryMgr.h
    activemq/activemq-cpp/trunk/activemq-cpp/src/examples/cmstemplate-stress/MessagingTask.cpp
    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/Sender.cpp
    activemq/activemq-cpp/trunk/activemq-cpp/src/examples/cmstemplate-stress/Sender.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/CMSTestMultipleSendersReceivers.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/examples/cmstemplate-stress/CMSTestMultipleSendersReceivers.cpp?rev=1419764&r1=1419763&r2=1419764&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/examples/cmstemplate-stress/CMSTestMultipleSendersReceivers.cpp
(original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/examples/cmstemplate-stress/CMSTestMultipleSendersReceivers.cpp
Mon Dec 10 21:01:37 2012
@@ -41,7 +41,7 @@ int main(int argc, char** argv) {
 
     printf("Test Started\n");
     int cnt = 25;
-    int done = 3600;
+    int done = 240;
 
     if (argc > 1) {
         cnt = Integer::parseInt(argv[1]);
@@ -54,10 +54,10 @@ int main(int argc, char** argv) {
     string url = "tcp://127.0.0.1:61616?connection.sendTimeout=1000";
 
     ActiveMQCPP::initializeLibrary();
-    ConnectionFactoryMgr::Initialize();
+    ConnectionFactoryMgr::initialize();
     int maxThreads = 30;
     int reservedThreads = 3;
-    Receiver::Initialize(reservedThreads, maxThreads);
+    Receiver::initialize(reservedThreads, maxThreads);
 
     std::vector<TestSenderAndReceiver*> sar;
     sar.resize(cnt);
@@ -68,7 +68,7 @@ int main(int argc, char** argv) {
         str << i;
         topic += str.str();
         sar[i] = new TestSenderAndReceiver(url, topic, true, false, 50, 1000);
-        sar[i]->init();
+        sar[i]->initialize();
     }
 
     Thread::sleep(done * 1000);
@@ -80,5 +80,10 @@ int main(int argc, char** argv) {
         delete sar[i];
     }
 
+    Receiver::unInitialize();
+    ConnectionFactoryMgr::unInitialize();
+
+    ActiveMQCPP::shutdownLibrary();
+
     printf("\nTest Completed!\n");
 }

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/examples/cmstemplate-stress/ConnectionFactoryMgr.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/examples/cmstemplate-stress/ConnectionFactoryMgr.cpp?rev=1419764&r1=1419763&r2=1419764&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/examples/cmstemplate-stress/ConnectionFactoryMgr.cpp
(original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/examples/cmstemplate-stress/ConnectionFactoryMgr.cpp
Mon Dec 10 21:01:37 2012
@@ -37,18 +37,18 @@ ConnectionFactoryMgr::ConnectionFactoryM
 ////////////////////////////////////////////////////////////////////////////////
 ConnectionFactoryMgr::~ConnectionFactoryMgr() {
     try {
-        UnInitialize();
+        unInitialize();
     } catch(...) {
     }
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-void ConnectionFactoryMgr::Initialize() {
+void ConnectionFactoryMgr::initialize() {
     connectionFactories = new StlMap<std::string, ConnectionFactory*>();
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-void ConnectionFactoryMgr::UnInitialize() {
+void ConnectionFactoryMgr::unInitialize() {
     connectionFactories->lock();
 
     Pointer<Iterator<ConnectionFactory*> > iter(connectionFactories->values().iterator());
@@ -68,7 +68,7 @@ void ConnectionFactoryMgr::UnInitialize(
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-ConnectionFactory* ConnectionFactoryMgr::GetConnectionFactory(const std::string& url)
{
+ConnectionFactory* ConnectionFactoryMgr::getConnectionFactory(const std::string& url)
{
     ConnectionFactory* connectionFactory = NULL;
 
     connectionFactories->lock();

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/examples/cmstemplate-stress/ConnectionFactoryMgr.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/examples/cmstemplate-stress/ConnectionFactoryMgr.h?rev=1419764&r1=1419763&r2=1419764&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/examples/cmstemplate-stress/ConnectionFactoryMgr.h
(original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/examples/cmstemplate-stress/ConnectionFactoryMgr.h
Mon Dec 10 21:01:37 2012
@@ -34,11 +34,11 @@ namespace cmstemplate {
 
     public:
 
-        static void Initialize();
+        static void initialize();
 
-        static void UnInitialize();
+        static void unInitialize();
 
-        static cms::ConnectionFactory* GetConnectionFactory(const std::string& url);
+        static cms::ConnectionFactory* getConnectionFactory(const std::string& url);
 
     };
 }

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/examples/cmstemplate-stress/MessagingTask.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/examples/cmstemplate-stress/MessagingTask.cpp?rev=1419764&r1=1419763&r2=1419764&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/examples/cmstemplate-stress/MessagingTask.cpp
(original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/examples/cmstemplate-stress/MessagingTask.cpp
Mon Dec 10 21:01:37 2012
@@ -32,7 +32,7 @@ MessagingTask::~MessagingTask() {
 void MessagingTask::run() {
     try {
         if (receiver != NULL) {
-            receiver->ExecuteMessagingTask(message);
+            receiver->executeMessagingTask(message);
         }
     } catch (...) {
     }

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=1419764&r1=1419763&r2=1419764&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 21:01:37 2012
@@ -52,8 +52,8 @@ Receiver::Receiver(const string & url, c
         cmsTemplateCreateTime(0),
         numOfMessagingTasks(0) {
 
-    ConnectionFactory* connectionFactory = ConnectionFactoryMgr::GetConnectionFactory(url);
-    cmsTemplate = new CmsTemplate(connectionFactory);
+    ConnectionFactory* connectionFactory = ConnectionFactoryMgr::getConnectionFactory(url);
+    cmsTemplate.reset(new CmsTemplate(connectionFactory));
     cmsTemplate->setDefaultDestinationName(queueOrTopicName);
     cmsTemplate->setPubSubDomain(isTopic);
     cmsTemplate->setReceiveTimeout(receiveTimeout);
@@ -65,34 +65,31 @@ Receiver::~Receiver() {
     try {
         closing = true;
 
-        //delete m_cmsTemplate
-        mutexForCmsTemplate.lock();
-        if (cmsTemplate) {
-            delete cmsTemplate;
-            cmsTemplate = NULL;
-        }
-        mutexForCmsTemplate.unlock();
-
-        //wait until all outstanding messaging tasks are done
+        // wait until all outstanding messaging tasks are done
         while (true) {
-            long numOfMessagingTasks = GetNumOfMessagingTasks();
+            long numOfMessagingTasks = getNumOfMessagingTasks();
             if (numOfMessagingTasks <= 0) {
                 break;
             }
             Thread::sleep(1000);
         }
+
+        if (asyncReceiverThread.get() != NULL) {
+            asyncReceiverThread->join();
+        }
+
     } catch (...) {
     }
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-void Receiver::Initialize(int reservedThreads, int maxThreads) {
+void Receiver::initialize(int reservedThreads, int maxThreads) {
     threadPoolExecutor = new ThreadPoolExecutor(reservedThreads, maxThreads, 5, TimeUnit::SECONDS,
new LinkedBlockingQueue<Runnable*>());
     threadPoolExecutor->prestartCoreThread();
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-void Receiver::UnInitialize() {
+void Receiver::unInitialize() {
     if (threadPoolExecutor != NULL) {
         try {
             threadPoolExecutor->shutdown();
@@ -105,7 +102,7 @@ void Receiver::UnInitialize() {
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-void Receiver::ReceiveMessage(std::string& message, ErrorCode& errorCode, bool retryOnError)
{
+void Receiver::receiveMessage(std::string& message, ErrorCode& errorCode, bool retryOnError)
{
     long long stopRetryTime = System::currentTimeMillis() + receiveTimeout;
     errorCode = CMS_SUCCESS;
 
@@ -128,7 +125,7 @@ void Receiver::ReceiveMessage(std::strin
         }
 
         mutexForCmsTemplate.lock();
-        if (cmsTemplate) {
+        if (cmsTemplate.get() != NULL) {
             cmsTemplate->setReceiveTimeout(timeoutForThisLoop);
 
             cms::Message* cmsMessage = NULL;
@@ -145,7 +142,7 @@ void Receiver::ReceiveMessage(std::strin
                 break;
             }
 
-            if (IsMessageExpired(cmsMessage)) {
+            if (isMessageExpired(cmsMessage)) {
                 errorCode = CMS_ERROR_INVALID_MESSAGE;
                 delete cmsMessage;
                 continue;
@@ -165,12 +162,12 @@ void Receiver::ReceiveMessage(std::strin
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-void Receiver::WaitUntilReady() {
+void Receiver::waitUntilReady() {
     ready.await();
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-void Receiver::RegisterMessageListener(ReceiverListener* messageListener, ErrorCode&
errorCode) {
+void Receiver::registerMessageListener(ReceiverListener* messageListener, ErrorCode&
errorCode) {
     errorCode = CMS_SUCCESS;
 
     mutexGeneral.lock();
@@ -188,11 +185,11 @@ void Receiver::RegisterMessageListener(R
 
     this->messageListener = messageListener;
 
-    asyncReceiverThread = new Thread(this, "AsyncReceiver");
+    asyncReceiverThread.reset(new Thread(this, "AsyncReceiver"));
     asyncReceiverThread->start();
     mutexGeneral.unlock();
 
-    this->WaitUntilReady();
+    this->waitUntilReady();
 }
 
 ////////////////////////////////////////////////////////////////////////////////
@@ -203,13 +200,13 @@ void Receiver::run() {
 
         ErrorCode errorCode = CMS_SUCCESS;
 
-        Receiver::ReceiveMessage(message, errorCode, false);
+        receiveMessage(message, errorCode, false);
         if (message != "") {
             if (bUseThreadPool) {
-                QueueMessagingTask(message);
+                queueMessagingTask(message);
             } else {
                 try {
-                    ExecuteMessagingTask(message, false);
+                    executeMessagingTask(message, false);
                 } catch (...) {
                 }
             }
@@ -226,16 +223,16 @@ void Receiver::run() {
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-void Receiver::QueueMessagingTask(const string& message) {
+void Receiver::queueMessagingTask(const string& message) {
     if (message != "" && (!closing)) {
         MessagingTask* task = new MessagingTask(this, message);
+        increaseNumOfMessagingTasks();
         threadPoolExecutor->execute(task);
-        IncreaseNumOfMessagingTasks();
     }
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-void Receiver::ExecuteMessagingTask(const string& message, bool bDecreaseNumOfMessagingTasks/*=true*/)
{
+void Receiver::executeMessagingTask(const string& message, bool bDecreaseNumOfMessagingTasks/*=true*/)
{
     if ((!closing)) {
         mutexGeneral.lock();
         ReceiverListener* copy = this->messageListener;
@@ -246,12 +243,12 @@ void Receiver::ExecuteMessagingTask(cons
     }
 
     if (bDecreaseNumOfMessagingTasks) {
-        DecreaseNumOfMessagingTasks();
+        decreaseNumOfMessagingTasks();
     }
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-bool Receiver::IsMessageExpired(cms::Message* message) {
+bool Receiver::isMessageExpired(cms::Message* message) {
     long long expireTime = message->getCMSExpiration();
     long long currentTime = System::currentTimeMillis();
     if (expireTime > 0 && currentTime > expireTime) {
@@ -261,21 +258,21 @@ bool Receiver::IsMessageExpired(cms::Mes
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-void Receiver::IncreaseNumOfMessagingTasks() {
+void Receiver::increaseNumOfMessagingTasks() {
     mutexGeneral.lock();
     numOfMessagingTasks++;
     mutexGeneral.unlock();
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-void Receiver::DecreaseNumOfMessagingTasks() {
+void Receiver::decreaseNumOfMessagingTasks() {
     mutexGeneral.lock();
     numOfMessagingTasks--;
     mutexGeneral.unlock();
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-long Receiver::GetNumOfMessagingTasks() {
+long Receiver::getNumOfMessagingTasks() {
     long numOfMessagingTasks = 0;
     mutexGeneral.lock();
     this->numOfMessagingTasks = numOfMessagingTasks;
@@ -284,6 +281,6 @@ long Receiver::GetNumOfMessagingTasks() 
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-void Receiver::Close() {
+void Receiver::close() {
     closing = true;
 }

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=1419764&r1=1419763&r2=1419764&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 21:01:37 2012
@@ -28,6 +28,7 @@
 
 #include <decaf/util/concurrent/TimeUnit.h>
 #include <string>
+#include <memory>
 
 namespace cmstemplate {
 
@@ -49,21 +50,24 @@ namespace cmstemplate {
         bool closing;
         decaf::util::concurrent::CountDownLatch ready;
         ReceiverListener* messageListener;
-        activemq::cmsutil::CmsTemplate* cmsTemplate;
-        decaf::lang::Thread* asyncReceiverThread;
+        std::auto_ptr<activemq::cmsutil::CmsTemplate> cmsTemplate;
+        std::auto_ptr<decaf::lang::Thread> asyncReceiverThread;
         long long receiveTimeout;
         bool bUseThreadPool;
         long long cmsTemplateCreateTime;
-        static decaf::util::concurrent::ThreadPoolExecutor* threadPoolExecutor;
         long numOfMessagingTasks;
 
     private:
 
-        virtual void WaitUntilReady();
+        static decaf::util::concurrent::ThreadPoolExecutor* threadPoolExecutor;
+
+    private:
+
+        virtual void waitUntilReady();
 
-        void IncreaseNumOfMessagingTasks();
-        void DecreaseNumOfMessagingTasks();
-        long GetNumOfMessagingTasks();
+        void increaseNumOfMessagingTasks();
+        void decreaseNumOfMessagingTasks();
+        long getNumOfMessagingTasks();
 
     private:
 
@@ -76,22 +80,22 @@ namespace cmstemplate {
 
         virtual ~Receiver();
 
-        static void Initialize(int reservedThreads, int maxThreads);
-        static void UnInitialize();
+        static void initialize(int reservedThreads, int maxThreads);
+        static void unInitialize();
 
-        void Close();
+        void close();
 
         virtual void run();
 
-        void RegisterMessageListener(ReceiverListener* messageListener, ErrorCode& errorCode);
+        void registerMessageListener(ReceiverListener* messageListener, ErrorCode& errorCode);
 
-        void ReceiveMessage(std::string& message, ErrorCode& errorCode, bool retryOnError
= true);
+        void receiveMessage(std::string& message, ErrorCode& errorCode, bool retryOnError
= true);
 
-        static bool IsMessageExpired(cms::Message* message);
+        static bool isMessageExpired(cms::Message* message);
 
-        void QueueMessagingTask(const std::string& message);
+        void queueMessagingTask(const std::string& message);
 
-        void ExecuteMessagingTask(const std::string& message, bool bDecreaseNumOfMessagingTasks
= true);
+        void executeMessagingTask(const std::string& message, bool bDecreaseNumOfMessagingTasks
= true);
 
     };
 }

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/examples/cmstemplate-stress/Sender.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/examples/cmstemplate-stress/Sender.cpp?rev=1419764&r1=1419763&r2=1419764&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/examples/cmstemplate-stress/Sender.cpp (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/examples/cmstemplate-stress/Sender.cpp Mon
Dec 10 21:01:37 2012
@@ -33,9 +33,9 @@ using namespace cmstemplate;
 Sender::Sender(const string& url, const string& queueOrTopicName, bool isTopic, bool
isDeliveryPersistent, int timeToLive) :
     cmsTemplateMutex(), cmsTemplate(NULL) {
 
-    ConnectionFactory* connectionFactory = ConnectionFactoryMgr::GetConnectionFactory(url);
+    ConnectionFactory* connectionFactory = ConnectionFactoryMgr::getConnectionFactory(url);
 
-    cmsTemplate = new CmsTemplate(connectionFactory);
+    cmsTemplate.reset(new CmsTemplate(connectionFactory));
     cmsTemplate->setExplicitQosEnabled(true);
     cmsTemplate->setDefaultDestinationName(queueOrTopicName);
     cmsTemplate->setPubSubDomain(isTopic);
@@ -47,10 +47,7 @@ Sender::Sender(const string& url, const 
 Sender::~Sender() {
     try {
         cmsTemplateMutex.lock();
-        if (cmsTemplate) {
-            delete cmsTemplate;
-            cmsTemplate = NULL;
-        }
+        cmsTemplate.reset(NULL);
         cmsTemplateMutex.unlock();
     } catch (...) {
     }

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/examples/cmstemplate-stress/Sender.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/examples/cmstemplate-stress/Sender.h?rev=1419764&r1=1419763&r2=1419764&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/examples/cmstemplate-stress/Sender.h (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/examples/cmstemplate-stress/Sender.h Mon
Dec 10 21:01:37 2012
@@ -31,7 +31,7 @@ namespace cmstemplate {
     private:
 
         decaf::util::concurrent::Mutex cmsTemplateMutex;
-        activemq::cmsutil::CmsTemplate* cmsTemplate;
+        std::auto_ptr<activemq::cmsutil::CmsTemplate> cmsTemplate;
 
     private:
 

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=1419764&r1=1419763&r2=1419764&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 21:01:37 2012
@@ -43,12 +43,14 @@ void TestSenderAndReceiver::onMessage(co
 ////////////////////////////////////////////////////////////////////////////////
 TestSenderAndReceiver::TestSenderAndReceiver(const string& url, const string& queueOrTopicName,
bool isTopic,
                                              bool isDeliveryPersistent, int timeToLive, int
receiveTimeout) :
-    sender(NULL), receiver(NULL), senderThread(NULL), closing(false), sendIndex(0), receiveIndex(0)
{
+    sender(), receiver(), senderThread(), closing(false), sendIndex(0), receiveIndex(0) {
+
+    sender.reset(new Sender(url, queueOrTopicName, isTopic, isDeliveryPersistent, timeToLive));
+    receiver.reset(new Receiver(url, queueOrTopicName, isTopic, receiveTimeout, true));
 
-    sender = new Sender(url, queueOrTopicName, isTopic, isDeliveryPersistent, timeToLive);
-    receiver = new Receiver(url, queueOrTopicName, isTopic, receiveTimeout, true);
     ErrorCode errorCode = CMS_SUCCESS;
-    receiver->RegisterMessageListener(this, errorCode);
+
+    receiver->registerMessageListener(this, errorCode);
 }
 
 ////////////////////////////////////////////////////////////////////////////////
@@ -59,8 +61,8 @@ TestSenderAndReceiver::~TestSenderAndRec
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-void TestSenderAndReceiver::init() {
-    senderThread = new Thread(this, "TestSenderAndReceiver");
+void TestSenderAndReceiver::initialize() {
+    senderThread.reset(new Thread(this, "TestSenderAndReceiver"));
     senderThread->start();
 }
 
@@ -105,22 +107,16 @@ void TestSenderAndReceiver::close() {
     if (!closing) {
         closing = true;
 
-        if (senderThread) {
-            senderThread->join();
-            delete senderThread;
-            senderThread = NULL;
-        }
-
         try {
-            delete sender;
-            sender = NULL;
-        } catch(Exception& ex) {}
+            if (senderThread.get() != NULL) {
+                senderThread->join();
+            }
+        } catch (Exception& ex) {}
 
         try {
-            receiver->Close();
-        } catch(Exception& ex) {}
-
-        delete receiver;
-        receiver = NULL;
+            if (receiver.get() != NULL) {
+                receiver->close();
+            }
+        } catch (Exception& ex) {}
     }
 }

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=1419764&r1=1419763&r2=1419764&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 21:01:37 2012
@@ -32,9 +32,9 @@ namespace cmstemplate {
                                   public ReceiverListener {
     private:
 
-        Sender* sender;
-        Receiver* receiver;
-        decaf::lang::Thread* senderThread;
+        std::auto_ptr<Sender> sender;
+        std::auto_ptr<Receiver> receiver;
+        std::auto_ptr<decaf::lang::Thread> senderThread;
         bool closing;
         int sendIndex;
         int receiveIndex;
@@ -51,7 +51,7 @@ namespace cmstemplate {
 
         virtual ~TestSenderAndReceiver();
 
-        void init();
+        void initialize();
 
         virtual void run();
 



Mime
View raw message