You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by ac...@apache.org on 2009/01/16 22:34:02 UTC
svn commit: r735150 - in /qpid/trunk/qpid/cpp/src/qpid/cluster:
PollerDispatch.cpp PollerDispatch.h ThreadDispatch.cpp ThreadDispatch.h
Author: aconway
Date: Fri Jan 16 13:34:01 2009
New Revision: 735150
URL: http://svn.apache.org/viewvc?rev=735150&view=rev
Log:
cluster refactor: separate out dispatch strategy, implement poller and thread dispatch.
Added:
qpid/trunk/qpid/cpp/src/qpid/cluster/PollerDispatch.cpp (with props)
qpid/trunk/qpid/cpp/src/qpid/cluster/PollerDispatch.h (with props)
qpid/trunk/qpid/cpp/src/qpid/cluster/ThreadDispatch.cpp (with props)
qpid/trunk/qpid/cpp/src/qpid/cluster/ThreadDispatch.h (with props)
Added: qpid/trunk/qpid/cpp/src/qpid/cluster/PollerDispatch.cpp
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/qpid/cluster/PollerDispatch.cpp?rev=735150&view=auto
==============================================================================
--- qpid/trunk/qpid/cpp/src/qpid/cluster/PollerDispatch.cpp (added)
+++ qpid/trunk/qpid/cpp/src/qpid/cluster/PollerDispatch.cpp Fri Jan 16 13:34:01 2009
@@ -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
Propchange: qpid/trunk/qpid/cpp/src/qpid/cluster/PollerDispatch.cpp
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: qpid/trunk/qpid/cpp/src/qpid/cluster/PollerDispatch.cpp
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: qpid/trunk/qpid/cpp/src/qpid/cluster/PollerDispatch.h
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/qpid/cluster/PollerDispatch.h?rev=735150&view=auto
==============================================================================
--- qpid/trunk/qpid/cpp/src/qpid/cluster/PollerDispatch.h (added)
+++ qpid/trunk/qpid/cpp/src/qpid/cluster/PollerDispatch.h Fri Jan 16 13:34:01 2009
@@ -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*/
Propchange: qpid/trunk/qpid/cpp/src/qpid/cluster/PollerDispatch.h
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: qpid/trunk/qpid/cpp/src/qpid/cluster/PollerDispatch.h
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: qpid/trunk/qpid/cpp/src/qpid/cluster/ThreadDispatch.cpp
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/qpid/cluster/ThreadDispatch.cpp?rev=735150&view=auto
==============================================================================
--- qpid/trunk/qpid/cpp/src/qpid/cluster/ThreadDispatch.cpp (added)
+++ qpid/trunk/qpid/cpp/src/qpid/cluster/ThreadDispatch.cpp Fri Jan 16 13:34:01 2009
@@ -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
Propchange: qpid/trunk/qpid/cpp/src/qpid/cluster/ThreadDispatch.cpp
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: qpid/trunk/qpid/cpp/src/qpid/cluster/ThreadDispatch.cpp
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: qpid/trunk/qpid/cpp/src/qpid/cluster/ThreadDispatch.h
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/qpid/cluster/ThreadDispatch.h?rev=735150&view=auto
==============================================================================
--- qpid/trunk/qpid/cpp/src/qpid/cluster/ThreadDispatch.h (added)
+++ qpid/trunk/qpid/cpp/src/qpid/cluster/ThreadDispatch.h Fri Jan 16 13:34:01 2009
@@ -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*/
Propchange: qpid/trunk/qpid/cpp/src/qpid/cluster/ThreadDispatch.h
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: qpid/trunk/qpid/cpp/src/qpid/cluster/ThreadDispatch.h
------------------------------------------------------------------------------
svn:keywords = Rev Date