From 9e115470654bf67fbb4720ab3bfb3768b9331e55 Mon Sep 17 00:00:00 2001 From: Alan Conway Date: Thu, 26 Jun 2008 21:39:28 +0000 Subject: Plugin framework change: single PluginFactory creates per-target Plugin instances. git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@672032 13f79535-47bb-0310-9956-ffa450edef68 --- cpp/src/qpid/cluster/ClusterPlugin.cpp | 59 ++++++++++++++++++++++------------ 1 file changed, 38 insertions(+), 21 deletions(-) (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 ceafa389b0..a638f509c6 100644 --- a/cpp/src/qpid/cluster/ClusterPlugin.cpp +++ b/cpp/src/qpid/cluster/ClusterPlugin.cpp @@ -33,47 +33,64 @@ namespace qpid { namespace cluster { using namespace std; +using broker::Broker; -struct ClusterOptions : public Options { +struct OptionValues { string name; string url; - ClusterOptions() : Options("Cluster Options") { + Url getUrl(uint16_t port) const { + if (url.empty()) return Url::getIpAddressesUrl(port); + return Url(url); + } +}; + +// Note we update the values in a separate struct. +// This is to work around boost::program_options differences, +// older versions took a reference to the options, newer +// ones take a copy (or require a shared_ptr) +// +struct ClusterOptions : public Options { + + ClusterOptions(OptionValues* v) : Options("Cluster Options") { addOptions() - ("cluster-name", optValue(name, "NAME"), "Name of cluster to join") - ("cluster-url", optValue(url,"URL"), + ("cluster-name", optValue(v->name, "NAME"), "Name of cluster to join") + ("cluster-url", optValue(v->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 PluginT { + OptionValues values; + boost::optional cluster; + + ClusterPlugin(const OptionValues& v) : values(v) {} + + void initializeT(Broker& broker) { + cluster = boost::in_place(values.name, values.getUrl(broker.getPort()), boost::ref(broker)); + broker.getSessionManager().add(cluster->getObserver()); } }; -struct ClusterPlugin : public Plugin { +struct PluginFactory : public Plugin::FactoryT { + OptionValues values; ClusterOptions options; - boost::optional cluster; - Options* getOptions() { return &options; } + PluginFactory() : options(&values) {} - void earlyInitialize(Plugin::Target&) {} + Options* getOptions() { return &options; } - void initialize(Plugin::Target& target) { - broker::Broker* broker = dynamic_cast(&target); + boost::shared_ptr createT(Broker&) { // Only provide to a Broker, and only if the --cluster config is set. - if (broker && !options.name.empty()) { - assert(!cluster); // A process can only belong to one cluster. - cluster = boost::in_place(options.name, - options.getUrl(broker->getPort()), - boost::ref(*broker)); - broker->getSessionManager().add(cluster->getObserver()); - } + if (values.name.empty()) + return boost::shared_ptr(); + else + return make_shared_ptr(new ClusterPlugin(values)); } }; -static ClusterPlugin instance; // Static initialization. +static PluginFactory instance; // Static initialization. }} // namespace qpid::cluster -- cgit v1.2.1