summaryrefslogtreecommitdiff
path: root/cpp/src/qpid/ha/ConnectionObserver.cpp
diff options
context:
space:
mode:
authorAlan Conway <aconway@apache.org>2012-06-12 21:19:48 +0000
committerAlan Conway <aconway@apache.org>2012-06-12 21:19:48 +0000
commitc9fc98ae80a5d8c4f58541f9738aa975723ff3d6 (patch)
tree0d10d97ca0e884db6106870b503b2d044cd77a88 /cpp/src/qpid/ha/ConnectionObserver.cpp
parentacb2762118591c4f26d189fa4c0c284026222ccd (diff)
downloadqpid-python-c9fc98ae80a5d8c4f58541f9738aa975723ff3d6.tar.gz
QPID-3603: Separate QueueGuard from ReplicatingSubscription.
QueueGuard: implements QueueObserver to delay completion of new messages. ReplicatingSubscription: Implements subscription, sends messages & events to backup. These were previously combined as one. QueueGuard is now separated out so that it can be created before the ReplicatingSubscription, in anticipation of an expected backup connecting. This is needed for 2 reasons: - new queues must be guarded until they are backuped up. - after a failover, all queues must be guarded until backups are ready. git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk/qpid@1349538 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp/src/qpid/ha/ConnectionObserver.cpp')
-rw-r--r--cpp/src/qpid/ha/ConnectionObserver.cpp75
1 files changed, 75 insertions, 0 deletions
diff --git a/cpp/src/qpid/ha/ConnectionObserver.cpp b/cpp/src/qpid/ha/ConnectionObserver.cpp
new file mode 100644
index 0000000000..694a253fc3
--- /dev/null
+++ b/cpp/src/qpid/ha/ConnectionObserver.cpp
@@ -0,0 +1,75 @@
+/*
+ *
+ * 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 "ConnectionObserver.h"
+#include "BrokerInfo.h"
+#include "qpid/framing/FieldTable.h"
+#include "qpid/broker/Connection.h"
+#include "qpid/log/Statement.h"
+
+namespace qpid {
+namespace ha {
+
+ConnectionObserver::ConnectionObserver(const types::Uuid& uuid)
+ : logPrefix("HA: "), self(uuid) {}
+
+bool ConnectionObserver::getBrokerInfo(broker::Connection& connection, BrokerInfo& info) {
+ framing::FieldTable ft;
+ if (connection.getClientProperties().getTable(ConnectionObserver::BACKUP_TAG, ft)) {
+ info = BrokerInfo(ft);
+ return true;
+ }
+ return false;
+}
+
+void ConnectionObserver::setObserver(const ObserverPtr& o){
+ sys::Mutex::ScopedLock l(lock);
+ observer = o;
+}
+
+ConnectionObserver::ObserverPtr ConnectionObserver::getObserver() {
+ sys::Mutex::ScopedLock l(lock);
+ return observer;
+}
+
+void ConnectionObserver::opened(broker::Connection& connection) {
+ if (connection.isLink()) return; // Allow outgoing links.
+ if (connection.getClientProperties().isSet(ADMIN_TAG)) {
+ QPID_LOG(debug, logPrefix << "Allowing admin connection: "
+ << connection.getMgmtId());
+ return; // No need to call observer, always allow admins.
+ }
+ BrokerInfo info; // Avoid self connections.
+ if (getBrokerInfo(connection, info) && info.getSystemId() == self)
+ throw Exception("HA rejected self connection");
+ ObserverPtr o(getObserver());
+ if (o) o->opened(connection);
+}
+
+void ConnectionObserver::closed(broker::Connection& connection) {
+ ObserverPtr o(getObserver());
+ if (o) o->closed(connection);
+}
+
+const std::string ConnectionObserver::ADMIN_TAG="qpid.ha-admin";
+const std::string ConnectionObserver::BACKUP_TAG="qpid.ha-backup";
+
+}} // namespace qpid::ha