activemq-commits mailing list archives

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

URL: http://svn.apache.org/viewvc?rev=620177&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=620177&r1=620176&r2=620177&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:40:21
2008
@@ -437,14 +437,8 @@
 throw (cms::CMSException, IllegalStateException)  {
     
     try {
-        
-        checkDefaultDestination();
-        if (getDefaultDestination() != NULL) {
-            send(getDefaultDestination(), messageCreator);
-        }
-        else {
-            send(getDefaultDestinationName(), messageCreator);
-        }
+        SenderExecutor senderExecutor(messageCreator, this);
+        execute(&senderExecutor);
     }
     AMQ_CATCH_RETHROW( ActiveMQException )
     AMQ_CATCH_RETHROW( IllegalStateException )
@@ -456,9 +450,9 @@
                 MessageCreator* messageCreator) 
 throw (cms::CMSException, IllegalStateException) {
     
-    try {
-        Sender sender(dest, messageCreator, this);
-        execute(&sender);
+    try {        
+        SenderExecutor senderExecutor(messageCreator, this);
+        execute(dest, &senderExecutor);
     }
     AMQ_CATCH_RETHROW( ActiveMQException )
     AMQ_CATCHALL_THROW( ActiveMQException )
@@ -470,28 +464,24 @@
 throw (cms::CMSException, IllegalStateException) {
     
     try {
-        ResolveSender sender(destinationName, messageCreator, this);
-        execute(&sender);
+        SenderExecutor senderExecutor(messageCreator, this);
+        execute(destinationName, &senderExecutor);
     }
     AMQ_CATCH_RETHROW( ActiveMQException )
     AMQ_CATCHALL_THROW( ActiveMQException )
 }
         
 ////////////////////////////////////////////////////////////////////////////////
-void CmsTemplate::doSend(cms::Session* session, cms::Destination* dest, 
+void CmsTemplate::doSend(cms::Session* session, cms::MessageProducer* producer, 
         MessageCreator* messageCreator) throw (cms::CMSException) {
     
-    cms::MessageProducer* producer = NULL;
     cms::Message* message = NULL;
         
     try {
     
-        if( session == NULL || dest == NULL) {
+        if( producer == NULL ) {
             return;
-        }
-        
-        // Create the producer.
-        producer = createProducer(session, dest);
+        }        
         
         // Create the message.
         message = messageCreator->createMessage(session);
@@ -504,7 +494,6 @@
         }
         
         // Destroy the resources.
-        destroyProducer(producer);
         destroyMessage(message);
         
     } catch( ActiveMQException& e) {
@@ -512,23 +501,10 @@
         e.setMark(__FILE__, __LINE__ );
         
         // Destroy the resources.
-        destroyProducer(producer);
         destroyMessage(message);
         
         throw e;
     }
 }
 
-////////////////////////////////////////////////////////////////////////////////
-void CmsTemplate::ResolveSender::doInCms(cms::Session* session) 
-throw (cms::CMSException) {
-    
-    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=620177&r1=620176&r2=620177&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:40:21
2008
@@ -21,6 +21,7 @@
 #include <activemq/util/Config.h>
 #include <activemq/cmsutil/CmsDestinationAccessor.h>
 #include <activemq/cmsutil/SessionCallback.h>
+#include <activemq/cmsutil/ProducerCallback.h>
 #include <activemq/cmsutil/SessionPool.h>
 #include <decaf/lang/exceptions/IllegalStateException.h>
 #include <cms/ConnectionFactory.h>
@@ -31,7 +32,6 @@
 namespace cmsutil {
 
     // Forward declarations.
-    class ProducerCallback;
     class MessageCreator;
     
     /**
@@ -145,58 +145,30 @@
         /**
          * Session callback that sends to the given destination.
          */
-        class Sender;
-        friend class Sender;
-        class Sender : public SessionCallback {
+        class SenderExecutor;
+        friend class SenderExecutor;
+        class SenderExecutor : public ProducerCallback {
         private:
             
-            cms::Destination* dest;
             MessageCreator* messageCreator;
             CmsTemplate* parent;
             
         public:
             
-            Sender(cms::Destination* dest, MessageCreator* messageCreator,
+            SenderExecutor( MessageCreator* messageCreator,
                     CmsTemplate* parent) {
-                this->dest = dest;
                 this->messageCreator = messageCreator;
                 this->parent = parent;
             }
             
-            virtual ~Sender() {}
+            virtual ~SenderExecutor() {}
             
-            virtual void doInCms(cms::Session* session) throw (cms::CMSException) {
-                parent->doSend(session, dest, messageCreator);
+            virtual void doInCms(cms::Session* session,
+                    cms::MessageProducer* producer) throw (cms::CMSException) {
+                parent->doSend(session, producer, messageCreator);
             }
         };
         
-        /**
-         * Session callback that sends a message to a named destination.
-         */
-        class ResolveSender;
-        friend class ResolveSender;
-        class ResolveSender : public SessionCallback {
-        private:
-                    
-            std::string destinationName;
-            MessageCreator* messageCreator;
-            CmsTemplate* parent;
-            
-        public:
-                
-            ResolveSender(const std::string& destinationName, 
-                    MessageCreator* messageCreator,
-                    CmsTemplate* parent ) {
-                this->destinationName = destinationName;
-                this->messageCreator = messageCreator;
-                this->parent = parent;
-            }
-            
-            virtual ~ResolveSender() {}
-            
-            virtual void doInCms(cms::Session* session) throw (cms::CMSException);
-        };
-        
     private:
                 
         static const int NUM_SESSION_POOLS = (int)cms::Session::SESSION_TRANSACTED + 1;
@@ -629,14 +601,15 @@
         /**
          * Sends a message to a destination.
          * @param session
-         *          the session to be used.
-         * @param dest
-         *          the destination to send the message on.
+         *          the session
+         * @param producer
+         *          the producer to send to.
          * @param messageCreator
          *          creates the message to be sent
          * @throws cms::CMSException thrown if the CMS API throws.
          */
-        void doSend(cms::Session* session, cms::Destination* dest, 
+        void doSend(cms::Session* session,
+                cms::MessageProducer* producer, 
                 MessageCreator* messageCreator) throw (cms::CMSException);
         
         /**



Mime
View raw message