summaryrefslogtreecommitdiff
path: root/qpid/cpp
diff options
context:
space:
mode:
authorAlan Conway <aconway@apache.org>2009-01-16 21:34:01 +0000
committerAlan Conway <aconway@apache.org>2009-01-16 21:34:01 +0000
commit6f5510b30bdb1dadafef8b49b61bea61d9aeb3a5 (patch)
tree9ff8846c041858ba778948f114b28cd20d0c3d4b /qpid/cpp
parent06bbe3a94cf4a6a8ed0626f00d96249a6a67ae98 (diff)
downloadqpid-python-6f5510b30bdb1dadafef8b49b61bea61d9aeb3a5.tar.gz
cluster refactor: separate out dispatch strategy, implement poller and thread dispatch.
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@735150 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'qpid/cpp')
-rw-r--r--qpid/cpp/src/qpid/cluster/PollerDispatch.cpp60
-rw-r--r--qpid/cpp/src/qpid/cluster/PollerDispatch.h56
-rw-r--r--qpid/cpp/src/qpid/cluster/ThreadDispatch.cpp53
-rw-r--r--qpid/cpp/src/qpid/cluster/ThreadDispatch.h53
4 files changed, 222 insertions, 0 deletions
diff --git a/qpid/cpp/src/qpid/cluster/PollerDispatch.cpp b/qpid/cpp/src/qpid/cluster/PollerDispatch.cpp
new file mode 100644
index 0000000000..528a21481c
--- /dev/null
+++ b/qpid/cpp/src/qpid/cluster/PollerDispatch.cpp
@@ -0,0 +1,60 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+#include "PollerDispatch.h"
+
+#include "qpid/log/Statement.h"
+#include <boost/bind.hpp>
+
+namespace qpid {
+namespace cluster {
+
+PollerDispatch::PollerDispatch(Cpg& c, boost::shared_ptr<sys::Poller> p,
+ boost::function<void()> e)
+ : cpg(c), poller(p), onError(e),
+ dispatchHandle(cpg,
+ boost::bind(&PollerDispatch::dispatch, this, _1), // read
+ 0, // write
+ boost::bind(&PollerDispatch::disconnect, this, _1) // disconnect
+ )
+{}
+
+void PollerDispatch::start() {
+ dispatchHandle.startWatch(poller);
+}
+
+// Entry point: called by IO to dispatch CPG events.
+void PollerDispatch::dispatch(sys::DispatchHandle& h) {
+ try {
+ cpg.dispatchAll();
+ h.rewatch();
+ } catch (const std::exception& e) {
+ QPID_LOG(critical, "Error in cluster dispatch: " << e.what());
+ onError();
+ }
+}
+
+// Entry point: called if disconnected from CPG.
+void PollerDispatch::disconnect(sys::DispatchHandle& ) {
+ QPID_LOG(critical, "Disconnected from cluster");
+ onError();
+}
+
+}} // namespace qpid::cluster
diff --git a/qpid/cpp/src/qpid/cluster/PollerDispatch.h b/qpid/cpp/src/qpid/cluster/PollerDispatch.h
new file mode 100644
index 0000000000..24b3496eb5
--- /dev/null
+++ b/qpid/cpp/src/qpid/cluster/PollerDispatch.h
@@ -0,0 +1,56 @@
+#ifndef QPID_CLUSTER_POLLERDISPATCH_H
+#define QPID_CLUSTER_POLLERDISPATCH_H
+
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+#include "Cpg.h"
+#include "qpid/sys/Poller.h"
+#include "qpid/sys/DispatchHandle.h"
+#include <boost/function.hpp>
+
+namespace qpid {
+namespace cluster {
+
+/**
+ * Dispatch CPG events via the poller.
+ */
+class PollerDispatch {
+ public:
+ PollerDispatch(Cpg&, boost::shared_ptr<sys::Poller> poller,
+ boost::function<void()> onError) ;
+ void start();
+
+ private:
+ // Poller callbacks
+ void dispatch(sys::DispatchHandle&); // Dispatch CPG events.
+ void disconnect(sys::DispatchHandle&); // CPG was disconnected
+
+ Cpg& cpg;
+ boost::shared_ptr<sys::Poller> poller;
+ boost::function<void()> onError;
+ sys::DispatchHandle dispatchHandle;
+
+
+};
+}} // namespace qpid::cluster
+
+#endif /*!QPID_CLUSTER_POLLERDISPATCH_H*/
diff --git a/qpid/cpp/src/qpid/cluster/ThreadDispatch.cpp b/qpid/cpp/src/qpid/cluster/ThreadDispatch.cpp
new file mode 100644
index 0000000000..2f3f27f834
--- /dev/null
+++ b/qpid/cpp/src/qpid/cluster/ThreadDispatch.cpp
@@ -0,0 +1,53 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+#include "ThreadDispatch.h"
+
+#include "qpid/log/Statement.h"
+#include <boost/bind.hpp>
+
+namespace qpid {
+namespace cluster {
+
+ThreadDispatch::ThreadDispatch(Cpg& c, boost::shared_ptr<sys::Poller>,
+ boost::function<void()> e)
+ : cpg(c), onError(e)
+{}
+
+ThreadDispatch::~ThreadDispatch() {
+ // FIXME aconway 2009-01-16: leaking thread. problems with Shutdown.
+ // thread.join();
+}
+
+void ThreadDispatch::start() {
+ thread = sys::Thread(static_cast<Runnable*>(this));
+}
+
+// Entry point: called by IO to dispatch CPG events.
+void ThreadDispatch::run() {
+ try {
+ cpg.dispatchBlocking();
+ } catch (const std::exception& e) {
+ QPID_LOG(critical, "Error in cluster dispatch: " << e.what());
+ onError();
+ }
+}
+
+}} // namespace qpid::cluster
diff --git a/qpid/cpp/src/qpid/cluster/ThreadDispatch.h b/qpid/cpp/src/qpid/cluster/ThreadDispatch.h
new file mode 100644
index 0000000000..03038ea91b
--- /dev/null
+++ b/qpid/cpp/src/qpid/cluster/ThreadDispatch.h
@@ -0,0 +1,53 @@
+#ifndef QPID_CLUSTER_THREADDISPATCH_H
+#define QPID_CLUSTER_THREADDISPATCH_H
+
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+#include "Cpg.h"
+#include "qpid/sys/Thread.h"
+#include "qpid/sys/Runnable.h"
+#include "qpid/sys/Poller.h"
+#include <boost/function.hpp>
+
+namespace qpid {
+namespace cluster {
+
+/**
+ * Dispatch CPG events in a dedicated thread.
+ */
+class ThreadDispatch : private sys::Runnable {
+ public:
+ ThreadDispatch(Cpg&, boost::shared_ptr<sys::Poller>, boost::function<void()> onError) ;
+ ~ThreadDispatch();
+
+ void start();
+
+ private:
+
+ Cpg& cpg;
+ sys::Thread thread;
+ boost::function<void()> onError;
+ void run();
+};
+}} // namespace qpid::cluster
+
+#endif /*!QPID_CLUSTER_THREADDISPATCH_H*/