summaryrefslogtreecommitdiff
path: root/cpp/src/qpid/cluster/ClassifierHandler.cpp
diff options
context:
space:
mode:
authorAlan Conway <aconway@apache.org>2007-08-30 17:06:44 +0000
committerAlan Conway <aconway@apache.org>2007-08-30 17:06:44 +0000
commitefa3feb65f59e10a378b9074ac2d01b540a3278c (patch)
tree5cb9c87f71b6f428365e377376280d2792481b40 /cpp/src/qpid/cluster/ClassifierHandler.cpp
parentf6c5c0d464efd4a19af54cbbb68a2ae315fbfd96 (diff)
downloadqpid-python-efa3feb65f59e10a378b9074ac2d01b540a3278c.tar.gz
- Update cluster code to work with new FrameHandler
- Update ClassifierHandler to use Visitor rather than map. - Replace heap allocation in cluster classes with boost::optional. git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@571246 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp/src/qpid/cluster/ClassifierHandler.cpp')
-rw-r--r--cpp/src/qpid/cluster/ClassifierHandler.cpp61
1 files changed, 18 insertions, 43 deletions
diff --git a/cpp/src/qpid/cluster/ClassifierHandler.cpp b/cpp/src/qpid/cluster/ClassifierHandler.cpp
index fc7765eef6..a4ea257f0c 100644
--- a/cpp/src/qpid/cluster/ClassifierHandler.cpp
+++ b/cpp/src/qpid/cluster/ClassifierHandler.cpp
@@ -18,59 +18,34 @@
#include "ClassifierHandler.h"
+#include "qpid/framing/FrameDefaultVisitor.h"
#include "qpid/framing/AMQFrame.h"
-#include "qpid/framing/ExchangeDeclareBody.h"
-#include "qpid/framing/ExchangeDeleteBody.h"
-#include "qpid/framing/QueueBindBody.h"
-#include "qpid/framing/QueueDeclareBody.h"
-#include "qpid/framing/QueueDeleteBody.h"
-#include "qpid/framing/QueueUnbindBody.h"
-
namespace qpid {
namespace cluster {
using namespace framing;
-typedef uint32_t FullMethodId; // Combind class & method ID.
-
-FullMethodId fullId(ClassId c, MethodId m) { return c<<16+m; }
-
-FullMethodId fullId(const AMQMethodBody* body) {
- return fullId(body->amqpClassId(), body->amqpMethodId());
-}
-
-template <class M>
-FullMethodId fullId() { return fullId(M::CLASS_ID, M::METHOD_ID); }
+struct ClassifierHandler::Visitor : public FrameDefaultVisitor {
+ Visitor(AMQFrame& f, ClassifierHandler& c)
+ : chosen(0), frame(f), classifier(c) { f.getBody()->accept(*this); }
+ void visit(const ExchangeDeclareBody&) { chosen=&classifier.wiring; }
+ void visit(const ExchangeDeleteBody&) { chosen=&classifier.wiring; }
+ void visit(const QueueBindBody&) { chosen=&classifier.wiring; }
+ void visit(const QueueDeclareBody&) { chosen=&classifier.wiring; }
+ void visit(const QueueDeleteBody&) { chosen=&classifier.wiring; }
+ void visit(const QueueUnbindBody&) { chosen=&classifier.wiring; }
+ void defaultVisit(const AMQBody&) { chosen=&classifier.other; }
-ClassifierHandler::ClassifierHandler(Chain wiring, Chain other)
- : FrameHandler(other)
-{
- map[fullId<ExchangeDeclareBody>()] = wiring;
- map[fullId<ExchangeDeleteBody>()] = wiring;
- map[fullId<QueueBindBody>()] = wiring;
- map[fullId<QueueDeclareBody>()] = wiring;
- map[fullId<QueueDeleteBody>()] = wiring;
- map[fullId<QueueUnbindBody>()] = wiring;
-}
+ using framing::FrameDefaultVisitor::visit;
+ using framing::FrameDefaultVisitor::defaultVisit;
-void ClassifierHandler::handle(AMQFrame& frame) {
- // TODO aconway 2007-07-03: Flatten the frame hierarchy so we
- // can do a single lookup to dispatch a frame.
- Chain chosen;
- AMQMethodBody* method = dynamic_cast<AMQMethodBody*>(frame.getBody());
+ FrameHandler::Chain chosen;
+ AMQFrame& frame;
+ ClassifierHandler& classifier;
+};
- // FIXME aconway 2007-07-05: Need to stop bypassed frames
- // from overtaking mcast frames.
- //
- if (method)
- chosen=map[fullId(method)];
- if (chosen)
- chosen->handle(frame);
- else
- next->handle(frame);
-}
-
+void ClassifierHandler::handle(AMQFrame& f) { Visitor(f, *this).chosen(f); }
}} // namespace qpid::cluster