activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nmitt...@apache.org
Subject svn commit: r620176 - in /activemq/activemq-cpp/trunk/src/main/activemq/cmsutil: CmsTemplate.cpp CmsTemplate.h
Date Sat, 09 Feb 2008 19:23:23 GMT
Author: nmittler
Date: Sat Feb  9 11:23:23 2008
New Revision: 620176

URL: http://svn.apache.org/viewvc?rev=620176&view=rev
Log:
AMQCPP-152 - Adding addition execute methods for ProducerCallback

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

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=620176&r1=620175&r2=620176&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/activemq/cmsutil/CmsTemplate.cpp (original)
+++ activemq/activemq-cpp/trunk/src/main/activemq/cmsutil/CmsTemplate.cpp Sat Feb  9 11:23:23
2008
@@ -347,8 +347,39 @@
     
     try {
         
+        // Create the callback with using default destination.
+        ProducerExecutor cb(action, this, NULL);
+        
+        // Execute the action in a session.
+        execute(&cb);
+    }
+    AMQ_CATCH_RETHROW( ActiveMQException )
+    AMQ_CATCHALL_THROW( ActiveMQException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void CmsTemplate::execute(cms::Destination* dest,
+        ProducerCallback* action) throw (cms::CMSException) {
+    
+    try {
+        
+        // Create the callback.
+        ProducerExecutor cb(action, this, dest);
+        
+        // Execute the action in a session.
+        execute(&cb);
+    }
+    AMQ_CATCH_RETHROW( ActiveMQException )
+    AMQ_CATCHALL_THROW( ActiveMQException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void CmsTemplate::execute(const std::string& destinationName,
+        ProducerCallback* action) throw (cms::CMSException) {
+    
+    try {
         // Create the callback.
-        ProducerSessionCallback cb(action, this);
+        ResolveProducerExecutor cb(action, this, destinationName);
         
         // Execute the action in a session.
         execute(&cb);
@@ -358,7 +389,7 @@
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-void CmsTemplate::ProducerSessionCallback::doInCms( cms::Session* session ) 
+void CmsTemplate::ProducerExecutor::doInCms( cms::Session* session ) 
 throw (cms::CMSException) {
         
     cms::MessageProducer* producer = NULL;
@@ -370,7 +401,7 @@
         }
         
         // Create the producer.
-        producer = parent->createProducer(session, NULL);
+        producer = parent->createProducer(session, getDestination(session));
         
         // Execute the action.
         action->doInCms(session, producer);
@@ -390,6 +421,18 @@
 }
 
 ////////////////////////////////////////////////////////////////////////////////
+cms::Destination* CmsTemplate::ResolveProducerExecutor::getDestination(
+        cms::Session* session ) 
+    throw (cms::CMSException) {
+    
+    try {    
+        return parent->resolveDestinationName(session, destinationName);        
+    }
+    AMQ_CATCH_RETHROW( ActiveMQException )
+    AMQ_CATCHALL_THROW( ActiveMQException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
 void CmsTemplate::send(MessageCreator* messageCreator) 
 throw (cms::CMSException, IllegalStateException)  {
     
@@ -483,7 +526,7 @@
     try {
         cms::Destination* dest = parent->resolveDestinationName(session, destinationName);
         parent->doSend(session, dest, messageCreator);
-    } 
+    }
     AMQ_CATCH_RETHROW( ActiveMQException )
     AMQ_CATCH_EXCEPTION_CONVERT( IllegalStateException, ActiveMQException )
     AMQ_CATCHALL_THROW( ActiveMQException )

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=620176&r1=620175&r2=620176&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/activemq/cmsutil/CmsTemplate.h (original)
+++ activemq/activemq-cpp/trunk/src/main/activemq/cmsutil/CmsTemplate.h Sat Feb  9 11:23:23
2008
@@ -18,6 +18,7 @@
 #ifndef ACTIVEMQ_CMSUTIL_CMSTEMPLATE_H_
 #define ACTIVEMQ_CMSUTIL_CMSTEMPLATE_H_
 
+#include <activemq/util/Config.h>
 #include <activemq/cmsutil/CmsDestinationAccessor.h>
 #include <activemq/cmsutil/SessionCallback.h>
 #include <activemq/cmsutil/SessionPool.h>
@@ -87,25 +88,58 @@
         /**
          * Session callback that executes a producer callback.
          */
-        class ProducerSessionCallback;
-        friend class ProducerSessionCallback;
-        class ProducerSessionCallback : public SessionCallback {
-        private:
+        class ProducerExecutor;
+        friend class ProducerExecutor;
+        class ProducerExecutor : public SessionCallback {
+        protected:
             
             ProducerCallback* action;
             CmsTemplate* parent;
+            cms::Destination* destination;
             
         public:
             
-            ProducerSessionCallback(ProducerCallback* action,
-                    CmsTemplate* parent){
+            ProducerExecutor(ProducerCallback* action,
+                    CmsTemplate* parent, cms::Destination* destination){
                 this->action = action;
                 this->parent = parent;
+                this->destination = destination;
             }
             
-            virtual ~ProducerSessionCallback() {}
+            virtual ~ProducerExecutor() {}
             
             virtual void doInCms(cms::Session* session) throw (cms::CMSException);
+            
+            virtual cms::Destination* getDestination(cms::Session* session AMQCPP_UNUSED)

+                throw (cms::CMSException) {
+                return destination;
+            }
+        };
+        
+        /**
+         * Session callback that executes a producer callback for a named destination.
+         */
+        class ResolveProducerExecutor;
+        friend class ResolveProducerExecutor;
+        class ResolveProducerExecutor : public ProducerExecutor {
+        private:
+            
+            std::string destinationName;
+            
+        public:
+            
+            ResolveProducerExecutor(ProducerCallback* action,
+                    CmsTemplate* parent, const std::string& destinationName)
+            :
+                ProducerExecutor(action, parent, NULL) {
+                
+                this->destinationName = destinationName;
+            }
+            
+            virtual ~ResolveProducerExecutor() {}
+            
+            virtual cms::Destination* getDestination(cms::Session* session) 
+                throw (cms::CMSException) ;
         };
         
         /**
@@ -149,7 +183,7 @@
             CmsTemplate* parent;
             
         public:
-            
+                
             ResolveSender(const std::string& destinationName, 
                     MessageCreator* messageCreator,
                     CmsTemplate* parent ) {
@@ -420,6 +454,33 @@
          * @throws cms::CMSException thrown if an error occurs.
          */
         virtual void execute(ProducerCallback* action) throw (cms::CMSException);
+        
+        /**
+         * Executes the given action and provides it with a CMS Session and 
+         * producer
+         * 
+         * @param dest
+         *          the destination to send messages to
+         * @param action
+         *          the action to perform
+         * @throws cms::CMSException thrown if an error occurs.
+         */
+        virtual void execute(cms::Destination* dest,
+                ProducerCallback* action) throw (cms::CMSException);
+        
+        /**
+         * Executes the given action and provides it with a CMS Session and 
+         * producer
+         * 
+         * @param dest
+         *          the name of the destination to send messages to
+         *          (to internally be resolved to an actual destination)
+         * @param action
+         *          the action to perform
+         * @throws cms::CMSException thrown if an error occurs.
+         */
+        virtual void execute(const std::string& destinationName,
+                ProducerCallback* action) throw (cms::CMSException);
     
         /**
          * Convenience method for sending a message to the default destination.



Mime
View raw message