activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nmitt...@apache.org
Subject svn commit: r630644 - in /activemq/activemq-cpp/trunk/src: main/activemq/cmsutil/ test-integration/integration/connector/stomp/ test/activemq/cmsutil/
Date Sun, 24 Feb 2008 17:58:47 GMT
Author: nmittler
Date: Sun Feb 24 09:58:43 2008
New Revision: 630644

URL: http://svn.apache.org/viewvc?rev=630644&view=rev
Log:
AMQCPP-152 - Removing init and destroy from public interface of CmsTemplate

Modified:
    activemq/activemq-cpp/trunk/src/main/activemq/cmsutil/CmsAccessor.h
    activemq/activemq-cpp/trunk/src/main/activemq/cmsutil/CmsDestinationAccessor.cpp
    activemq/activemq-cpp/trunk/src/main/activemq/cmsutil/CmsDestinationAccessor.h
    activemq/activemq-cpp/trunk/src/main/activemq/cmsutil/CmsTemplate.cpp
    activemq/activemq-cpp/trunk/src/main/activemq/cmsutil/CmsTemplate.h
    activemq/activemq-cpp/trunk/src/main/activemq/cmsutil/DestinationResolver.h
    activemq/activemq-cpp/trunk/src/main/activemq/cmsutil/DynamicDestinationResolver.cpp
    activemq/activemq-cpp/trunk/src/main/activemq/cmsutil/DynamicDestinationResolver.h
    activemq/activemq-cpp/trunk/src/test-integration/integration/connector/stomp/CmsTemplateTest.cpp
    activemq/activemq-cpp/trunk/src/test-integration/integration/connector/stomp/CmsTemplateTest.h
    activemq/activemq-cpp/trunk/src/test/activemq/cmsutil/CmsDestinationAccessorTest.cpp
    activemq/activemq-cpp/trunk/src/test/activemq/cmsutil/CmsDestinationAccessorTest.h
    activemq/activemq-cpp/trunk/src/test/activemq/cmsutil/CmsTemplateTest.cpp
    activemq/activemq-cpp/trunk/src/test/activemq/cmsutil/DynamicDestinationResolverTest.cpp

Modified: activemq/activemq-cpp/trunk/src/main/activemq/cmsutil/CmsAccessor.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/activemq/cmsutil/CmsAccessor.h?rev=630644&r1=630643&r2=630644&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/activemq/cmsutil/CmsAccessor.h (original)
+++ activemq/activemq-cpp/trunk/src/main/activemq/cmsutil/CmsAccessor.h Sun Feb 24 09:58:43
2008
@@ -50,24 +50,7 @@
         
         CmsAccessor();
         
-        virtual ~CmsAccessor();
-        
-        /**
-         * Initializes this object and prepares it for use.  This should be called
-         * before any other methds are called.
-         */
-        virtual void init() 
-        throw (cms::CMSException, decaf::lang::exceptions::IllegalStateException) {
-            checkConnectionFactory();
-        }
-        
-        /**
-         * Shuts down this object and destroys any allocated resources.
-         */
-        virtual void destroy() 
-        throw (cms::CMSException, decaf::lang::exceptions::IllegalStateException) {
-            resourceLifecycleManager.destroy();
-        }
+        virtual ~CmsAccessor();                
         
         virtual ResourceLifecycleManager* getResourceLifecycleManager() {
             return &resourceLifecycleManager;
@@ -121,6 +104,22 @@
     
     protected:
     
+        /**
+         * Initializes this object and prepares it for use.  This should be called
+         * before any other methds are called.  This version does nothing.
+         */
+        virtual void init() 
+        throw (cms::CMSException, decaf::lang::exceptions::IllegalStateException) {
+        }
+        
+        /**
+         * Shuts down this object and destroys any allocated resources.
+         */
+        virtual void destroy() 
+        throw (cms::CMSException, decaf::lang::exceptions::IllegalStateException) {
+            resourceLifecycleManager.destroy();
+        }
+                
         /**
          * Create a CMS Connection via this template's ConnectionFactory.
          * @return the new CMS Connection

Modified: activemq/activemq-cpp/trunk/src/main/activemq/cmsutil/CmsDestinationAccessor.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/activemq/cmsutil/CmsDestinationAccessor.cpp?rev=630644&r1=630643&r2=630644&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/activemq/cmsutil/CmsDestinationAccessor.cpp (original)
+++ activemq/activemq-cpp/trunk/src/main/activemq/cmsutil/CmsDestinationAccessor.cpp Sun Feb
24 09:58:43 2008
@@ -38,25 +38,24 @@
 void CmsDestinationAccessor::init() 
 throw (cms::CMSException, IllegalStateException) {
     
-    // Invoke the base class.
     CmsAccessor::init();
     
     // Make sure we have a destination resolver.
     checkDestinationResolver();
     
     // Give the resolver our lifecycle manager.
-    destinationResolver->setResourceLifecycleManager(getResourceLifecycleManager()); 
  
+    destinationResolver->init(getResourceLifecycleManager());    
 }
 
 ////////////////////////////////////////////////////////////////////////////////
 void CmsDestinationAccessor::destroy() 
-throw (cms::CMSException, IllegalStateException) {
-        
-    // Invoke the base class.
-    CmsAccessor::destroy();
+throw (cms::CMSException, IllegalStateException) {        
+    
+    if( destinationResolver != NULL ) {
+        destinationResolver->destroy();
+    }   
     
-    // Reinitialize the destination resolver with the lifecycle manager.
-    destinationResolver->setResourceLifecycleManager(getResourceLifecycleManager()); 
+    CmsAccessor::destroy();
 }
   
 ////////////////////////////////////////////////////////////////////////////////

Modified: activemq/activemq-cpp/trunk/src/main/activemq/cmsutil/CmsDestinationAccessor.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/activemq/cmsutil/CmsDestinationAccessor.h?rev=630644&r1=630643&r2=630644&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/activemq/cmsutil/CmsDestinationAccessor.h (original)
+++ activemq/activemq-cpp/trunk/src/main/activemq/cmsutil/CmsDestinationAccessor.h Sun Feb
24 09:58:43 2008
@@ -54,17 +54,7 @@
         
         CmsDestinationAccessor();
         
-        virtual ~CmsDestinationAccessor();
-        
-        /**
-         * Initializes this object and prepares it for use.  This should be called
-         * before any other methds are called.
-         */
-        virtual void init() 
-        throw (cms::CMSException, decaf::lang::exceptions::IllegalStateException);
-        
-        virtual void destroy() 
-                throw (cms::CMSException, decaf::lang::exceptions::IllegalStateException);
+        virtual ~CmsDestinationAccessor();        
                 
         virtual bool isPubSubDomain() const {
             return this->pubSubDomain;
@@ -88,6 +78,18 @@
         
     protected:
         
+        /**
+         * Initializes the destination resolver.
+         */
+        virtual void init() 
+        throw (cms::CMSException, decaf::lang::exceptions::IllegalStateException);
+                
+        /**
+         * Calls destroy() on the destination resolver.
+         */
+        virtual void destroy() 
+        throw (cms::CMSException, decaf::lang::exceptions::IllegalStateException);
+                
         /**
          * Resolves the destination via the <code>DestinationResolver</code>.
          * @param session

Modified: activemq/activemq-cpp/trunk/src/main/activemq/cmsutil/CmsTemplate.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/activemq/cmsutil/CmsTemplate.cpp?rev=630644&r1=630643&r2=630644&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/activemq/cmsutil/CmsTemplate.cpp (original)
+++ activemq/activemq-cpp/trunk/src/main/activemq/cmsutil/CmsTemplate.cpp Sun Feb 24 09:58:43
2008
@@ -74,11 +74,14 @@
 ////////////////////////////////////////////////////////////////////////////////
 CmsTemplate::~CmsTemplate() {
     
-    destroySessionPools();
+    try {
+        destroy();
+    } catch( ... ) { /* Absorb */ }
 }
 
 ////////////////////////////////////////////////////////////////////////////////
 void CmsTemplate::initDefaults() {
+    initialized = false;
     defaultDestination = NULL;
     defaultDestinationName = "";
     messageIdEnabled = true;
@@ -134,11 +137,11 @@
 
     try {
         
-        // Invoke the base class.
-        CmsDestinationAccessor::init();
-    
-        // Make sure we have a valid default destination.
-        checkDefaultDestination();
+        if( !initialized ) {
+        
+            // Invoke the base class.
+            CmsDestinationAccessor::init();
+        }
     }
     CMSTEMPLATE_CATCH( ActiveMQException, this )
     CMSTEMPLATE_CATCH( IllegalStateException, this )
@@ -150,6 +153,9 @@
       
     try {
         
+        // Mark as not initialized.
+        initialized = false;
+        
         // Clear the connection reference
         connection = NULL;
         
@@ -160,7 +166,7 @@
         destroySessionPools();
                 
         // Call the base class.
-        CmsDestinationAccessor::destroy();
+        CmsDestinationAccessor::destroy();                
     }
     CMSTEMPLATE_CATCH( ActiveMQException, this )
     CMSTEMPLATE_CATCH( IllegalStateException, this )
@@ -399,6 +405,9 @@
             return;
         }
         
+        // Verify that we are initialized
+        init();
+        
         // Take a session from the pool.
         pooledSession = takeSession();
         
@@ -417,6 +426,9 @@
     
     try {
         
+        // Verify that we are initialized
+        init();
+        
         // Create the callback with using default destination.
         ProducerExecutor cb(action, this, NULL);
         
@@ -433,6 +445,9 @@
     
     try {
         
+        // Verify that we are initialized
+        init();
+        
         // Create the callback.
         ProducerExecutor cb(action, this, dest);
         
@@ -448,6 +463,10 @@
         ProducerCallback* action) throw (cms::CMSException) {
     
     try {
+        
+        // Verify that we are initialized
+        init();
+                
         // Create the callback.
         ResolveProducerExecutor cb(action, this, destinationName);
         

Modified: activemq/activemq-cpp/trunk/src/main/activemq/cmsutil/CmsTemplate.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/activemq/cmsutil/CmsTemplate.h?rev=630644&r1=630643&r2=630644&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/activemq/cmsutil/CmsTemplate.h (original)
+++ activemq/activemq-cpp/trunk/src/main/activemq/cmsutil/CmsTemplate.h Sun Feb 24 09:58:43
2008
@@ -265,26 +265,15 @@
         int priority;
     
         long long timeToLive;
+        
+        bool initialized;
     
     public:
     
         CmsTemplate();
         CmsTemplate(cms::ConnectionFactory* connectionFactory);
     
-        virtual ~CmsTemplate();
-    
-        /**
-         * Initializes this object and prepares it for use.  This should be called
-         * before any other methds are called.
-         */
-        virtual void init()
-        throw (cms::CMSException, decaf::lang::exceptions::IllegalStateException);
-    
-        /**
-         * Clears all internal resources.
-         */
-        virtual void destroy() 
-        throw (cms::CMSException, decaf::lang::exceptions::IllegalStateException);
+        virtual ~CmsTemplate();            
         
         /**
          * Sets the destination object to be used by default for send/receive operations.
@@ -637,6 +626,21 @@
                 const std::string& selector )
                 throw (cms::CMSException);
         
+    protected:
+        
+        /**
+         * Initializes this object and prepares it for use.  This should be called
+         * before any other methds are called.
+         */
+        void init()
+        throw (cms::CMSException, decaf::lang::exceptions::IllegalStateException);
+    
+        /**
+         * Clears all internal resources.
+         */
+        void destroy() 
+        throw (cms::CMSException, decaf::lang::exceptions::IllegalStateException);
+                
     private:
     
         /**

Modified: activemq/activemq-cpp/trunk/src/main/activemq/cmsutil/DestinationResolver.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/activemq/cmsutil/DestinationResolver.h?rev=630644&r1=630643&r2=630644&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/activemq/cmsutil/DestinationResolver.h (original)
+++ activemq/activemq-cpp/trunk/src/main/activemq/cmsutil/DestinationResolver.h Sun Feb 24
09:58:43 2008
@@ -35,13 +35,19 @@
         virtual ~DestinationResolver() {}
     
         /**
-         * Sets the <code>ResourceLifecycleManager</code> to be used for
-         * any allocated resources.
+         * Initializes this destination resolver for use.  Ensures that any 
+         * previously allocated resources are first destroyed 
+         * (e.g. calls destroy()).
          * 
          * @param mgr
          *      the resource lifecycle manager.
          */
-        virtual void setResourceLifecycleManager( ResourceLifecycleManager* mgr) = 0;
+        virtual void init( ResourceLifecycleManager* mgr) = 0;
+        
+        /**
+         * Destroys any allocated resources.
+         */
+        virtual void destroy() = 0;
         
         /**
          * Resolves the given name to a destination.  If 

Modified: activemq/activemq-cpp/trunk/src/main/activemq/cmsutil/DynamicDestinationResolver.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/activemq/cmsutil/DynamicDestinationResolver.cpp?rev=630644&r1=630643&r2=630644&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/activemq/cmsutil/DynamicDestinationResolver.cpp (original)
+++ activemq/activemq-cpp/trunk/src/main/activemq/cmsutil/DynamicDestinationResolver.cpp Sun
Feb 24 09:58:43 2008
@@ -75,11 +75,11 @@
 ////////////////////////////////////////////////////////////////////////////////
 DynamicDestinationResolver::~DynamicDestinationResolver() {
     
-    clear();
+    destroy();
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-void DynamicDestinationResolver::clear() {
+void DynamicDestinationResolver::destroy() {
     
     // Destroy the session resolvers.
     vector<SessionResolver*> r = sessionResolverMap.getValues();

Modified: activemq/activemq-cpp/trunk/src/main/activemq/cmsutil/DynamicDestinationResolver.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/activemq/cmsutil/DynamicDestinationResolver.h?rev=630644&r1=630643&r2=630644&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/activemq/cmsutil/DynamicDestinationResolver.h (original)
+++ activemq/activemq-cpp/trunk/src/main/activemq/cmsutil/DynamicDestinationResolver.h Sun
Feb 24 09:58:43 2008
@@ -71,28 +71,18 @@
         
     public:
     
-        virtual ~DynamicDestinationResolver();
-        
-        /**
-         * Clears the internal data structures.
-         */
-        void clear();
+        virtual ~DynamicDestinationResolver();        
     
-        /**
-         * Sets the <code>ResourceLifecycleManager</code> to be used for
-         * any allocated resources.
-         * 
-         * @param mgr
-         *      the resource lifecycle manager.
-         */
-        virtual void setResourceLifecycleManager( ResourceLifecycleManager* mgr) {
+        virtual void init( ResourceLifecycleManager* mgr) {
             
             // since we're changing the lifecycle manager, clear out references
             // to old resources.
-            clear();
+            destroy();
             
             this->resourceLifecycleManager = mgr;
         }
+        
+        virtual void destroy();
                 
         /**
          * Resolves the given name to a destination.  If 

Modified: activemq/activemq-cpp/trunk/src/test-integration/integration/connector/stomp/CmsTemplateTest.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/test-integration/integration/connector/stomp/CmsTemplateTest.cpp?rev=630644&r1=630643&r2=630644&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/src/test-integration/integration/connector/stomp/CmsTemplateTest.cpp
(original)
+++ activemq/activemq-cpp/trunk/src/test-integration/integration/connector/stomp/CmsTemplateTest.cpp
Sun Feb 24 09:58:43 2008
@@ -121,7 +121,6 @@
     activemq::core::ActiveMQConnectionFactory cf("tcp://localhost:61666"); // Invalid URL
(at least by default)
     activemq::cmsutil::CmsTemplate cmsTemplate(&cf);
     cmsTemplate.setDefaultDestinationName("hello");
-    cmsTemplate.init();            
     try {                
         cmsTemplate.receive();
         CPPUNIT_FAIL("failed to throw expected exception");
@@ -156,7 +155,6 @@
     activemq::core::ActiveMQConnectionFactory cf("tcp://localhost:61666"); // Invalid URL
(at least by default)
     activemq::cmsutil::CmsTemplate cmsTemplate(&cf);
     cmsTemplate.setDefaultDestinationName("hello");
-    cmsTemplate.init();
     try {                      
         TextMessageCreator msgCreator("hello world");
         cmsTemplate.send(&msgCreator);

Modified: activemq/activemq-cpp/trunk/src/test-integration/integration/connector/stomp/CmsTemplateTest.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/test-integration/integration/connector/stomp/CmsTemplateTest.h?rev=630644&r1=630643&r2=630644&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/src/test-integration/integration/connector/stomp/CmsTemplateTest.h
(original)
+++ activemq/activemq-cpp/trunk/src/test-integration/integration/connector/stomp/CmsTemplateTest.h
Sun Feb 24 09:58:43 2008
@@ -71,11 +71,9 @@
                 cmsTemplate.setConnectionFactory(&cf);
                 cmsTemplate.setPubSubDomain(pubSub);
                 cmsTemplate.setDefaultDestinationName(destName);
-                cmsTemplate.init();
                 this->count = count;
             }
             virtual ~Sender(){
-                cmsTemplate.destroy();
             }
             virtual void run() {                
                 try {
@@ -107,11 +105,9 @@
                 cmsTemplate.setConnectionFactory(&cf);
                 cmsTemplate.setPubSubDomain(pubSub);
                 cmsTemplate.setDefaultDestinationName(destName);
-                cmsTemplate.init();
                 this->count = count;
             }
             virtual ~Receiver(){
-                cmsTemplate.destroy();
             }
             int getNumReceived() const {
                 return numReceived;

Modified: activemq/activemq-cpp/trunk/src/test/activemq/cmsutil/CmsDestinationAccessorTest.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/test/activemq/cmsutil/CmsDestinationAccessorTest.cpp?rev=630644&r1=630643&r2=630644&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/src/test/activemq/cmsutil/CmsDestinationAccessorTest.cpp (original)
+++ activemq/activemq-cpp/trunk/src/test/activemq/cmsutil/CmsDestinationAccessorTest.cpp Sun
Feb 24 09:58:43 2008
@@ -35,7 +35,6 @@
 
 ////////////////////////////////////////////////////////////////////////////////
 void CmsDestinationAccessorTest::tearDown() {
-    accessor->destroy();
     delete accessor;
     delete cf;
 }

Modified: activemq/activemq-cpp/trunk/src/test/activemq/cmsutil/CmsDestinationAccessorTest.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/test/activemq/cmsutil/CmsDestinationAccessorTest.h?rev=630644&r1=630643&r2=630644&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/src/test/activemq/cmsutil/CmsDestinationAccessorTest.h (original)
+++ activemq/activemq-cpp/trunk/src/test/activemq/cmsutil/CmsDestinationAccessorTest.h Sun
Feb 24 09:58:43 2008
@@ -39,7 +39,12 @@
         
         public:
             
-            virtual ~MyAccessor(){}
+            virtual ~MyAccessor(){
+                try {
+                    destroy();
+                } catch( ... ) {                    
+                }
+            }
             
             virtual cms::Connection* createConnection() throw (cms::CMSException) {
                 return CmsDestinationAccessor::createConnection();
@@ -53,6 +58,14 @@
                 cms::Session* session, 
                 const std::string& destName ) throw (cms::CMSException) {
                 return CmsDestinationAccessor::resolveDestinationName(session,destName);
+            }
+            virtual void init() 
+            throw (cms::CMSException, decaf::lang::exceptions::IllegalStateException) {
+                CmsDestinationAccessor::init();
+            }
+            virtual void destroy() 
+            throw (cms::CMSException, decaf::lang::exceptions::IllegalStateException) {
+                CmsDestinationAccessor::destroy();
             }
         };
         

Modified: activemq/activemq-cpp/trunk/src/test/activemq/cmsutil/CmsTemplateTest.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/test/activemq/cmsutil/CmsTemplateTest.cpp?rev=630644&r1=630643&r2=630644&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/src/test/activemq/cmsutil/CmsTemplateTest.cpp (original)
+++ activemq/activemq-cpp/trunk/src/test/activemq/cmsutil/CmsTemplateTest.cpp Sun Feb 24 09:58:43
2008
@@ -31,12 +31,10 @@
     cf = new DummyConnectionFactory();
     cmsTemplate = new CmsTemplate(cf);
     cmsTemplate->setDefaultDestinationName("test");
-    cmsTemplate->init();
 }
 
 ////////////////////////////////////////////////////////////////////////////////
 void CmsTemplateTest::tearDown() {
-    cmsTemplate->destroy();
     delete cmsTemplate;
     delete cf;
 }
@@ -105,6 +103,9 @@
         CPPUNIT_ASSERT(callback4.session == callback.session);
         CPPUNIT_ASSERT(callback4.producer != callback3.producer);
         
+        std::cout << "before exception" << std::endl;
+        std::cout.flush();
+        
         // Now try without a valid default destination and make sure
         // we get an exception.
         try {
@@ -115,6 +116,9 @@
         } catch( cms::CMSException& ex) {
             // expected.
         }
+        
+        std::cout << "after exception" << std::endl;
+        std::cout.flush();
         
         // Now try an explicit destination 
         MyProducerCallback callback6;

Modified: activemq/activemq-cpp/trunk/src/test/activemq/cmsutil/DynamicDestinationResolverTest.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/test/activemq/cmsutil/DynamicDestinationResolverTest.cpp?rev=630644&r1=630643&r2=630644&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/src/test/activemq/cmsutil/DynamicDestinationResolverTest.cpp
(original)
+++ activemq/activemq-cpp/trunk/src/test/activemq/cmsutil/DynamicDestinationResolverTest.cpp
Sun Feb 24 09:58:43 2008
@@ -30,7 +30,7 @@
 
     ResourceLifecycleManager mgr;    
     DynamicDestinationResolver resolver;
-    resolver.setResourceLifecycleManager(&mgr);
+    resolver.init(&mgr);
     
     DummySession session(NULL);
     
@@ -62,7 +62,7 @@
 
     ResourceLifecycleManager mgr;    
     DynamicDestinationResolver resolver;
-    resolver.setResourceLifecycleManager(&mgr);
+    resolver.init(&mgr);
     
     DummySession session(NULL);
     



Mime
View raw message