summaryrefslogtreecommitdiff
path: root/cpp
diff options
context:
space:
mode:
authorTed Ross <tross@apache.org>2009-06-16 18:41:58 +0000
committerTed Ross <tross@apache.org>2009-06-16 18:41:58 +0000
commite79f8a1242e5e626db2784ae48ef31a433e7a7d4 (patch)
treee82bae8f2c33b85265f8079dcb1b715f575d24ff /cpp
parentd80a6773fc179cbbaf7a13dd6a8e4c66bebe4455 (diff)
downloadqpid-python-e79f8a1242e5e626db2784ae48ef31a433e7a7d4.tar.gz
Minor cleanup of the new management-failover example.
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk/qpid@785339 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp')
-rw-r--r--cpp/examples/qmf-console/cluster-qmon.cpp21
1 files changed, 15 insertions, 6 deletions
diff --git a/cpp/examples/qmf-console/cluster-qmon.cpp b/cpp/examples/qmf-console/cluster-qmon.cpp
index 4ee2ce1edd..fe92f8a8ae 100644
--- a/cpp/examples/qmf-console/cluster-qmon.cpp
+++ b/cpp/examples/qmf-console/cluster-qmon.cpp
@@ -43,6 +43,11 @@ using qpid::sys::Mutex;
//==============================================================
// Main program
//==============================================================
+
+//
+// The Main class extends ConsoleListener so it can receive broker connected/disconnected
+// notifications.
+//
class Main : public ConsoleListener {
bool stopping; // Used to tell the program to exit
Mutex lock; // Mutex to protect the broker-map
@@ -84,11 +89,12 @@ public:
// Connect to the brokers.
//
for (int idx = 1; idx < argc; idx++) {
- Mutex::ScopedLock l(lock);
qpid::client::ConnectionSettings connSettings;
connSettings.host = "localhost";
connSettings.port = atoi(argv[idx]);
Broker* broker = sm.addBroker(connSettings);
+
+ Mutex::ScopedLock l(lock);
brokerMap[broker] = false; // initially assume broker is disconnected
}
@@ -100,11 +106,14 @@ public:
// Find an operational broker
//
Broker* operationalBroker = 0;
- for (map<Broker*, bool>::iterator iter = brokerMap.begin();
- iter != brokerMap.end(); iter++) {
- if (iter->second) {
- operationalBroker = iter->first;
- break;
+ {
+ Mutex::ScopedLock l(lock);
+ for (map<Broker*, bool>::iterator iter = brokerMap.begin();
+ iter != brokerMap.end(); iter++) {
+ if (iter->second) {
+ operationalBroker = iter->first;
+ break;
+ }
}
}