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 2013/02/08 18:29:18 UTC
svn commit: r1444163 - in
/activemq/activemq-cpp/branches/activemq-cpp-3.5.x: ./
activemq-cpp/src/main/activemq/core/ActiveMQConnectionFactory.cpp
Author: tabish
Date: Fri Feb 8 17:29:17 2013
New Revision: 1444163
URL: http://svn.apache.org/r1444163
Log:
fix for: https://issues.apache.org/jira/browse/AMQCPP-455
Makes the connection factory config data thread safe.
Modified:
activemq/activemq-cpp/branches/activemq-cpp-3.5.x/ (props changed)
activemq/activemq-cpp/branches/activemq-cpp-3.5.x/activemq-cpp/src/main/activemq/core/ActiveMQConnectionFactory.cpp
Propchange: activemq/activemq-cpp/branches/activemq-cpp-3.5.x/
------------------------------------------------------------------------------
Merged /activemq/activemq-cpp/trunk:r1444160
Modified: activemq/activemq-cpp/branches/activemq-cpp-3.5.x/activemq-cpp/src/main/activemq/core/ActiveMQConnectionFactory.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/branches/activemq-cpp-3.5.x/activemq-cpp/src/main/activemq/core/ActiveMQConnectionFactory.cpp?rev=1444163&r1=1444162&r2=1444163&view=diff
==============================================================================
--- activemq/activemq-cpp/branches/activemq-cpp-3.5.x/activemq-cpp/src/main/activemq/core/ActiveMQConnectionFactory.cpp (original)
+++ activemq/activemq-cpp/branches/activemq-cpp-3.5.x/activemq-cpp/src/main/activemq/core/ActiveMQConnectionFactory.cpp Fri Feb 8 17:29:17 2013
@@ -19,6 +19,7 @@
#include <cms/MessageTransformer.h>
#include <decaf/net/URI.h>
#include <decaf/util/Properties.h>
+#include <decaf/util/concurrent/Mutex.h>
#include <decaf/lang/Boolean.h>
#include <decaf/lang/Integer.h>
#include <decaf/lang/Pointer.h>
@@ -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> properties;
std::string username;
@@ -86,7 +90,8 @@ namespace core{
std::auto_ptr<PrefetchPolicy> defaultPrefetchPolicy;
std::auto_ptr<RedeliveryPolicy> 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> properties(this->settings->properties->clone());
+ Pointer<Properties> 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);
+ }
}
////////////////////////////////////////////////////////////////////////////////