activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject git commit: https://issues.apache.org/jira/browse/AMQCPP-546
Date Tue, 08 Jul 2014 21:02:30 GMT
Repository: activemq-cpp
Updated Branches:
  refs/heads/trunk 352475374 -> 74ef17b0e


https://issues.apache.org/jira/browse/AMQCPP-546

make the connection audit class methods thread safe

Project: http://git-wip-us.apache.org/repos/asf/activemq-cpp/repo
Commit: http://git-wip-us.apache.org/repos/asf/activemq-cpp/commit/74ef17b0
Tree: http://git-wip-us.apache.org/repos/asf/activemq-cpp/tree/74ef17b0
Diff: http://git-wip-us.apache.org/repos/asf/activemq-cpp/diff/74ef17b0

Branch: refs/heads/trunk
Commit: 74ef17b0ed25fe04d23e2346bee156fd1e840012
Parents: 3524753
Author: Timothy Bish <tabish121@gmail.com>
Authored: Tue Jul 8 17:02:24 2014 -0400
Committer: Timothy Bish <tabish121@gmail.com>
Committed: Tue Jul 8 17:02:24 2014 -0400

----------------------------------------------------------------------
 .../src/main/activemq/core/ConnectionAudit.cpp  | 61 ++++++++++----------
 1 file changed, 32 insertions(+), 29 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/activemq-cpp/blob/74ef17b0/activemq-cpp/src/main/activemq/core/ConnectionAudit.cpp
----------------------------------------------------------------------
diff --git a/activemq-cpp/src/main/activemq/core/ConnectionAudit.cpp b/activemq-cpp/src/main/activemq/core/ConnectionAudit.cpp
index b8e3c5e..40b8cde 100644
--- a/activemq-cpp/src/main/activemq/core/ConnectionAudit.cpp
+++ b/activemq-cpp/src/main/activemq/core/ConnectionAudit.cpp
@@ -90,30 +90,31 @@ void ConnectionAudit::removeDispatcher(Dispatcher* dispatcher) {
 
 ////////////////////////////////////////////////////////////////////////////////
 bool ConnectionAudit::isDuplicate(Dispatcher* dispatcher, Pointer<commands::Message>
message) {
-
-    if (checkForDuplicates && message != NULL) {
-        Pointer<ActiveMQDestination> destination = message->getDestination();
-        if (destination != NULL) {
-            if (destination->isQueue()) {
+    synchronized(&this->impl->mutex) {
+        if (checkForDuplicates && message != NULL) {
+            Pointer<ActiveMQDestination> destination = message->getDestination();
+            if (destination != NULL) {
+                if (destination->isQueue()) {
+                    Pointer<ActiveMQMessageAudit> audit;
+                    try {
+                        audit = this->impl->destinations.get(destination);
+                    } catch (NoSuchElementException& ex) {
+                        audit.reset(new ActiveMQMessageAudit(auditDepth, auditMaximumProducerNumber));
+                        this->impl->destinations.put(destination, audit);
+                    }
+                    bool result = audit->isDuplicate(message->getMessageId());
+                    return result;
+                }
                 Pointer<ActiveMQMessageAudit> audit;
                 try {
-                    audit = this->impl->destinations.get(destination);
+                    audit = this->impl->dispatchers.get(dispatcher);
                 } catch (NoSuchElementException& ex) {
                     audit.reset(new ActiveMQMessageAudit(auditDepth, auditMaximumProducerNumber));
-                    this->impl->destinations.put(destination, audit);
+                    this->impl->dispatchers.put(dispatcher, audit);
                 }
                 bool result = audit->isDuplicate(message->getMessageId());
                 return result;
             }
-            Pointer<ActiveMQMessageAudit> audit;
-            try {
-                audit = this->impl->dispatchers.get(dispatcher);
-            } catch (NoSuchElementException& ex) {
-                audit.reset(new ActiveMQMessageAudit(auditDepth, auditMaximumProducerNumber));
-                this->impl->dispatchers.put(dispatcher, audit);
-            }
-            bool result = audit->isDuplicate(message->getMessageId());
-            return result;
         }
     }
     return false;
@@ -121,19 +122,21 @@ bool ConnectionAudit::isDuplicate(Dispatcher* dispatcher, Pointer<commands::Mess
 
 ////////////////////////////////////////////////////////////////////////////////
 void ConnectionAudit::rollbackDuplicate(Dispatcher* dispatcher, Pointer<commands::Message>
message) {
-    if (checkForDuplicates && message != NULL) {
-        Pointer<ActiveMQDestination> destination = message->getDestination();
-        if (destination != NULL) {
-            if (destination->isQueue()) {
-                try {
-                    Pointer<ActiveMQMessageAudit> audit = this->impl->destinations.get(destination);
-                    audit->rollback(message->getMessageId());
-                } catch (NoSuchElementException& ex) {}
-            } else {
-                try {
-                    Pointer<ActiveMQMessageAudit> audit = this->impl->dispatchers.get(dispatcher);
-                    audit->rollback(message->getMessageId());
-                } catch (NoSuchElementException& ex) {}
+    synchronized(&this->impl->mutex) {
+        if (checkForDuplicates && message != NULL) {
+            Pointer<ActiveMQDestination> destination = message->getDestination();
+            if (destination != NULL) {
+                if (destination->isQueue()) {
+                    try {
+                        Pointer<ActiveMQMessageAudit> audit = this->impl->destinations.get(destination);
+                        audit->rollback(message->getMessageId());
+                    } catch (NoSuchElementException& ex) {}
+                } else {
+                    try {
+                        Pointer<ActiveMQMessageAudit> audit = this->impl->dispatchers.get(dispatcher);
+                        audit->rollback(message->getMessageId());
+                    } catch (NoSuchElementException& ex) {}
+                }
             }
         }
     }


Mime
View raw message