activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject svn commit: r915792 - in /activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/cmsutil: ResourceLifecycleManager.cpp ResourceLifecycleManager.h
Date Wed, 24 Feb 2010 13:45:33 GMT
Author: tabish
Date: Wed Feb 24 13:45:33 2010
New Revision: 915792

URL: http://svn.apache.org/viewvc?rev=915792&view=rev
Log:
Apply patch for: https://issues.apache.org/activemq/browse/AMQCPP-288

Modified:
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/cmsutil/ResourceLifecycleManager.cpp
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/cmsutil/ResourceLifecycleManager.h

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/cmsutil/ResourceLifecycleManager.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/cmsutil/ResourceLifecycleManager.cpp?rev=915792&r1=915791&r2=915792&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/cmsutil/ResourceLifecycleManager.cpp
(original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/cmsutil/ResourceLifecycleManager.cpp
Wed Feb 24 13:45:33 2010
@@ -17,6 +17,9 @@
 
 #include "ResourceLifecycleManager.h"
 
+#include <activemq/exceptions/ActiveMQException.h>
+#include <activemq/util/CMSExceptionSupport.h>
+
 using namespace activemq::cmsutil;
 
 ////////////////////////////////////////////////////////////////////////////////
@@ -30,8 +33,8 @@
 
         // Destroy all the resources
         destroy();
-
-    } catch( cms::CMSException& e ) { /* Absorb*/ }
+    }
+    AMQ_CATCHALL_NOTHROW()
 }
 
 ////////////////////////////////////////////////////////////////////////////////
@@ -47,48 +50,140 @@
 ////////////////////////////////////////////////////////////////////////////////
 void ResourceLifecycleManager::destroy() throw ( cms::CMSException ) {
 
-    // Close all the connections.
-    for (std::size_t ix=0; ix<connections.size(); ++ix) {
-        try {
-            connections[ix]->close();
-        } catch(...){}
-    }
+    try{
+        // Close all the connections.
+        std::auto_ptr< decaf::util::Iterator< cms::Connection* > > connIter(
+            connections.iterator() );
+
+        while( connIter->hasNext() ) {
+            cms::Connection* conn = connIter->next();
+            try {
+                conn->close();
+            } catch(...){}
+        }
+
+        // Destroy the producers.
+        std::auto_ptr< decaf::util::Iterator< cms::MessageProducer* > > prodIter(
+            producers.iterator() );
+
+        while( prodIter->hasNext() ) {
+            cms::MessageProducer* producer = prodIter->next();
+            try {
+                delete producer;
+            } catch( ... ) {}
+        }
+
+        // Destroy the consumers.
+        std::auto_ptr< decaf::util::Iterator< cms::MessageConsumer* > > consIter(
+            consumers.iterator() );
+
+        while( consIter->hasNext() ) {
+            cms::MessageConsumer* consumer = consIter->next();
+            try {
+                delete consumer;
+            } catch( ... ) {}
+        }
+
+        // Destroy the destinations.
+        std::auto_ptr< decaf::util::Iterator< cms::Destination* > > destIter(
+            destinations.iterator() );
+
+        while( destIter->hasNext() ) {
+            cms::Destination* dest = destIter->next();
+            try {
+                delete dest;
+            } catch( ... ) {}
+        }
+
+        // Destroy the sessions.
+        std::auto_ptr< decaf::util::Iterator< cms::Session* > > sessIter(
+            sessions.iterator() );
+
+        while( sessIter->hasNext() ) {
+            cms::Session* session = sessIter->next();
+            try {
+                delete session;
+            } catch( ... ) {}
+        }
+
+        // Destroy the connections,
+        connIter.reset( connections.iterator() );
+
+        while( connIter->hasNext() ) {
+            cms::Connection* conn = connIter->next();
+            try {
+                delete conn;
+            } catch( ... ) {}
+        }
 
-    // Destroy the producers.
-    for (std::size_t ix=0; ix<producers.size(); ++ix) {
-        try {
-            delete producers[ix];
-        } catch( ... ) {}
+        // Empty all the lists.
+        releaseAll();
     }
+    AMQ_CATCH_ALL_THROW_CMSEXCEPTION()
+}
 
-    // Destroy the consumers.
-    for (std::size_t ix=0; ix<consumers.size(); ++ix) {
-        try {
-            delete consumers[ix];
-        } catch( ... ) {}
+////////////////////////////////////////////////////////////////////////////////
+void ResourceLifecycleManager::addConnection( cms::Connection* connection )
+    throw ( cms::CMSException ) {
+
+    try{
+        // Add the connection to the list.
+        synchronized( &connections ) {
+            connections.add( connection );
+        }
     }
+    AMQ_CATCH_ALL_THROW_CMSEXCEPTION()
+}
 
-    // Destroy the destinations.
-    for (std::size_t ix=0; ix<destinations.size(); ++ix) {
-        try {
-            delete destinations[ix];
-        } catch( ... ) {}
+////////////////////////////////////////////////////////////////////////////////
+void ResourceLifecycleManager::addSession( cms::Session* session )
+    throw ( cms::CMSException ) {
+
+    try{
+        // Add the session to the list.
+        synchronized( &sessions ) {
+            sessions.add( session );
+        }
     }
+    AMQ_CATCH_ALL_THROW_CMSEXCEPTION()
+}
 
-    // Destroy the sessions.
-    for (std::size_t ix=0; ix<sessions.size(); ++ix) {
-        try {
-            delete sessions[ix];
-        } catch( ... ) {}
+
+////////////////////////////////////////////////////////////////////////////////
+void ResourceLifecycleManager::addDestination( cms::Destination* dest )
+    throw ( cms::CMSException ) {
+
+    try{
+        // Add the destination to the list.
+        synchronized( &destinations ) {
+            destinations.add( dest );
+        }
     }
+    AMQ_CATCH_ALL_THROW_CMSEXCEPTION()
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ResourceLifecycleManager::addMessageProducer( cms::MessageProducer* producer )
+    throw ( cms::CMSException ) {
 
-    // Destroy the connections,
-    for (std::size_t ix=0; ix<connections.size(); ++ix) {
-        try {
-            delete connections[ix];
-        } catch( ... ) {}
+    try{
+        // Add the producer to the list.
+        synchronized( &producers ) {
+            producers.add( producer );
+        }
     }
+    AMQ_CATCH_ALL_THROW_CMSEXCEPTION()
+}
 
-    // Empty all the vectors.
-    releaseAll();
+////////////////////////////////////////////////////////////////////////////////
+void ResourceLifecycleManager::addMessageConsumer( cms::MessageConsumer* consumer )
+    throw ( cms::CMSException ) {
+
+    try{
+        // Add the consumer to the list.
+        synchronized( &consumers ) {
+            consumers.add( consumer );
+        }
+    }
+    AMQ_CATCH_ALL_THROW_CMSEXCEPTION()
 }

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/cmsutil/ResourceLifecycleManager.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/cmsutil/ResourceLifecycleManager.h?rev=915792&r1=915791&r2=915792&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/cmsutil/ResourceLifecycleManager.h
(original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/cmsutil/ResourceLifecycleManager.h
Wed Feb 24 13:45:33 2010
@@ -24,6 +24,7 @@
 #include <cms/MessageProducer.h>
 #include <cms/MessageConsumer.h>
 #include <activemq/util/Config.h>
+#include <decaf/util/StlList.h>
 
 namespace activemq {
 namespace cmsutil {
@@ -36,11 +37,17 @@
     class AMQCPP_API ResourceLifecycleManager {
     private:
 
-        std::vector<cms::Connection*> connections;
-        std::vector<cms::Session*> sessions;
-        std::vector<cms::Destination*> destinations;
-        std::vector<cms::MessageProducer*> producers;
-        std::vector<cms::MessageConsumer*> consumers;
+        typedef decaf::util::StlList< cms::Connection* > ConnectionList;
+        typedef decaf::util::StlList< cms::Session* > SessionList;
+        typedef decaf::util::StlList< cms::Destination* > DestinationList;
+        typedef decaf::util::StlList< cms::MessageProducer* > ProducerList;
+        typedef decaf::util::StlList< cms::MessageConsumer* > ConsumerList;
+
+        ConnectionList connections;
+        SessionList sessions;
+        DestinationList destinations;
+        ProducerList producers;
+        ConsumerList consumers;
 
     public:
 
@@ -58,9 +65,8 @@
          * @param connection
          *         the object to be managed
          */
-        void addConnection( cms::Connection* connection ) {
-            connections.push_back( connection );
-        }
+        void addConnection( cms::Connection* connection )
+            throw ( cms::CMSException );
 
         /**
          * Adds a session so that its life will be managed by
@@ -69,9 +75,8 @@
          * @param session
          *         the object to be managed
          */
-        void addSession( cms::Session* session ) {
-            sessions.push_back( session );
-        }
+        void addSession( cms::Session* session )
+            throw ( cms::CMSException );
 
         /**
          * Adds a destination so that its life will be managed by
@@ -80,9 +85,8 @@
          * @param dest
          *         the object to be managed
          */
-        void addDestination( cms::Destination* dest ) {
-            destinations.push_back( dest );
-        }
+        void addDestination( cms::Destination* dest )
+            throw ( cms::CMSException );
 
         /**
          * Adds a message producer so that its life will be managed by
@@ -91,9 +95,8 @@
          * @param producer
          *         the object to be managed
          */
-        void addMessageProducer( cms::MessageProducer* producer ) {
-            producers.push_back( producer );
-        }
+        void addMessageProducer( cms::MessageProducer* producer )
+            throw ( cms::CMSException );
 
         /**
          * Adds a message consumer so that its life will be managed by
@@ -102,9 +105,8 @@
          * @param consumer
          *         the object to be managed
          */
-        void addMessageConsumer( cms::MessageConsumer* consumer ) {
-            consumers.push_back( consumer );
-        }
+        void addMessageConsumer( cms::MessageConsumer* consumer )
+            throw ( cms::CMSException );
 
         /**
          * Closes and destroys the contained CMS resources.



Mime
View raw message