activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nmitt...@apache.org
Subject svn commit: r609364 - in /activemq/activemq-cpp/trunk/src/main/activemq/cmsutil: CmsAccessor.cpp CmsAccessor.h CmsDestinationAccessor.cpp CmsDestinationAccessor.h CmsTemplate.cpp CmsTemplate.h
Date Sun, 06 Jan 2008 18:18:22 GMT
Author: nmittler
Date: Sun Jan  6 10:18:20 2008
New Revision: 609364

URL: http://svn.apache.org/viewvc?rev=609364&view=rev
Log:
AMQCPP-152 - Adding classes for support of CmsTemplate

Added:
    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/CmsAccessor.cpp
    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

Modified: activemq/activemq-cpp/trunk/src/main/activemq/cmsutil/CmsAccessor.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/activemq/cmsutil/CmsAccessor.cpp?rev=609364&r1=609363&r2=609364&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/activemq/cmsutil/CmsAccessor.cpp (original)
+++ activemq/activemq-cpp/trunk/src/main/activemq/cmsutil/CmsAccessor.cpp Sun Jan  6 10:18:20
2008
@@ -18,6 +18,7 @@
 #include "CmsAccessor.h"
 
 using namespace activemq::cmsutil;
+using namespace decaf::lang::exceptions;
 
 ////////////////////////////////////////////////////////////////////////////////
 CmsAccessor::CmsAccessor() {
@@ -29,7 +30,10 @@
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-cms::Connection* CmsAccessor::createConnection() throw (cms::CMSException) {
+cms::Connection* CmsAccessor::createConnection() 
+throw (cms::CMSException,IllegalStateException) {
+    
+    checkConnectionFactory();
     
     // Create the connection.
     cms::Connection* c = getConnectionFactory()->createConnection();
@@ -42,7 +46,7 @@
 
 ////////////////////////////////////////////////////////////////////////////////
 cms::Session* CmsAccessor::createSession(cms::Connection* con) 
-    throw (cms::CMSException) {
+throw (cms::CMSException,IllegalStateException) {
     
     // Create the session.
     cms::Session* s = con->createSession(getSessionAcknowledgeMode());
@@ -52,3 +56,13 @@
     
     return s;
 }
+
+////////////////////////////////////////////////////////////////////////////////
+void CmsAccessor::checkConnectionFactory() throw (IllegalStateException) {
+    if (getConnectionFactory() == NULL) {
+            throw IllegalStateException(
+                    __FILE__, __LINE__,
+                    "Property 'connectionFactory' is required");
+    }
+}
+

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=609364&r1=609363&r2=609364&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/activemq/cmsutil/CmsAccessor.h (original)
+++ activemq/activemq-cpp/trunk/src/main/activemq/cmsutil/CmsAccessor.h Sun Jan  6 10:18:20
2008
@@ -19,6 +19,7 @@
 
 #include <cms/ConnectionFactory.h>
 #include <activemq/cmsutil/ResourceLifecycleManager.h>
+#include <decaf/lang/exceptions/IllegalStateException.h>
 
 namespace activemq {
 namespace cmsutil {
@@ -55,7 +56,8 @@
          * Initializes this object and prepares it for use.  This should be called
          * before any other methds are called.
          */
-        virtual void init() throw (cms::CMSException) {            
+        virtual void init() throw (cms::CMSException, decaf::lang::exceptions::IllegalStateException)
{
+            checkConnectionFactory();
         }
         
         /**
@@ -122,7 +124,8 @@
          * @return the new CMS Connection
          * @throws cms::CMSException if thrown by CMS API methods
          */
-        virtual cms::Connection* createConnection() throw (cms::CMSException);
+        virtual cms::Connection* createConnection() 
+            throw (cms::CMSException, decaf::lang::exceptions::IllegalStateException);
     
         /**
          * Create a CMS Session for the given Connection.
@@ -131,7 +134,12 @@
          * @throws cms::CMSException if thrown by CMS API methods
          */
         virtual cms::Session* createSession(cms::Connection* con) 
-            throw (cms::CMSException);
+            throw (cms::CMSException, decaf::lang::exceptions::IllegalStateException);
+        
+        /**
+         * Verifies that the connection factory is valid.
+         */
+        virtual void checkConnectionFactory() throw (decaf::lang::exceptions::IllegalStateException);
     
     };
 

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=609364&r1=609363&r2=609364&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/activemq/cmsutil/CmsDestinationAccessor.cpp (original)
+++ activemq/activemq-cpp/trunk/src/main/activemq/cmsutil/CmsDestinationAccessor.cpp Sun Jan
 6 10:18:20 2008
@@ -18,6 +18,7 @@
 #include "CmsDestinationAccessor.h"
 
 using namespace activemq::cmsutil;
+using namespace decaf::lang::exceptions;
 
 ////////////////////////////////////////////////////////////////////////////////
 CmsDestinationAccessor::CmsDestinationAccessor() {
@@ -35,23 +36,37 @@
 
 ////////////////////////////////////////////////////////////////////////////////
 void CmsDestinationAccessor::init() throw (cms::CMSException) {
-    setDestinationResolver(destinationResolver);
-}
-
-////////////////////////////////////////////////////////////////////////////////
-void CmsDestinationAccessor::setDestinationResolver( DestinationResolver* destRes ) {
-    this->destinationResolver = destRes; 
-    destRes->setResourceLifecycleManager(getResourceLifecycleManager());
+    
+    // Invoke the base class.
+    CmsAccessor::init();
+    
+    // Make sure we have a destination resolver.
+    checkDestinationResolver();
+    
+    // Give the resolver our lifecycle manager.
+    destinationResolver->setResourceLifecycleManager(getResourceLifecycleManager()); 
  
 }
   
 ////////////////////////////////////////////////////////////////////////////////
 cms::Destination* CmsDestinationAccessor::resolveDestinationName( 
     cms::Session* session, 
-    const std::string& destName ) throw (cms::CMSException) {
+    const std::string& destName ) 
+throw (cms::CMSException, IllegalStateException) {
+    
+    checkDestinationResolver();
     
     getDestinationResolver()->resolveDestinationName(session, 
             destName, 
             isPubSubDomain());
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void CmsDestinationAccessor::checkDestinationResolver() throw (IllegalStateException) {
+    if (getDestinationResolver() == NULL) {
+            throw IllegalStateException(
+                    __FILE__, __LINE__,
+                    "Property 'destinationResolver' is required");
+    }
 }
 
 

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=609364&r1=609363&r2=609364&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/activemq/cmsutil/CmsDestinationAccessor.h (original)
+++ activemq/activemq-cpp/trunk/src/main/activemq/cmsutil/CmsDestinationAccessor.h Sun Jan
 6 10:18:20 2008
@@ -78,7 +78,9 @@
             return destinationResolver;
         }
         
-        virtual void setDestinationResolver( DestinationResolver* destRes );
+        virtual void setDestinationResolver( DestinationResolver* destRes ) {
+            this->destinationResolver = destRes;     
+        }
         
     protected:
         
@@ -90,10 +92,18 @@
          *      the name of the destination.
          * @return the destination
          * @throws cms::CMSException if resolution failed.
+         * @throws decaf::lang::exceptions::IllegalStateException if the destiation
+         *      resolver property is NULL.
          */
         virtual cms::Destination* resolveDestinationName( 
                 cms::Session* session, 
-                const std::string& destName ) throw (cms::CMSException);
+                const std::string& destName ) 
+                throw (cms::CMSException, decaf::lang::exceptions::IllegalStateException);
+        
+        /**
+         * Verifies that the connection factory is valid.
+         */
+        virtual void checkDestinationResolver() throw (decaf::lang::exceptions::IllegalStateException);
     };
 
 }}

Added: 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=609364&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/activemq/cmsutil/CmsTemplate.cpp (added)
+++ activemq/activemq-cpp/trunk/src/main/activemq/cmsutil/CmsTemplate.cpp Sun Jan  6 10:18:20
2008
@@ -0,0 +1,60 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "CmsTemplate.h"
+
+using namespace activemq::cmsutil;
+using namespace decaf::lang::exceptions;
+
+////////////////////////////////////////////////////////////////////////////////
+CmsTemplate::CmsTemplate() {
+    initDefaults();
+}
+
+////////////////////////////////////////////////////////////////////////////////
+CmsTemplate::CmsTemplate(cms::ConnectionFactory* connectionFactory) {
+    initDefaults();
+    setConnectionFactory(connectionFactory);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+CmsTemplate::~CmsTemplate() {
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void CmsTemplate::initDefaults() {
+    defaultDestination = NULL;
+    defaultDestinationName = "";
+    messageIdEnabled = true;
+    messageTimestampEnabled = true;
+    pubSubNoLocal = false;
+    receiveTimeout = RECEIVE_TIMEOUT_INDEFINITE_WAIT;
+    explicitQosEnabled = false;
+    deliveryMode = cms::DeliveryMode::PERSISTENT;
+    priority = DEFAULT_PRIORITY;
+    timeToLive = DEFAULT_TIME_TO_LIVE;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void CmsTemplate::checkDefaultDestination() throw (IllegalStateException) {
+    if (this->defaultDestination == NULL) {
+        throw IllegalStateException(
+                __FILE__, __LINE__,
+                "No defaultDestination or defaultDestinationName specified. Check configuration
of CmsTemplate.");
+    }
+}
+

Added: 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=609364&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/activemq/cmsutil/CmsTemplate.h (added)
+++ activemq/activemq-cpp/trunk/src/main/activemq/cmsutil/CmsTemplate.h Sun Jan  6 10:18:20
2008
@@ -0,0 +1,237 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef ACTIVEMQ_CMSUTIL_CMSTEMPLATE_H_
+#define ACTIVEMQ_CMSUTIL_CMSTEMPLATE_H_
+
+#include <activemq/cms/CmsDestinationAccessor.h>
+#include <decaf/lang/exceptions/IllegalStateException.h>
+#include <cms/ConnectionFactory.h>
+#include <cms/DeliveryMode.h>
+#include <string>
+
+namespace activemq {
+namespace cmsutil {
+
+    class CmsTemplate : public CmsDestinationAccessor
+    {
+    public:
+        
+        /**
+         * Timeout value indicating that a receive operation should
+         * check if a message is immediately available without blocking.
+         */
+        static const long long RECEIVE_TIMEOUT_NO_WAIT = -1;
+
+        /**
+         * Timeout value indicating a blocking receive without timeout.
+         */
+        static const long long RECEIVE_TIMEOUT_INDEFINITE_WAIT = 0;
+        
+        /**
+         * Default message priority.
+         */
+        static const int DEFAULT_PRIORITY = 4;
+        
+        /**
+         * My default, messages should live forever.
+         */
+        static const long long DEFAULT_TIME_TO_LIVE = 0;
+        
+    private:                
+        
+        cms::Destination* defaultDestination;
+        
+        std::string defaultDestinationName;
+        
+        bool messageIdEnabled;
+        
+        bool messageTimestampEnabled;
+        
+        bool pubSubNoLocal;
+        
+        long long receiveTimeout;
+        
+        bool explicitQosEnabled;
+        
+        int deliveryMode;
+        
+        int priority;
+        
+        long long timeToLive;
+        
+    public:
+        
+    	CmsTemplate();
+    	CmsTemplate(cms::ConnectionFactory* connectionFactory);
+    	    
+    	virtual ~CmsTemplate();
+    	
+    	virtual void setDefaultDestination(cms::Destination* defaultDestination) {
+    	    this->defaultDestination = defaultDestination;
+    	}
+    	
+    	virtual const cms::Destination* getDefaultDestination() const {
+    	    return this->defaultDestination;
+    	}    	    	
+    	
+    	virtual void setDefaultDestinationName(const std::string& defaultDestinationName)
{
+    	    this->defaultDestinationName = defaultDestinationName;
+    	}
+    	
+    	virtual const std::string getDefaultDestinationName() const {
+            return this->defaultDestinationName;
+        }            	
+    	
+    	virtual void setMessageIdEnabled(bool messageIdEnabled) {
+    	    this->messageIdEnabled = messageIdEnabled;
+    	}
+    	
+    	virtual bool isMessageIdEnabled() const {
+            return this->messageIdEnabled;
+        }                
+        
+        virtual void setMessageTimestampEnabled(bool messageTimestampEnabled) {
+            this->messageTimestampEnabled = messageTimestampEnabled;
+        }
+        
+        virtual bool isMessageTimestampEnabled() const {
+            return this->messageTimestampEnabled;
+        }                
+
+        virtual void setPubSubNoLocal(bool pubSubNoLocal) {
+            this->pubSubNoLocal = pubSubNoLocal;
+        }
+
+        virtual bool isPubSubNoLocal() const {
+            return this->pubSubNoLocal;
+        }
+        
+        virtual void setReceiveTimeout(long long receiveTimeout) {
+            this->receiveTimeout = receiveTimeout;
+        }
+
+        virtual long long getReceiveTimeout() const {
+            return this->receiveTimeout;
+        }
+        
+        /**
+         * Set if the QOS values (deliveryMode, priority, timeToLive)
+         * should be used for sending a message.
+         * 
+         * @see #setDeliveryMode
+         * @see #setPriority
+         * @see #setTimeToLive
+         */
+        virtual void setExplicitQosEnabled(bool explicitQosEnabled) {
+            this->explicitQosEnabled = explicitQosEnabled;
+        }
+
+        /**
+         * If "true", then the values of deliveryMode, priority, and timeToLive
+         * will be used when sending a message. Otherwise, the default values,
+         * that may be set administratively, will be used.
+         * 
+         * @return true if overriding default values of QOS parameters
+         * (deliveryMode, priority, and timeToLive)
+         * 
+         * @see #setDeliveryMode
+         * @see #setPriority
+         * @see #setTimeToLive
+         */
+        virtual bool isExplicitQosEnabled() const {
+            return this->explicitQosEnabled;
+        }
+        
+        /**
+         * Set whether message delivery should be persistent or non-persistent,
+         * specified as boolean value ("true" or "false"). This will set the delivery
+         * mode accordingly, to either "PERSISTENT" or "NON_PERSISTENT".
+         * <p>Default it "true" aka delivery mode "PERSISTENT".
+         * 
+         * @see #setDeliveryMode(int)
+         */
+        virtual void setDeliveryPersistent(bool deliveryPersistent) {
+            this->deliveryMode = (deliveryPersistent ? cms::DeliveryMode.PERSISTENT :
cms::DeliveryMode.NON_PERSISTENT);
+        }
+
+        /**
+         * Set the delivery mode to use when sending a message.
+         * Default is the Message default: "PERSISTENT".
+         * <p>Since a default value may be defined administratively,
+         * this is only used when "isExplicitQosEnabled" equals "true".
+         * @param deliveryMode the delivery mode to use
+         * @see #isExplicitQosEnabled
+         */
+        virtual void setDeliveryMode(int deliveryMode) {
+            this.deliveryMode = deliveryMode;
+        }
+        
+        /**
+         * Return the delivery mode to use when sending a message.
+         */
+        virtual int getDeliveryMode() const {
+            return this->deliveryMode;
+        }
+        
+        /**
+         * Set the priority of a message when sending.
+         * <p>Since a default value may be defined administratively,
+         * this is only used when "isExplicitQosEnabled" equals "true".
+         * 
+         * @see #isExplicitQosEnabled
+         */
+        public void setPriority(int priority) {
+            this->priority = priority;
+        }
+            
+        /**
+         * Return the priority of a message when sending.
+         */
+        virtual int getPriority() const {
+            return this->priority;
+        }
+
+        /**
+         * Set the time-to-live of the message when sending.
+         * <p>Since a default value may be defined administratively,
+         * this is only used when "isExplicitQosEnabled" equals "true".
+         * @param timeToLive the message's lifetime (in milliseconds)
+         * 
+         * @see #isExplicitQosEnabled
+         */
+        virtual void setTimeToLive(long long timeToLive) {
+            this->timeToLive = timeToLive;
+        }
+
+        /**
+         * Return the time-to-live of the message when sending.
+         */
+        virtual long long getTimeToLive() const {
+            return this->timeToLive;
+        }
+    	
+    private:
+        
+        void initDefaults();
+        
+        void checkDefaultDestination() throw (decaf::lang::exceptions::IllegalStateException);
+    };
+
+}}
+
+#endif /*ACTIVEMQ_CMSUTIL_CMSTEMPLATE_H_*/



Mime
View raw message