summaryrefslogtreecommitdiff
path: root/cpp/src/qpid/cluster/ChannelManager.cpp
diff options
context:
space:
mode:
authorAlan Conway <aconway@apache.org>2007-06-29 17:59:00 +0000
committerAlan Conway <aconway@apache.org>2007-06-29 17:59:00 +0000
commitfda6dadde945a9c73c97b73dc79e93368b743348 (patch)
treed7755539ae485efdfbc46298cd1ef6632515159e /cpp/src/qpid/cluster/ChannelManager.cpp
parent79cd6c772da003ddc917eff362f9adaa99e28b49 (diff)
downloadqpid-python-fda6dadde945a9c73c97b73dc79e93368b743348.tar.gz
* Summary:
- Improved plugin framework and HandlerUpdater interface. - Cluster handlers for traffic to/from cluster. - Cluster HandlerUpdater configures channel chains for cluster. - Cluster PluginProvider registers cluster objects with broker. * src/qpid/framing/AMQFrame.h: Made data members public. Handlers need to be able to modify frame data, getters/setters are just a nuisance here. * src/tests/Cluster.cpp: Updated for cluster changes, using handlers instead of friendship to hook test into Cluster code. * src/qpid/framing/amqp_types.h: Added CHANNEL_MAX and CHANNEL_HIGH_BIT constants. * src/qpid/framing/HandlerUpdater.h: Renamed ChannelInitializer, broke dependency on broker channel types. * src/qpid/framing/Handler.h: Added constructors and nextHandler() * src/qpid/framing/AMQFrame.h (class AMQFrame): Inlined getChannel() * src/qpid/cluster/ClusterPluginProvider.cpp: Provider for cluster plugins. * src/qpid/cluster/Cluster.cpp: Use ChannelManager. Factor out plugin details to ClusterPluginProvider. * src/qpid/cluster/ChannelManager.h: Insert cluster handlers into channel chains, route frames between cluster and channels. * src/qpid/broker/BrokerAdapter.cpp (startOk): use CHANNEL_MAX constant. * src/qpid/broker/Broker.cpp: - Refactored for new plugin framework. - Added getUrl(). * src/qpid/Url.h: Added constructor from Address. * src/qpid/Plugin.h: Generalized plugin framework, broke dependency on Broker interfaces. We may want to use plug-ins for clients also at some point. * src/tests/run_test: Fix bug when VALGRIND is not set. git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@551981 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp/src/qpid/cluster/ChannelManager.cpp')
-rw-r--r--cpp/src/qpid/cluster/ChannelManager.cpp85
1 files changed, 85 insertions, 0 deletions
diff --git a/cpp/src/qpid/cluster/ChannelManager.cpp b/cpp/src/qpid/cluster/ChannelManager.cpp
new file mode 100644
index 0000000000..f573d78ca1
--- /dev/null
+++ b/cpp/src/qpid/cluster/ChannelManager.cpp
@@ -0,0 +1,85 @@
+/*
+ *
+ * Copyright (c) 2006 The Apache Software Foundation
+ *
+ * Licensed 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 "qpid/log/Statement.h"
+#include "qpid/framing/amqp_types.h"
+#include "qpid/framing/AMQFrame.h"
+#include "ChannelManager.h"
+
+namespace qpid {
+namespace cluster {
+
+using namespace framing;
+
+/** Handler to multicast to the cluster */
+struct ClusterHandler : public FrameHandler {
+
+ ClusterHandler(FrameHandler::Chain next, ChannelId bitmask_)
+ : FrameHandler(next), bitmask(bitmask_) {}
+
+ void handle(AMQFrame& frame) {
+ frame.channel |= bitmask; // Mark the frame
+ nextHandler(frame);
+ // TODO aconway 2007-06-28: Right now everything is backed up
+ // via multicast. When we have point-to-point backups this
+ // function must determine where each frame should be sent: to
+ // multicast or only to specific backup(s) via AMQP.
+ }
+
+ ChannelId bitmask;
+};
+
+ChannelManager::ChannelManager(FrameHandler::Chain mcast) : mcastOut(mcast){}
+
+void ChannelManager::update(ChannelId id, FrameHandler::Chains& chains) {
+ // Store the original cluster chains for the channel.
+ channels[id] = chains;
+
+ // Replace chains with multicast-to-cluster handlers that mark the
+ // high-bit of the channel ID on outgoing frames so we can tell
+ // them from incoming frames in handle()
+ //
+ // When handle() receives the frames from the cluster it
+ // will forward them to the original channel chains stored in
+ // channels map.
+ //
+ chains.in = make_shared_ptr(new ClusterHandler(mcastOut, 0));
+ chains.out= make_shared_ptr(new ClusterHandler(mcastOut, CHANNEL_HIGH_BIT));
+}
+
+void ChannelManager::handle(AMQFrame& frame) {
+ bool isOut = frame.channel | CHANNEL_HIGH_BIT;
+ frame.channel |= ~CHANNEL_HIGH_BIT; // Clear the bit.
+ ChannelMap::iterator i = channels.find(frame.getChannel());
+ if (i != channels.end()) {
+ Chain& chain = isOut ? i->second.out : i->second.in;
+ chain->handle(frame);
+ }
+ else
+ updateFailoverState(frame);
+}
+
+void ChannelManager::updateFailoverState(AMQFrame& ) {
+ QPID_LOG(critical, "Failover is not implemented");
+ // FIXME aconway 2007-06-28:
+ // If the channel is not in my map then I'm not primary so
+ // I don't pass the frame to the channel handler but I
+ // do need to update the session failover state.
+}
+
+}} // namespace qpid::cluster