activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject svn commit: r1446802 - in /activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/transport/failover: URIPool.cpp URIPool.h
Date Fri, 15 Feb 2013 22:58:52 GMT
Author: tabish
Date: Fri Feb 15 22:58:52 2013
New Revision: 1446802

URL: http://svn.apache.org/r1446802
Log:
Enhance the API a bit

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

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/transport/failover/URIPool.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/transport/failover/URIPool.cpp?rev=1446802&r1=1446801&r2=1446802&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/transport/failover/URIPool.cpp
(original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/transport/failover/URIPool.cpp
Fri Feb 15 22:58:52 2013
@@ -31,12 +31,28 @@ using namespace decaf::lang;
 using namespace decaf::lang::exceptions;
 
 ////////////////////////////////////////////////////////////////////////////////
-URIPool::URIPool() : uriPool(), randomize( false ) {
+URIPool::URIPool() : uriPool(), randomize(false) {
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-URIPool::URIPool(const decaf::util::List<URI>& uris) : uriPool(), randomize( false
) {
-    this->uriPool.copy( uris );
+URIPool::URIPool(const decaf::util::List<URI>& uris) : uriPool(), randomize(false)
{
+    this->uriPool.copy(uris);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+URIPool::URIPool(const URIPool& uris) : uriPool(), randomize(false) {
+    synchronized(&uris.uriPool) {
+        this->uriPool.copy(uris.uriPool);
+    }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+URIPool& URIPool::operator= (const URIPool& uris) {
+    synchronized(&uris.uriPool) {
+        this->uriPool.copy(uris.uriPool);
+    }
+
+    return *this;
 }
 
 ////////////////////////////////////////////////////////////////////////////////
@@ -47,22 +63,21 @@ URIPool::~URIPool() {
 URI URIPool::getURI() {
 
     synchronized(&uriPool) {
-        if( !uriPool.isEmpty() ) {
+        if (!uriPool.isEmpty()) {
 
-            int index = 0;  // Take the first one in the list unless random is on.
+            int index = 0; // Take the first one in the list unless random is on.
 
-            if( isRandomize() ) {
+            if (isRandomize()) {
                 Random rand;
-                rand.setSeed( decaf::lang::System::currentTimeMillis() );
-                index = rand.nextInt( (int)uriPool.size() );
+                rand.setSeed(decaf::lang::System::currentTimeMillis());
+                index = rand.nextInt((int) uriPool.size());
             }
 
-            return uriPool.removeAt( index );
+            return uriPool.removeAt(index);
         }
     }
 
-    throw NoSuchElementException(
-        __FILE__, __LINE__, "URI Pool is currently empty." );
+    throw NoSuchElementException(__FILE__, __LINE__, "URI Pool is currently empty.");
 }
 
 ////////////////////////////////////////////////////////////////////////////////
@@ -79,7 +94,7 @@ bool URIPool::addURI(const URI& uri) {
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-bool URIPool::addURIs(const LinkedList<URI>& uris) {
+bool URIPool::addURIs(const List<URI>& uris) {
 
     bool result = false;
 
@@ -147,3 +162,20 @@ bool URIPool::isEmpty() const {
     }
     return result;
 }
+
+////////////////////////////////////////////////////////////////////////////////
+bool URIPool::equals(const URIPool& other) const {
+
+    LinkedList<URI> mine;
+    LinkedList<URI> others;
+
+    synchronized(&other.uriPool) {
+        others.copy(other.uriPool);
+    }
+
+    synchronized(&this->uriPool) {
+        mine.copy(this->uriPool);
+    }
+
+    return mine.equals(others);
+}

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/transport/failover/URIPool.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/transport/failover/URIPool.h?rev=1446802&r1=1446801&r2=1446802&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/transport/failover/URIPool.h
(original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/transport/failover/URIPool.h
Fri Feb 15 22:58:52 2013
@@ -48,6 +48,22 @@ namespace failover {
          */
         URIPool(const decaf::util::List<decaf::net::URI>& uris);
 
+        /**
+         * Creates a new URI Pool which will be a copy of the given URI Pool
+         *
+         * @param uris
+         *      The URIPool instance to copy.
+         */
+        URIPool(const URIPool& uris);
+
+        /**
+         * Assignment operator, copies the contents of the given URIPool into this one.
+         *
+         * @param uris
+         *      The URIPool whose contents are to be copied.
+         */
+        URIPool& operator= (const URIPool& uris);
+
         ~URIPool();
 
         /**
@@ -138,6 +154,13 @@ namespace failover {
          */
         void clear();
 
+        /**
+         * Compares the URIs in this set to that of another URIPool
+         *
+         * @returns true if the URIPool instance contains the same values.
+         */
+        bool equals(const URIPool& other) const;
+
     };
 
 }}}



Mime
View raw message