Author: cctrieloff
Date: Mon Mar 14 16:30:12 2011
New Revision: 1081450

URL: http://svn.apache.org/viewvc?rev=1081450&view=rev
Log:
QPID-3138 some cosmetic cleanup & correction for IVE

Modified:
    qpid/trunk/qpid/cpp/src/qpid/broker/TopicExchange.cpp
    qpid/trunk/qpid/cpp/src/qpid/broker/TopicExchange.h

Modified: qpid/trunk/qpid/cpp/src/qpid/broker/TopicExchange.cpp
URL: 
http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/qpid/broker/TopicExchange.cpp?rev=1081450&r1=1081449&r2=1081450&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/src/qpid/broker/TopicExchange.cpp (original)
+++ qpid/trunk/qpid/cpp/src/qpid/broker/TopicExchange.cpp Mon Mar 14 16:30:12 
2011
@@ -221,7 +221,7 @@ TopicExchange::TopicExchange(const std::
 
 bool TopicExchange::bind(Queue::shared_ptr queue, const string& routingKey, 
const FieldTable* args)
 {
-       ClearCache cc(&cacheLock,&bindingCache); // clear the cache on function 
exit.
+    ClearCache cc(&cacheLock,&bindingCache); // clear the cache on function 
exit.
     string fedOp(args ? args->getAsString(qpidFedOp) : fedOpBind);
     string fedTags(args ? args->getAsString(qpidFedTags) : "");
     string fedOrigin(args ? args->getAsString(qpidFedOrigin) : "");
@@ -282,6 +282,7 @@ bool TopicExchange::bind(Queue::shared_p
         }
     }
 
+    cc.clearCache(); // clear the cache before we IVE route.
     routeIVE();
     if (propagate)
         propagateFedOp(routingKey, fedTags, fedOp, fedOrigin);
@@ -289,7 +290,7 @@ bool TopicExchange::bind(Queue::shared_p
 }
 
 bool TopicExchange::unbind(Queue::shared_ptr queue, const string& 
constRoutingKey, const FieldTable* /*args*/){
-       ClearCache cc(&cacheLock,&bindingCache); // clear the cache on function 
exit.
+    ClearCache cc(&cacheLock,&bindingCache); // clear the cache on function 
exit.
     RWlock::ScopedWlock l(lock);
     string routingKey = normalize(constRoutingKey);
     BindingKey* bk = bindingTree.getBindingKey(routingKey);
@@ -336,23 +337,24 @@ void TopicExchange::route(Deliverable& m
 {
     // Note: PERFORMANCE CRITICAL!!!
     BindingList b;
-       std::map<std::string, BindingList>::iterator it;
-       {  // only lock the cache for read
+    std::map<std::string, BindingList>::iterator it;
+    {  // only lock the cache for read
        RWlock::ScopedRlock cl(cacheLock);
-          it = bindingCache.find(routingKey);
-       }
+       it = bindingCache.find(routingKey);
+       if (it != bindingCache.end()) {
+           b = it->second;
+       }
+    }
     PreRoute pr(msg, this);
-    if (it == bindingCache.end())  // no cache hit
+    if (!b.get())  // no cache hit
     {
         RWlock::ScopedRlock l(lock);
        b = BindingList(new 
std::vector<boost::shared_ptr<qpid::broker::Exchange::Binding> >);
         BindingsFinderIter bindingsFinder(b);
         bindingTree.iterateMatch(routingKey, bindingsFinder);
-           RWlock::ScopedWlock cwl(cacheLock);
-               bindingCache[routingKey] = b; // update cache
-    }else {
-        b = it->second;
-     }
+        RWlock::ScopedWlock cwl(cacheLock);
+        bindingCache[routingKey] = b; // update cache
+    }
     doRoute(msg, b);
 }
 

Modified: qpid/trunk/qpid/cpp/src/qpid/broker/TopicExchange.h
URL: 
http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/qpid/broker/TopicExchange.h?rev=1081450&r1=1081449&r2=1081450&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/src/qpid/broker/TopicExchange.h (original)
+++ qpid/trunk/qpid/cpp/src/qpid/broker/TopicExchange.h Mon Mar 14 16:30:12 2011
@@ -136,18 +136,26 @@ class TopicExchange : public virtual Exc
     unsigned long nBindings;
     qpid::sys::RWlock lock;     // protects bindingTree and nBindings
     qpid::sys::RWlock cacheLock;     // protects cache
-       std::map<std::string, BindingList> bindingCache; // cache of matched 
routes.
-       class ClearCache {
-       private:
-               qpid::sys::RWlock* cacheLock;
-               std::map<std::string, BindingList>* bindingCache; 
-       public:
-               ClearCache(qpid::sys::RWlock* l, std::map<std::string, 
BindingList>* bc): cacheLock(l),bindingCache(bc) {};
-               ~ClearCache(){ 
-                       qpid::sys::RWlock::ScopedWlock l(*cacheLock);
-                       bindingCache->clear();   
-               };
-       };
+    std::map<std::string, BindingList> bindingCache; // cache of matched 
routes.
+    class ClearCache {
+    private:
+        qpid::sys::RWlock* cacheLock;
+        std::map<std::string, BindingList>* bindingCache;
+       bool cleared; 
+    public:
+        ClearCache(qpid::sys::RWlock* l, std::map<std::string, BindingList>* 
bc): cacheLock(l),
+             bindingCache(bc),cleared(false) {};
+        void clearCache() {
+             qpid::sys::RWlock::ScopedWlock l(*cacheLock);
+             if (!cleared) {
+                 bindingCache->clear();
+                 cleared =true;
+             }
+        };
+        ~ClearCache(){ 
+            clearCache();
+        };
+    };
     bool isBound(Queue::shared_ptr queue, const std::string& pattern);
 
     class ReOriginIter;



---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project:      http://qpid.apache.org
Use/Interact: mailto:[email protected]

Reply via email to