From df599b1716535909317e61f4b43516d48373ad1c Mon Sep 17 00:00:00 2001 From: Alan Conway Date: Fri, 1 Feb 2008 16:03:02 +0000 Subject: Added cluster URL configuration, defaults to all interfaces. src/qpid/Plugin.h - added doxygen src/qpid/Url.cpp,.h - cache string rep, op==, istream/ostream ops. src/qpid/broker/Broker.h,.cpp - removed getUrl() src/qpid/cluster/Cluster.h,.cpp - use Url class src/qpid/cluster/ClusterPlugin.cpp - added --url configuration. git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@617533 13f79535-47bb-0310-9956-ffa450edef68 --- cpp/src/qpid/cluster/Cluster.cpp | 6 ++--- cpp/src/qpid/cluster/Cluster.h | 10 +++++---- cpp/src/qpid/cluster/ClusterPlugin.cpp | 40 ++++++++++++++++++++++++---------- 3 files changed, 37 insertions(+), 19 deletions(-) (limited to 'cpp/src/qpid/cluster') diff --git a/cpp/src/qpid/cluster/Cluster.cpp b/cpp/src/qpid/cluster/Cluster.cpp index ce87d23c0d..49270bcfef 100644 --- a/cpp/src/qpid/cluster/Cluster.cpp +++ b/cpp/src/qpid/cluster/Cluster.cpp @@ -47,7 +47,7 @@ ostream& operator <<(ostream& out, const Cluster::MemberMap& members) { return out; } -Cluster::Cluster(const std::string& name_, const std::string& url_, broker::Broker&) : +Cluster::Cluster(const std::string& name_, const Url& url_, broker::Broker&) : FrameHandler(0), // FIXME aconway 2008-01-29: handler. + observer cpg(*this), name(name_), @@ -87,7 +87,7 @@ void Cluster::handle(AMQFrame& frame) { } void Cluster::notify() { - AMQFrame frame(in_place(ProtocolVersion(), url)); + AMQFrame frame(in_place(ProtocolVersion(), url.str())); handle(frame); } @@ -143,7 +143,7 @@ void Cluster::handleClusterFrame(Id from, AMQFrame& frame) { { Mutex::ScopedLock l(lock); members[from].url=notifyIn->getUrl(); - if (!self.id && notifyIn->getUrl() == url) + if (!self.id && notifyIn->getUrl() == url.str()) self=from; lock.notifyAll(); QPID_LOG(trace, *this << ": members joined: " << members); diff --git a/cpp/src/qpid/cluster/Cluster.h b/cpp/src/qpid/cluster/Cluster.h index 5aca3faf44..e9809f2264 100644 --- a/cpp/src/qpid/cluster/Cluster.h +++ b/cpp/src/qpid/cluster/Cluster.h @@ -27,6 +27,8 @@ #include "qpid/sys/Runnable.h" #include "qpid/sys/Thread.h" #include "qpid/log/Logger.h" +#include "qpid/Url.h" + #include #include @@ -50,8 +52,8 @@ class Cluster : public framing::FrameHandler, public: /** Details of a cluster member */ struct Member { - Member(const std::string& url_=std::string()) : url(url_) {} - std::string url; ///< Broker address. + Member(const Url& url_=Url()) : url(url_) {} + Url url; ///< Broker address. }; typedef std::vector MemberList; @@ -61,7 +63,7 @@ class Cluster : public framing::FrameHandler, * @param name of the cluster. * @param url of this broker, sent to the cluster. */ - Cluster(const std::string& name, const std::string& url, broker::Broker&); + Cluster(const std::string& name, const Url& url, broker::Broker&); virtual ~Cluster(); @@ -115,7 +117,7 @@ class Cluster : public framing::FrameHandler, mutable sys::Monitor lock; Cpg cpg; Cpg::Name name; - std::string url; + Url url; Id self; MemberMap members; sys::Thread dispatcher; diff --git a/cpp/src/qpid/cluster/ClusterPlugin.cpp b/cpp/src/qpid/cluster/ClusterPlugin.cpp index e24c60dc2f..e6b5f1a0bd 100644 --- a/cpp/src/qpid/cluster/ClusterPlugin.cpp +++ b/cpp/src/qpid/cluster/ClusterPlugin.cpp @@ -15,6 +15,10 @@ * limitations under the License. * */ +#include + + + #include "qpid/broker/Broker.h" #include "qpid/cluster/Cluster.h" #include "qpid/Plugin.h" @@ -24,21 +28,31 @@ #include #include + namespace qpid { namespace cluster { using namespace std; -struct ClusterPlugin : public Plugin { +struct ClusterOptions : public Options { + string name; + string url; - struct ClusterOptions : public Options { - string clusterName; - ClusterOptions() : Options("Cluster Options") { - addOptions() - ("cluster", optValue(clusterName, "NAME"), - "Joins the cluster named NAME"); - } - }; + ClusterOptions() : Options("Cluster Options") { + addOptions() + ("cluster-name", optValue(name, "NAME"), "Name of cluster to join") + ("cluster-url", optValue(url,"URL"), + "URL of this broker, advertized to the cluster.\n" + "Defaults to a URL listing all the local IP addresses\n"); + } + + Url getUrl(uint16_t port) const { + if (url.empty()) return Url::getIpAddressesUrl(port); + return Url(url); + } +}; + +struct ClusterPlugin : public Plugin { ClusterOptions options; boost::optional cluster; @@ -50,10 +64,12 @@ struct ClusterPlugin : public Plugin { void initialize(Plugin::Target& target) { broker::Broker* broker = dynamic_cast(&target); // Only provide to a Broker, and only if the --cluster config is set. - if (broker && !options.clusterName.empty()) { + if (broker && !options.name.empty()) { assert(!cluster); // A process can only belong to one cluster. - cluster = boost::in_place(options.clusterName, broker->getUrl(), boost::ref(*broker)); - // broker->add(make_shared_ptr(&cluster->getHandlerUpdater(), nullDeleter)); + cluster = boost::in_place(options.name, + options.getUrl(broker->getPort()), + boost::ref(*broker)); + // FIXME aconway 2008-02-01: Add observer. } } }; -- cgit v1.2.1