activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject svn commit: r555115 - /activemq/activemq-cpp/trunk/src/main/activemq/core/ActiveMQConnection.cpp
Date Tue, 10 Jul 2007 23:44:07 GMT
Author: tabish
Date: Tue Jul 10 16:44:06 2007
New Revision: 555115

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

Using Set iterator to save time copying and iterating over elements.

Modified:
    activemq/activemq-cpp/trunk/src/main/activemq/core/ActiveMQConnection.cpp

Modified: activemq/activemq-cpp/trunk/src/main/activemq/core/ActiveMQConnection.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/activemq/core/ActiveMQConnection.cpp?view=diff&rev=555115&r1=555114&r2=555115
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/activemq/core/ActiveMQConnection.cpp (original)
+++ activemq/activemq-cpp/trunk/src/main/activemq/core/ActiveMQConnection.cpp Tue Jul 10 16:44:06
2007
@@ -22,6 +22,7 @@
 #include <activemq/core/ActiveMQConsumer.h>
 #include <activemq/exceptions/NullPointerException.h>
 #include <activemq/util/Boolean.h>
+#include <activemq/util/Iterator.h>
 
 using namespace cms;
 using namespace activemq;
@@ -48,8 +49,7 @@
 ////////////////////////////////////////////////////////////////////////////////
 ActiveMQConnection::~ActiveMQConnection()
 {
-    try
-    {
+    try {
         close();
     }
     AMQ_CATCH_NOTHROW( ActiveMQException )
@@ -61,8 +61,7 @@
     Dispatcher* dispatcher )
 {
     // Add the consumer to the map.
-    synchronized( &dispatchers )
-    {
+    synchronized( &dispatchers ) {
         dispatchers.setValue( consumer->getConsumerId(), dispatcher );
     }
 }
@@ -71,8 +70,7 @@
 void ActiveMQConnection::removeDispatcher( const connector::ConsumerInfo* consumer ) {
 
     // Remove the consumer from the map.
-    synchronized( &dispatchers )
-    {
+    synchronized( &dispatchers ) {
         dispatchers.remove( consumer->getConsumerId() );
     }
 }
@@ -80,8 +78,7 @@
 ////////////////////////////////////////////////////////////////////////////////
 cms::Session* ActiveMQConnection::createSession() throw ( cms::CMSException )
 {
-    try
-    {
+    try {
         return createSession( Session::AUTO_ACKNOWLEDGE );
     }
     AMQ_CATCH_RETHROW( ActiveMQException )
@@ -92,8 +89,8 @@
 cms::Session* ActiveMQConnection::createSession(
     cms::Session::AcknowledgeMode ackMode ) throw ( cms::CMSException )
 {
-    try
-    {
+    try {
+
         // Create the session instance.
         ActiveMQSession* session = new ActiveMQSession(
             connectionData->getConnector()->createSession( ackMode ),
@@ -129,10 +126,9 @@
 ////////////////////////////////////////////////////////////////////////////////
 void ActiveMQConnection::close() throw ( cms::CMSException )
 {
-    try
-    {
-        if( closed )
-        {
+    try {
+
+        if( closed ) {
             return;
         }
 
@@ -190,21 +186,20 @@
     // new messages.
     started = false;
 
-    // Stop all the sessions.
-    std::vector<ActiveMQSession*> sessions = activeSessions.toArray();
-    for( unsigned int ix=0; ix<sessions.size(); ++ix ) {
-        sessions[ix]->stop();
+    Iterator<ActiveMQSession*>* iter = activeSessions.iterator();
+    while( iter->hasNext() ){
+        iter->next()->stop();
     }
+    delete iter;
 }
 
 ////////////////////////////////////////////////////////////////////////////////
 void ActiveMQConnection::onConsumerMessage( connector::ConsumerInfo* consumer,
                                             core::ActiveMQMessage* message )
 {
-    try
-    {
-        if( connectionData == NULL)
-        {
+    try {
+
+        if( connectionData == NULL) {
             NullPointerException ex(
                 __FILE__, __LINE__,
                 "ActiveMQConnection::onConsumerMessage - "
@@ -217,8 +212,8 @@
 
         // Look up the dispatcher.
         Dispatcher* dispatcher = NULL;
-        synchronized( &dispatchers )
-        {
+        synchronized( &dispatchers ) {
+
             dispatcher = dispatchers.getValue(consumer->getConsumerId());
 
             // If we have no registered dispatcher, the consumer was probably
@@ -233,13 +228,11 @@
             }
         }
     }
-    catch( exceptions::ActiveMQException& ex )
-    {
+    catch( exceptions::ActiveMQException& ex ) {
         ex.setMark( __FILE__, __LINE__ );
         fire( ex );
     }
-    catch( ... )
-    {
+    catch( ... ) {
         exceptions::ActiveMQException ex(
            __FILE__, __LINE__,
            "IOTransport::run - caught unknown exception" );
@@ -259,8 +252,8 @@
 void ActiveMQConnection::removeSession( ActiveMQSession* session )
     throw ( cms::CMSException )
 {
-    try
-    {
+    try {
+
         // Remove this session from the set of active sessions.
         synchronized( &activeSessions ) {
             activeSessions.remove( session );



Mime
View raw message