Author: tross
Date: Fri Oct 14 18:29:00 2011
New Revision: 1183455

URL: http://svn.apache.org/viewvc?rev=1183455&view=rev
Log:
QPID-3549 - Improved handling of boolean configuration options in Queue.cpp

Modified:
    qpid/trunk/qpid/cpp/src/qpid/broker/Queue.cpp

Modified: qpid/trunk/qpid/cpp/src/qpid/broker/Queue.cpp
URL: 
http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/qpid/broker/Queue.cpp?rev=1183455&r1=1183454&r2=1183455&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/src/qpid/broker/Queue.cpp (original)
+++ qpid/trunk/qpid/cpp/src/qpid/broker/Queue.cpp Fri Oct 14 18:29:00 2011
@@ -952,6 +952,31 @@ int getIntegerSetting(const qpid::framin
     }
 }
 
+bool getBoolSetting(const qpid::framing::FieldTable& settings, const 
std::string& key)
+{
+    qpid::framing::FieldTable::ValuePtr v = settings.get(key);
+    if (!v) {
+        return false;
+    } else if (v->convertsTo<int>()) {
+        return v->get<int>() != 0;
+    } else if (v->convertsTo<std::string>()){
+        std::string s = v->get<std::string>();
+        if (s == "True")  return true;
+        if (s == "true")  return true;
+        if (s == "False") return false;
+        if (s == "false") return false;
+        try {
+            return boost::lexical_cast<bool>(s);
+        } catch(const boost::bad_lexical_cast&) {
+            QPID_LOG(warning, "Ignoring invalid boolean value for " << key << 
": " << s);
+            return false;
+        }
+    } else {
+        QPID_LOG(warning, "Ignoring invalid boolean value for " << key << ": " 
<< *v);
+        return false;
+    }
+}
+
 void Queue::configure(const FieldTable& _settings)
 {
     settings = _settings;
@@ -983,7 +1008,7 @@ void Queue::configureImpl(const FieldTab
     }
 
     //set this regardless of owner to allow use of no-local with exclusive 
consumers also
-    noLocal = _settings.get(qpidNoLocal);
+    noLocal = getBoolSetting(_settings, qpidNoLocal);
     QPID_LOG(debug, "Configured queue " << getName() << " with no-local=" << 
noLocal);
 
     std::string lvqKey = _settings.getAsString(qpidLastValueQueueKey);
@@ -991,11 +1016,11 @@ void Queue::configureImpl(const FieldTab
         QPID_LOG(debug, "Configured queue " <<  getName() << " as Last Value 
Queue with key " << lvqKey);
         messages = std::auto_ptr<Messages>(new MessageMap(lvqKey));
         allocator = boost::shared_ptr<MessageDistributor>(new FifoDistributor( 
*messages ));
-    } else if (_settings.get(qpidLastValueQueueNoBrowse)) {
+    } else if (getBoolSetting(_settings, qpidLastValueQueueNoBrowse)) {
         QPID_LOG(debug, "Configured queue " <<  getName() << " as Legacy Last 
Value Queue with 'no-browse' on");
         messages = LegacyLVQ::updateOrReplace(messages, qpidVQMatchProperty, 
true, broker);
         allocator = boost::shared_ptr<MessageDistributor>(new FifoDistributor( 
*messages ));
-    } else if (_settings.get(qpidLastValueQueue)) {
+    } else if (getBoolSetting(_settings, qpidLastValueQueue)) {
         QPID_LOG(debug, "Configured queue " <<  getName() << " as Legacy Last 
Value Queue");
         messages = LegacyLVQ::updateOrReplace(messages, qpidVQMatchProperty, 
false, broker);
         allocator = boost::shared_ptr<MessageDistributor>(new FifoDistributor( 
*messages ));
@@ -1015,7 +1040,7 @@ void Queue::configureImpl(const FieldTab
         }
     }
 
-    persistLastNode= _settings.get(qpidPersistLastNode);
+    persistLastNode = getBoolSetting(_settings, qpidPersistLastNode);
     if (persistLastNode) QPID_LOG(debug, "Configured queue to Persist data if 
cluster fails to one node for: " << getName());
 
     traceId = _settings.getAsString(qpidTraceIdentity);



---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project:      http://qpid.apache.org
Use/Interact: mailto:commits-subscr...@qpid.apache.org

Reply via email to