qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From acon...@apache.org
Subject svn commit: r553024 - in /incubator/qpid/trunk/qpid/cpp/src: cluster.mk qpid/cluster/ClassifierHandler.cpp qpid/cluster/ClassifierHandler.h tests/Cluster.cpp tests/FramingTest.cpp tests/Makefile.am
Date Tue, 03 Jul 2007 23:51:18 GMT
Author: aconway
Date: Tue Jul  3 16:51:17 2007
New Revision: 553024

URL: http://svn.apache.org/viewvc?view=rev&rev=553024
Log:

 * cluster/ClasifierHandler: classifies frames for clustering treatment.
   Currently classifies wiring separately from everything else.

Added:
    incubator/qpid/trunk/qpid/cpp/src/qpid/cluster/ClassifierHandler.cpp   (with props)
    incubator/qpid/trunk/qpid/cpp/src/qpid/cluster/ClassifierHandler.h   (with props)
Modified:
    incubator/qpid/trunk/qpid/cpp/src/cluster.mk
    incubator/qpid/trunk/qpid/cpp/src/tests/Cluster.cpp
    incubator/qpid/trunk/qpid/cpp/src/tests/FramingTest.cpp
    incubator/qpid/trunk/qpid/cpp/src/tests/Makefile.am

Modified: incubator/qpid/trunk/qpid/cpp/src/cluster.mk
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/cluster.mk?view=diff&rev=553024&r1=553023&r2=553024
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/cluster.mk (original)
+++ incubator/qpid/trunk/qpid/cpp/src/cluster.mk Tue Jul  3 16:51:17 2007
@@ -11,7 +11,9 @@
   qpid/cluster/Cpg.cpp \
   qpid/cluster/Cpg.h \
   qpid/cluster/Dispatchable.h \
-  qpid/cluster/ClusterPluginProvider.cpp
+  qpid/cluster/ClusterPluginProvider.cpp \
+  qpid/cluster/ClassifierHandler.h \
+  qpid/cluster/ClassifierHandler.cpp
 
 libqpidcluster_la_LIBADD= -lcpg libqpidbroker.la
 

Added: incubator/qpid/trunk/qpid/cpp/src/qpid/cluster/ClassifierHandler.cpp
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/cluster/ClassifierHandler.cpp?view=auto&rev=553024
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/cluster/ClassifierHandler.cpp (added)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/cluster/ClassifierHandler.cpp Tue Jul  3 16:51:17
2007
@@ -0,0 +1,73 @@
+/*
+ *
+ * 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 "ClassifierHandler.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 shared_ptr<AMQMethodBody>& body) {
+    return fullId(body->amqpClassId(), body->amqpMethodId());
+}
+
+template <class M>
+FullMethodId fullId() { return fullId(M::CLASS_ID, M::METHOD_ID); }
+
+
+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;
+}
+
+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;
+    shared_ptr<AMQMethodBody> method =
+        dynamic_pointer_cast<AMQMethodBody>(frame.getBody());
+    if (method) 
+        chosen=map[fullId(method)];
+    if (chosen)
+        chosen->handle(frame);
+    else
+        next->handle(frame);
+}
+ 
+
+}} // namespace qpid::cluster

Propchange: incubator/qpid/trunk/qpid/cpp/src/qpid/cluster/ClassifierHandler.cpp
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/qpid/trunk/qpid/cpp/src/qpid/cluster/ClassifierHandler.cpp
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/qpid/trunk/qpid/cpp/src/qpid/cluster/ClassifierHandler.h
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/cluster/ClassifierHandler.h?view=auto&rev=553024
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/cluster/ClassifierHandler.h (added)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/cluster/ClassifierHandler.h Tue Jul  3 16:51:17
2007
@@ -0,0 +1,48 @@
+#ifndef QPID_CLUSTER_CLASSIFIERHANDLER_H
+#define QPID_CLUSTER_CLASSIFIERHANDLER_H
+
+/*
+ *
+ * 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/framing/FrameHandler.h"
+#include "qpid/framing/amqp_types.h"
+
+#include <map>
+
+namespace qpid {
+namespace cluster {
+
+/**
+ * Classify frames and forward to the appropriate handler.
+ */
+class ClassifierHandler : public framing::FrameHandler
+{
+  public:
+    ClassifierHandler(Chain wiring, Chain other);
+
+    void handle(framing::AMQFrame& frame);
+
+  private:
+    std::map<uint32_t, framing::FrameHandler::Chain> map;
+};
+
+}} // namespace qpid::cluster
+
+
+
+#endif  /*!QPID_CLUSTER_CLASSIFIERHANDLER_H*/

Propchange: incubator/qpid/trunk/qpid/cpp/src/qpid/cluster/ClassifierHandler.h
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/qpid/trunk/qpid/cpp/src/qpid/cluster/ClassifierHandler.h
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: incubator/qpid/trunk/qpid/cpp/src/tests/Cluster.cpp
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/tests/Cluster.cpp?view=diff&rev=553024&r1=553023&r2=553024
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/tests/Cluster.cpp (original)
+++ incubator/qpid/trunk/qpid/cpp/src/tests/Cluster.cpp Tue Jul  3 16:51:17 2007
@@ -22,13 +22,14 @@
 #include "Cluster.h"
 #include "qpid/framing/ChannelPingBody.h"
 #include "qpid/framing/ChannelOkBody.h"
+#include "qpid/cluster/ClassifierHandler.h"
 
 static const ProtocolVersion VER;
 
 using namespace qpid::log;
 
 /** Verify membership in a cluster with one member. */
-BOOST_AUTO_TEST_CASE(clusterOne) {
+BOOST_AUTO_TEST_CASE(testClusterOne) {
     TestCluster cluster("clusterOne", "amqp:one:1");
     AMQFrame frame(VER, 1, new ChannelPingBody(VER));
     cluster.getToChains().in->handle(frame);
@@ -43,7 +44,7 @@
 }
 
 /** Fork a process to test a cluster with two members */
-BOOST_AUTO_TEST_CASE(clusterTwo) {
+BOOST_AUTO_TEST_CASE(testClusterTwo) {
     pid_t pid=fork();
     BOOST_REQUIRE(pid >= 0);
     if (pid) {              // Parent, see Cluster_child.cpp for child.
@@ -69,3 +70,28 @@
         BOOST_REQUIRE(execl("./Cluster_child", "./Cluster_child", NULL));
     }
 }
+
+struct CountHandler : public FrameHandler {
+    CountHandler() : count(0) {}
+    void handle(AMQFrame&) { count++; }
+    size_t count;
+};
+    
+/** Test the ClassifierHandler */
+BOOST_AUTO_TEST_CASE(testClassifierHandlerWiring) {
+    AMQFrame queueDecl(VER, 0, new QueueDeclareBody(VER));
+    AMQFrame messageTrans(VER, 0, new MessageTransferBody(VER));
+    shared_ptr<CountHandler> wiring(new CountHandler());
+    shared_ptr<CountHandler> other(new CountHandler());
+    
+    ClassifierHandler classify(wiring, other);
+
+    classify.handle(queueDecl);
+    BOOST_CHECK_EQUAL(1u, wiring->count);
+    BOOST_CHECK_EQUAL(0u, other->count);
+    
+    classify.handle(messageTrans);
+    BOOST_CHECK_EQUAL(1u, wiring->count);
+    BOOST_CHECK_EQUAL(1u, other->count);
+}
+    

Modified: incubator/qpid/trunk/qpid/cpp/src/tests/FramingTest.cpp
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/tests/FramingTest.cpp?view=diff&rev=553024&r1=553023&r2=553024
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/tests/FramingTest.cpp (original)
+++ incubator/qpid/trunk/qpid/cpp/src/tests/FramingTest.cpp Tue Jul  3 16:51:17 2007
@@ -352,6 +352,7 @@
         void print(std::ostream&) const {}
         MethodId amqpMethodId() const { return 0; }
         ClassId  amqpClassId() const { return 0; }
+        FullMethodId  getFullMethodId() const { return 0; }
         void encodeContent(Buffer& ) const {}
         void decodeContent(Buffer& ) {}
     };

Modified: incubator/qpid/trunk/qpid/cpp/src/tests/Makefile.am
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/tests/Makefile.am?view=diff&rev=553024&r1=553023&r2=553024
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/tests/Makefile.am (original)
+++ incubator/qpid/trunk/qpid/cpp/src/tests/Makefile.am Tue Jul  3 16:51:17 2007
@@ -87,9 +87,9 @@
   client_test		\
   echo_service		\
   topic_listener	\
-  topic_publisher	\
-  interop_runner 
-check_PROGRAMS += $(testprogs)
+  topic_publisher	
+
+check_PROGRAMS += $(testprogs) interop_runner
 
 TESTS_ENVIRONMENT = VALGRIND=$(VALGRIND) srcdir=$(srcdir) $(srcdir)/run_test
 



Mime
View raw message