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 2008/11/19 15:48:42 UTC

svn commit: r718976 - in /activemq/activemq-cpp/trunk/src/main/activemq/transport: MockTransport.cpp MockTransport.h

Author: tabish
Date: Wed Nov 19 06:48:42 2008
New Revision: 718976

URL: http://svn.apache.org/viewvc?rev=718976&view=rev
Log:
Refactor to use an AtomicInteger instead of a mutex to get command IDs

Modified:
    activemq/activemq-cpp/trunk/src/main/activemq/transport/MockTransport.cpp
    activemq/activemq-cpp/trunk/src/main/activemq/transport/MockTransport.h

Modified: activemq/activemq-cpp/trunk/src/main/activemq/transport/MockTransport.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/activemq/transport/MockTransport.cpp?rev=718976&r1=718975&r2=718976&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/activemq/transport/MockTransport.cpp (original)
+++ activemq/activemq-cpp/trunk/src/main/activemq/transport/MockTransport.cpp Wed Nov 19 06:48:42 2008
@@ -37,7 +37,7 @@
     this->exceptionListener = NULL;
     this->responseBuilder = responseBuilder;
     this->own = own;
-    this->nextCommandId = 0;
+    this->nextCommandId.set( 0 );
     this->instance = this;
 
     // Configure the Internal Listener this is the Fake Broker.
@@ -57,25 +57,6 @@
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-unsigned int MockTransport::getNextCommandId()
-    throw ( activemq::exceptions::ActiveMQException ) {
-
-    try{
-
-        synchronized( &commandIdMutex ){
-            return ++nextCommandId;
-        }
-
-        // Should never get here, but some compilers aren't
-        // smart enough to figure out we'll never get here.
-        return 0;
-    }
-    AMQ_CATCH_RETHROW( ActiveMQException )
-    AMQ_CATCH_EXCEPTION_CONVERT( Exception, ActiveMQException )
-    AMQ_CATCHALL_THROW( ActiveMQException )
-}
-
-////////////////////////////////////////////////////////////////////////////////
 void MockTransport::oneway( Command* command )
         throw( CommandIOException,
                decaf::lang::exceptions::UnsupportedOperationException) {
@@ -112,7 +93,7 @@
                 outgoingCommandListener->onCommand( command );
             }
 
-            command->setCommandId( getNextCommandId() );
+            command->setCommandId( this->nextCommandId.incrementAndGet() );
             command->setResponseRequired( true );
             return responseBuilder->buildResponse( command );
         }

Modified: activemq/activemq-cpp/trunk/src/main/activemq/transport/MockTransport.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/activemq/transport/MockTransport.h?rev=718976&r1=718975&r2=718976&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/activemq/transport/MockTransport.h (original)
+++ activemq/activemq-cpp/trunk/src/main/activemq/transport/MockTransport.h Wed Nov 19 06:48:42 2008
@@ -26,11 +26,10 @@
 #include <activemq/transport/CommandIOException.h>
 
 #include <decaf/lang/Thread.h>
-#include <decaf/util/concurrent/Concurrent.h>
-#include <decaf/util/concurrent/Mutex.h>
 #include <decaf/util/Queue.h>
-#include <decaf/util/concurrent/CountDownLatch.h>
 #include <decaf/util/concurrent/Concurrent.h>
+#include <decaf/util/concurrent/atomic/AtomicInteger.h>
+#include <decaf/util/concurrent/CountDownLatch.h>
 
 #include <cms/Message.h>
 
@@ -105,7 +104,7 @@
 
         public:
 
-            InternalCommandListener(void) : startedLatch(1) {
+            InternalCommandListener() : startedLatch(1) {
                 transport = NULL;
                 responseBuilder = NULL;
                 done = false;
@@ -179,8 +178,7 @@
         CommandListener* commandListener;
         CommandListener* outgoingCommandListener;
         TransportExceptionListener* exceptionListener;
-        unsigned int nextCommandId;
-        decaf::util::concurrent::Mutex commandIdMutex;
+        decaf::util::concurrent::atomic::AtomicInteger nextCommandId;
         bool own;
         InternalCommandListener internalListener;
         static MockTransport* instance;
@@ -285,10 +283,6 @@
             return NULL;
         }
 
-    protected:
-
-        unsigned int getNextCommandId() throw( exceptions::ActiveMQException );
-
     };
 
 }}