diff options
Diffstat (limited to 'cpp/src/qpid/cluster/ClusterPlugin.cpp')
-rw-r--r-- | cpp/src/qpid/cluster/ClusterPlugin.cpp | 48 |
1 files changed, 20 insertions, 28 deletions
diff --git a/cpp/src/qpid/cluster/ClusterPlugin.cpp b/cpp/src/qpid/cluster/ClusterPlugin.cpp index 10695496bc..6d3dca84be 100644 --- a/cpp/src/qpid/cluster/ClusterPlugin.cpp +++ b/cpp/src/qpid/cluster/ClusterPlugin.cpp @@ -33,56 +33,48 @@ namespace qpid { namespace cluster { using namespace std; -using broker::Broker; - -// 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 { - std::string name; - std::string url; + string name; + string url; ClusterOptions() : Options("Cluster Options") { addOptions() - ("cluster-name", optValue(name,""), "Cluster identifier") + ("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") ; } -}; -struct ClusterPlugin : public PluginT<Broker> { - ClusterOptions options; - boost::optional<Cluster> cluster; - - ClusterPlugin(const ClusterOptions& opts) : options(opts) {} - - void initializeT(Broker& broker) { // FIXME aconway 2008-07-01: drop T suffix. - Url url = options.url.empty() ? Url::getIpAddressesUrl(broker.getPort()) : Url(options.url); - cluster = boost::in_place(options.name, url, boost::ref(broker)); - broker.getConnectionManager().add(cluster->getObserver()); // FIXME aconway 2008-07-01: to Cluster ctor + Url getUrl(uint16_t port) const { + if (url.empty()) return Url::getIpAddressesUrl(port); + return Url(url); } }; -struct PluginFactory : public Plugin::FactoryT<Broker> { +struct ClusterPlugin : public Plugin { ClusterOptions options; + boost::optional<Cluster> cluster; Options* getOptions() { return &options; } - boost::shared_ptr<Plugin> createT(Broker&) { - if (options.name.empty()) { // No cluster name, don't initialize cluster. - return boost::shared_ptr<Plugin>(); + void earlyInitialize(Plugin::Target&) {} + + void initialize(Plugin::Target& target) { + broker::Broker* broker = dynamic_cast<broker::Broker*>(&target); + // 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->getConnectionManager().add(cluster->getObserver()); } - else - return make_shared_ptr(new ClusterPlugin(options)); } }; -static PluginFactory instance; // Static initialization. +static ClusterPlugin instance; // Static initialization. }} // namespace qpid::cluster |