From b849efb083c88de6c1932d0f7a87a7c500dbd3d6 Mon Sep 17 00:00:00 2001 From: Gordon Sim Date: Fri, 23 Jan 2009 21:55:15 +0000 Subject: Use special management ids for objects used in state transfer to new members. This prevents the ids getting out of sync across the cluster and allows management methods to be used reliably. git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk/qpid@737203 13f79535-47bb-0310-9956-ffa450edef68 --- cpp/src/qpid/cluster/ClusterPlugin.cpp | 56 ++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) (limited to 'cpp/src/qpid/cluster/ClusterPlugin.cpp') diff --git a/cpp/src/qpid/cluster/ClusterPlugin.cpp b/cpp/src/qpid/cluster/ClusterPlugin.cpp index 6e1d275162..79c34d6873 100644 --- a/cpp/src/qpid/cluster/ClusterPlugin.cpp +++ b/cpp/src/qpid/cluster/ClusterPlugin.cpp @@ -21,13 +21,21 @@ #include "qpid/cluster/Cluster.h" #include "qpid/cluster/ConnectionCodec.h" +#include "qpid/cluster/DumpClient.h" #include "qpid/broker/Broker.h" #include "qpid/Plugin.h" #include "qpid/Options.h" #include "qpid/shared_ptr.h" +#include "qpid/sys/AtomicValue.h" #include "qpid/log/Statement.h" +#include "qpid/management/ManagementBroker.h" +#include "qpid/management/IdAllocator.h" +#include "qpid/broker/Exchange.h" +#include "qpid/broker/Queue.h" +#include "qpid/broker/SessionState.h" + #include #include @@ -36,6 +44,9 @@ namespace cluster { using namespace std; using broker::Broker; +using management::IdAllocator; +using management::ManagementAgent; +using management::ManagementBroker; struct ClusterValues { string name; @@ -76,6 +87,46 @@ struct ClusterOptions : public Options { } }; +struct DumpClientIdAllocator : management::IdAllocator +{ + qpid::sys::AtomicValue sequence; + + DumpClientIdAllocator() : sequence(0x4000000000000000LL) {} + + uint64_t getIdFor(management::Manageable* m) + { + if (isDumpQueue(m) || isDumpExchange(m) || isDumpSession(m) || isDumpBinding(m)) { + return ++sequence; + } else { + return 0; + } + } + + bool isDumpQueue(management::Manageable* manageable) + { + qpid::broker::Queue* queue = dynamic_cast(manageable); + return queue && queue->getName() == DumpClient::DUMP; + } + + bool isDumpExchange(management::Manageable* manageable) + { + qpid::broker::Exchange* exchange = dynamic_cast(manageable); + return exchange && exchange->getName() == DumpClient::DUMP; + } + + bool isDumpSession(management::Manageable* manageable) + { + broker::SessionState* session = dynamic_cast(manageable); + return session && session->getId().getName() == DumpClient::DUMP; + } + + bool isDumpBinding(management::Manageable* manageable) + { + broker::Exchange::Binding* binding = dynamic_cast(manageable); + return binding && binding->queue->getName() == DumpClient::DUMP; + } +}; + struct ClusterPlugin : public Plugin { ClusterValues values; @@ -102,6 +153,11 @@ struct ClusterPlugin : public Plugin { boost::shared_ptr( new ConnectionCodec::Factory(broker->getConnectionFactory(), *cluster))); broker->getExchanges().registerExchange(cluster->getFailoverExchange()); + ManagementBroker* mgmt = dynamic_cast(ManagementAgent::Singleton::getInstance()); + if (mgmt) { + std::auto_ptr allocator(new DumpClientIdAllocator()); + mgmt->setAllocator(allocator); + } } void earlyInitialize(Plugin::Target&) {} -- cgit v1.2.1