You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by ta...@apache.org on 2010/04/21 17:53:55 UTC

svn commit: r936371 - in /activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/core: ActiveMQConnectionFactory.cpp ActiveMQConnectionFactory.h

Author: tabish
Date: Wed Apr 21 15:53:54 2010
New Revision: 936371

URL: http://svn.apache.org/viewvc?rev=936371&view=rev
Log:
https://issues.apache.org/activemq/browse/AMQCPP-293

Some initial changes to the factory to start implementing this issue.

Modified:
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/core/ActiveMQConnectionFactory.cpp
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/core/ActiveMQConnectionFactory.h

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/core/ActiveMQConnectionFactory.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/core/ActiveMQConnectionFactory.cpp?rev=936371&r1=936370&r2=936371&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/core/ActiveMQConnectionFactory.cpp (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/core/ActiveMQConnectionFactory.cpp Wed Apr 21 15:53:54 2010
@@ -40,6 +40,26 @@ using namespace decaf::lang;
 using namespace decaf::lang::exceptions;
 
 ////////////////////////////////////////////////////////////////////////////////
+namespace activemq{
+namespace core{
+
+    class FactorySettings {
+    public:
+
+        std::string username;
+        std::string password;
+        std::string brokerURL;
+
+        cms::ExceptionListener* defaultListener;
+
+        FactorySettings() : brokerURL("failover:(tcp://localhost:61616)"), defaultListener( NULL ) {
+        }
+
+    };
+
+}}
+
+////////////////////////////////////////////////////////////////////////////////
 cms::ConnectionFactory* cms::ConnectionFactory::createCMSConnectionFactory( const std::string& brokerURI )
     throw ( cms::CMSException ) {
 
@@ -47,29 +67,24 @@ cms::ConnectionFactory* cms::ConnectionF
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-ActiveMQConnectionFactory::ActiveMQConnectionFactory() {
-
-    brokerURL = "failover:(tcp://localhost:61616)";
-    this->username = "";
-    this->password = "";
+ActiveMQConnectionFactory::ActiveMQConnectionFactory() : settings( new FactorySettings() ) {
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-ActiveMQConnectionFactory::ActiveMQConnectionFactory(
-    const std::string& url,
-    const std::string& username,
-    const std::string& password ) {
+ActiveMQConnectionFactory::ActiveMQConnectionFactory( const std::string& url,
+                                                      const std::string& username,
+                                                      const std::string& password ) : settings( new FactorySettings() ) {
 
-    brokerURL = url;
-    this->username = username;
-    this->password = password;
+    settings->brokerURL = url;
+    settings->username = username;
+    settings->password = password;
 }
 
 ////////////////////////////////////////////////////////////////////////////////
 cms::Connection* ActiveMQConnectionFactory::createConnection()
     throw ( cms::CMSException ) {
 
-    return createConnection( brokerURL, username, password, UUID::randomUUID().toString() );
+    return createConnection( settings->brokerURL, settings->username, settings->password, UUID::randomUUID().toString() );
 }
 
 ////////////////////////////////////////////////////////////////////////////////
@@ -78,7 +93,7 @@ cms::Connection* ActiveMQConnectionFacto
     const std::string& password )
         throw ( cms::CMSException ) {
 
-    return createConnection( brokerURL, username, password, UUID::randomUUID().toString() );
+    return createConnection( settings->brokerURL, username, password, UUID::randomUUID().toString() );
 }
 
 ////////////////////////////////////////////////////////////////////////////////
@@ -88,16 +103,15 @@ cms::Connection* ActiveMQConnectionFacto
     const std::string& clientId )
         throw ( cms::CMSException ) {
 
-    return createConnection( brokerURL, username, password, clientId );
+    return createConnection( settings->brokerURL, username, password, clientId );
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-cms::Connection* ActiveMQConnectionFactory::createConnection(
-    const std::string& url,
-    const std::string& username,
-    const std::string& password,
-    const std::string& clientId )
-       throw ( cms::CMSException ) {
+cms::Connection* ActiveMQConnectionFactory::doCreateConnection( const std::string& url,
+                                                                const std::string& username,
+                                                                const std::string& password,
+                                                                const std::string& clientId )
+    throw ( cms::CMSException ) {
 
     Pointer<Transport> transport;
     Pointer<Properties> properties( new Properties() );
@@ -160,3 +174,56 @@ cms::Connection* ActiveMQConnectionFacto
         throw cms::CMSException( "Caught Unknown Exception", NULL );
     }
 }
+
+////////////////////////////////////////////////////////////////////////////////
+cms::Connection* ActiveMQConnectionFactory::createConnection(
+    const std::string& url,
+    const std::string& username,
+    const std::string& password,
+    const std::string& clientId )
+       throw ( cms::CMSException ) {
+
+    ActiveMQConnectionFactory factory;
+
+    return factory.doCreateConnection( url, username, password, clientId );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ActiveMQConnectionFactory::setUsername( const std::string& username ) {
+    settings->username = username;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+const std::string& ActiveMQConnectionFactory::getUsername() const {
+    return settings->username;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ActiveMQConnectionFactory::setPassword( const std::string& password ){
+    settings->password = password;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+const std::string& ActiveMQConnectionFactory::getPassword() const {
+    return settings->password;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ActiveMQConnectionFactory::setBrokerURL( const std::string& brokerURL ){
+    settings->brokerURL = brokerURL;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+const std::string& ActiveMQConnectionFactory::getBrokerURL() const {
+    return settings->brokerURL;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ActiveMQConnectionFactory::setExceptionListener( cms::ExceptionListener* listener ) {
+    this->settings->defaultListener = listener;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+cms::ExceptionListener* ActiveMQConnectionFactory::getExceptionListener() const {
+    return this->settings->defaultListener;
+}

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/core/ActiveMQConnectionFactory.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/core/ActiveMQConnectionFactory.h?rev=936371&r1=936370&r2=936371&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/core/ActiveMQConnectionFactory.h (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/core/ActiveMQConnectionFactory.h Wed Apr 21 15:53:54 2010
@@ -25,18 +25,13 @@
 namespace activemq{
 namespace core{
 
+    class FactorySettings;
+
     class AMQCPP_API ActiveMQConnectionFactory : public cms::ConnectionFactory {
     private:
 
-        // The user name this factory will use to connect
-        std::string username;
-
-        // The password this factory will use to connect
-        std::string password;
-
-        // The URL of the Broker, the default is:
-        // "tcp://localhost:61616"
-        std::string brokerURL;
+        // d-Pointer holding pre-configured factory settings
+        FactorySettings* settings;
 
     public:
 
@@ -106,53 +101,59 @@ namespace core{
          * Sets the username that should be used when creating a new connection
          * @param username string
          */
-        virtual void setUsername( const std::string& username ){
-            this->username = username;
-        }
+        virtual void setUsername( const std::string& username );
 
         /**
          * Gets the username that this factory will use when creating a new
          * connection instance.
          * @return username string, "" for default credentials
          */
-        virtual const std::string& getUsername() const {
-            return username;
-        }
+        virtual const std::string& getUsername() const;
 
         /**
          * Sets the password that should be used when creating a new connection
          * @param password string
          */
-        virtual void setPassword( const std::string& password ){
-            this->password = password;
-        }
+        virtual void setPassword( const std::string& password );
 
         /**
          * Gets the password that this factory will use when creating a new
          * connection instance.
          * @return password string, "" for default credentials
          */
-        virtual const std::string& getPassword() const {
-            return password;
-        }
+        virtual const std::string& getPassword() const;
 
         /**
          * Sets the Broker URL that should be used when creating a new
          * connection instance
          * @param brokerURL string
          */
-        virtual void setBrokerURL( const std::string& brokerURL ){
-            this->brokerURL = brokerURL;
-        }
+        virtual void setBrokerURL( const std::string& brokerURL );
 
         /**
          * Gets the Broker URL that this factory will use when creating a new
          * connection instance.
          * @return brokerURL string
          */
-        virtual const std::string& getBrokerURL() const {
-            return brokerURL;
-        }
+        virtual const std::string& getBrokerURL() const;
+
+        /**
+         * Set an CMS ExceptionListener that will be set on eat connection once it has been
+         * created.  The factory des not take ownership of this pointer, the client must ensure
+         * that its lifetime is scoped to the connection that it is applied to.
+         *
+         * @param listener
+         * 		The listener to set on the connection or NULL for no listener.
+         */
+        virtual void setExceptionListener( cms::ExceptionListener* listener );
+
+        /**
+         * Returns the currently set ExceptionListener that will be set on any new Connection
+         * instance that is created by this factory.
+         *
+         * @return a pointer to a CMS ExceptionListener instance or NULL if not set.
+         */
+        virtual cms::ExceptionListener* getExceptionListener() const;
 
     public:
 
@@ -172,6 +173,14 @@ namespace core{
                                                   const std::string& clientId = "" )
             throw ( cms::CMSException );
 
+    public:
+
+        virtual cms::Connection* doCreateConnection( const std::string& url,
+                                                     const std::string& username,
+                                                     const std::string& password,
+                                                     const std::string& clientId )
+            throw ( cms::CMSException );
+
     };
 
 }}