summaryrefslogtreecommitdiff
path: root/cpp/src/qpid/sys
diff options
context:
space:
mode:
authorAlan Conway <aconway@apache.org>2010-01-27 22:20:51 +0000
committerAlan Conway <aconway@apache.org>2010-01-27 22:20:51 +0000
commit1297c818282f26838776df418d846e07457a7f7f (patch)
treed69c3b15f76b9d83a62462df3ca5211a45be7a4b /cpp/src/qpid/sys
parentd0df2e739d5fba4bfb9f549720518e55d6fa9c9c (diff)
downloadqpid-python-1297c818282f26838776df418d846e07457a7f7f.tar.gz
Added PeriodicTimer interface for periodic tasks that need cluster synchronization.
The ManagementAgent's periodic prociessing uses PeriodicTimer. PeriodicTimerImpl is the default implementation for stand-alone brokers, simple wrapper for sys::Timer. git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk/qpid@903866 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp/src/qpid/sys')
-rw-r--r--cpp/src/qpid/sys/PeriodicTimer.h56
-rw-r--r--cpp/src/qpid/sys/PeriodicTimerImpl.cpp49
-rw-r--r--cpp/src/qpid/sys/PeriodicTimerImpl.h45
-rw-r--r--cpp/src/qpid/sys/Timer.h6
4 files changed, 156 insertions, 0 deletions
diff --git a/cpp/src/qpid/sys/PeriodicTimer.h b/cpp/src/qpid/sys/PeriodicTimer.h
new file mode 100644
index 0000000000..290ffb6218
--- /dev/null
+++ b/cpp/src/qpid/sys/PeriodicTimer.h
@@ -0,0 +1,56 @@
+#ifndef QPID_SYS_PERIODICTIMER_H
+#define QPID_SYS_PERIODICTIMER_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 "Timer.h"
+#include <boost/function.hpp>
+
+namespace qpid {
+namespace sys {
+
+/**
+ * Interface of a timer for periodic tasks that should be synchronized
+ * across all brokers in a periodic. The standalone broker
+ * implementation simply wraps qpid::sys::Timer. The clustered broker
+ * implementation synchronizes execution of periodic tasks on all
+ * periodic members.
+ */
+class PeriodicTimer
+{
+ public:
+ typedef boost::function<void()> Task;
+
+ QPID_COMMON_EXTERN virtual ~PeriodicTimer() {}
+
+ /**
+ * Add a named task to be executed at the given period.
+ *
+ * The task registered under the same name will be executed on
+ * all brokers at the given period.
+ */
+ virtual void add(const Task& task, Duration period, const std::string& taskName) = 0;
+
+};
+}} // namespace qpid::sys
+
+#endif /*!QPID_SYS_PERIODICTIMER_H*/
diff --git a/cpp/src/qpid/sys/PeriodicTimerImpl.cpp b/cpp/src/qpid/sys/PeriodicTimerImpl.cpp
new file mode 100644
index 0000000000..e2a6dccf3e
--- /dev/null
+++ b/cpp/src/qpid/sys/PeriodicTimerImpl.cpp
@@ -0,0 +1,49 @@
+/*
+ *
+ * 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 "PeriodicTimerImpl.h"
+
+namespace qpid {
+namespace sys {
+
+PeriodicTimerImpl::PeriodicTimerImpl(Timer& t) : timer(t) {}
+
+struct PeriodicTimerImpl::TaskImpl : public TimerTask {
+ Timer& timer;
+ Task task;
+
+ TaskImpl(Timer& timer_, const Task& task_, Duration period) :
+ TimerTask(period), timer(timer_), task(task_) {}
+
+ void fire() {
+ task();
+ setupNextFire();
+ timer.add(this);
+ }
+};
+
+void PeriodicTimerImpl::add(
+ const Task& task, Duration period, const std::string& /*taskName*/
+)
+{
+ timer.add(new TaskImpl(timer, task, period));
+}
+
+}} // namespace qpid::sys
diff --git a/cpp/src/qpid/sys/PeriodicTimerImpl.h b/cpp/src/qpid/sys/PeriodicTimerImpl.h
new file mode 100644
index 0000000000..51ce0ffdf9
--- /dev/null
+++ b/cpp/src/qpid/sys/PeriodicTimerImpl.h
@@ -0,0 +1,45 @@
+#ifndef QPID_SYS_PERIODICTIMERIMPL_H
+#define QPID_SYS_PERIODICTIMERIMPL_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 "PeriodicTimer.h"
+
+namespace qpid {
+namespace sys {
+
+/**
+ * Standalone broker implementation of PeriodicTimer.
+ */
+class PeriodicTimerImpl : public PeriodicTimer
+{
+ public:
+ PeriodicTimerImpl(Timer& timer);
+ void add(const Task& task, Duration period, const std::string& taskName);
+
+ private:
+ struct TaskImpl;
+ Timer& timer;
+};
+}} // namespace qpid::sys
+
+#endif /*!QPID_SYS_PERIODICTIMER_H*/
diff --git a/cpp/src/qpid/sys/Timer.h b/cpp/src/qpid/sys/Timer.h
index 5748503841..303d44a299 100644
--- a/cpp/src/qpid/sys/Timer.h
+++ b/cpp/src/qpid/sys/Timer.h
@@ -69,6 +69,12 @@ protected:
bool operator<(const boost::intrusive_ptr<TimerTask>& a,
const boost::intrusive_ptr<TimerTask>& b);
+/**
+ A timer to trigger tasks that are local to one broker.
+
+ For periodic tasks that should be synchronized across all brokers
+ in a cluster, use qpid::sys::PeriodicTimer.
+ */
class Timer : private Runnable {
qpid::sys::Monitor monitor;
std::priority_queue<boost::intrusive_ptr<TimerTask> > tasks;