Return-Path: X-Original-To: apmail-activemq-commits-archive@www.apache.org Delivered-To: apmail-activemq-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id E1BB3EC11 for ; Fri, 8 Feb 2013 17:28:21 +0000 (UTC) Received: (qmail 68259 invoked by uid 500); 8 Feb 2013 17:28:21 -0000 Delivered-To: apmail-activemq-commits-archive@activemq.apache.org Received: (qmail 68230 invoked by uid 500); 8 Feb 2013 17:28:21 -0000 Mailing-List: contact commits-help@activemq.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@activemq.apache.org Delivered-To: mailing list commits@activemq.apache.org Received: (qmail 68221 invoked by uid 99); 8 Feb 2013 17:28:21 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 08 Feb 2013 17:28:21 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 08 Feb 2013 17:28:20 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id B8A3C2388A33; Fri, 8 Feb 2013 17:28:01 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1444160 - /activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/core/ActiveMQConnectionFactory.cpp Date: Fri, 08 Feb 2013 17:28:01 -0000 To: commits@activemq.apache.org From: tabish@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20130208172801.B8A3C2388A33@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: tabish Date: Fri Feb 8 17:28:00 2013 New Revision: 1444160 URL: http://svn.apache.org/r1444160 Log: fix for: https://issues.apache.org/jira/browse/AMQCPP-455 Makes the connection factory config data thread safe. Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/core/ActiveMQConnectionFactory.cpp 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=1444160&r1=1444159&r2=1444160&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 Fri Feb 8 17:28:00 2013 @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -44,6 +45,7 @@ using namespace activemq::transport; using namespace decaf; using namespace decaf::net; using namespace decaf::util; +using namespace decaf::util::concurrent; using namespace decaf::lang; using namespace decaf::lang::exceptions; @@ -62,6 +64,8 @@ namespace core{ public: + Mutex configLock; + Pointer properties; std::string username; @@ -86,7 +90,8 @@ namespace core{ std::auto_ptr defaultPrefetchPolicy; std::auto_ptr defaultRedeliveryPolicy; - FactorySettings() : properties(new Properties()), + FactorySettings() : configLock(), + properties(new Properties()), username(), password(), clientId(), @@ -265,40 +270,43 @@ cms::Connection* ActiveMQConnectionFacto try { - this->setBrokerURI(uri); + synchronized(&this->settings->configLock) { - // Store login data in the properties - if (!username.empty()) { - this->settings->username = username; - } - if (!password.empty()) { - this->settings->password = password; - } - if (!clientId.empty()) { - this->settings->clientId = clientId; - } + this->setBrokerURI(uri); + + // Store login data in the properties + if (!username.empty()) { + this->settings->username = username; + } + if (!password.empty()) { + this->settings->password = password; + } + if (!clientId.empty()) { + this->settings->clientId = clientId; + } - // Use the TransportBuilder to get our Transport - transport = TransportRegistry::getInstance().findFactory(uri.getScheme())->create(uri); + // Use the TransportBuilder to get our Transport + transport = TransportRegistry::getInstance().findFactory(uri.getScheme())->create(uri); - if (transport == NULL) { - throw ActiveMQException(__FILE__, __LINE__, "ActiveMQConnectionFactory::createConnection - " - "failed creating new Transport"); - } + if (transport == NULL) { + throw ActiveMQException(__FILE__, __LINE__, "ActiveMQConnectionFactory::createConnection - " + "failed creating new Transport"); + } - Pointer properties(this->settings->properties->clone()); + Pointer properties(this->settings->properties->clone()); - // Create and Return the new connection object. - connection.reset(createActiveMQConnection(transport, properties)); + // Create and Return the new connection object. + connection.reset(createActiveMQConnection(transport, properties)); - // Set all options parsed from the URI. - configureConnection(connection.get()); + // Set all options parsed from the URI. + configureConnection(connection.get()); - // Now start the connection since all other configuration is done. - transport->start(); + // Now start the connection since all other configuration is done. + transport->start(); - if (!this->settings->clientId.empty()) { - connection->setDefaultClientId(this->settings->clientId); + if (!this->settings->clientId.empty()) { + connection->setDefaultClientId(this->settings->clientId); + } } return connection.release(); @@ -400,7 +408,9 @@ void ActiveMQConnectionFactory::setBroke //////////////////////////////////////////////////////////////////////////////// void ActiveMQConnectionFactory::setBrokerURI(const decaf::net::URI& uri) { - this->settings->updateConfiguration(uri); + synchronized(&this->settings->configLock) { + this->settings->updateConfiguration(uri); + } } ////////////////////////////////////////////////////////////////////////////////