summaryrefslogtreecommitdiff
path: root/cpp/src/qpid/broker/FanOutExchange.cpp
diff options
context:
space:
mode:
authorAlan Conway <aconway@apache.org>2007-12-06 18:37:18 +0000
committerAlan Conway <aconway@apache.org>2007-12-06 18:37:18 +0000
commitf03223296e70664d3ecd57df357e71202c79eff7 (patch)
tree7d0b5b8bcb6be11ef3294d04c198b4e5e7981fce /cpp/src/qpid/broker/FanOutExchange.cpp
parent430e644a4a647c256ae51682d7230c35d954073e (diff)
downloadqpid-python-f03223296e70664d3ecd57df357e71202c79eff7.tar.gz
From Ted Ross <tross@redhat.com>
Queue statistics fixed. Additional objects added (exchange, binding). Changes: M cpp/src/qpid/broker/ExchangeRegistry.h M cpp/src/qpid/broker/ExchangeRegistry.cpp ExchangeRegistry was modified to pass a parent pointer to created exchanges. This parent reference is not stored but is used to link management objects in a hierarchy of ownership. M cpp/src/qpid/broker/Exchange.h M cpp/src/qpid/broker/Exchange.cpp Exchange now inherits Manageable to make it visible via the management interface. The Exchange parent class handles most of the management boilerplate. A Binding struct was introduced to track bindings for management. This is separate from QueueBindings which track bindings for queues. M cpp/src/qpid/broker/HeadersExchange.h M cpp/src/qpid/broker/FanOutExchange.h M cpp/src/qpid/broker/DirectExchange.h M cpp/src/qpid/broker/TopicExchange.h M cpp/src/qpid/broker/HeadersExchange.cpp M cpp/src/qpid/broker/FanOutExchange.cpp M cpp/src/qpid/broker/DirectExchange.cpp M cpp/src/qpid/broker/TopicExchange.cpp M cpp/src/qpid/management/ManagementExchange.cpp M cpp/src/qpid/management/ManagementExchange.h Each exchange type handles management stats in its own specific way. Additionally, the constructors pass the management parent pointer to the constructor or Exchange. An extra layer was added to contain bindings. Instead of directly storing bound queues, the exchanges store "bindings" which are managable constructs. M cpp/src/qpid/broker/Broker.cpp Broker now explicitly enables the management agent. Also sets the management parent (vhost) in the exchange registry. M cpp/src/qpid/broker/Vhost.cpp Updated constructor to be more defensive in case the management agent has not been enabled. M cpp/src/qpid/broker/Queue.cpp Same constructor update as vhost. Moved accounting of dequeues into "pop". Implemented management method handler (purge). M cpp/src/qpid/broker/Deliverable.h A new method was added to extract the content size of the deliverable content (if appropriate). The method is not pure virtual and returns zero if not overridden. M cpp/src/qpid/broker/DeliverableMessage.h M cpp/src/qpid/broker/TxPublish.cpp M cpp/src/qpid/broker/DeliverableMessage.cpp M cpp/src/qpid/broker/TxPublish.h These derivatives of Deliverable were updated with overrides for contenSize. M cpp/src/qpid/management/ManagementAgent.h M cpp/src/qpid/management/ManagementAgent.cpp An "enable" method was added to prevent inadvertent creation of a management agent when not desired. Adding and deleting management objects is now protected by a mutex. Make sure that deleted objects get reported even if neither their configuration nor instrumentation is changed. M specs/management-schema.xml Minor cosmetic updates. Additional parent linkage. M cpp/managementgen/schema.py M cpp/managementgen/templates/Class.cpp Added generated code to publish schema details for methods. git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@601807 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp/src/qpid/broker/FanOutExchange.cpp')
-rw-r--r--cpp/src/qpid/broker/FanOutExchange.cpp71
1 files changed, 63 insertions, 8 deletions
diff --git a/cpp/src/qpid/broker/FanOutExchange.cpp b/cpp/src/qpid/broker/FanOutExchange.cpp
index ea2327c788..714d4ea444 100644
--- a/cpp/src/qpid/broker/FanOutExchange.cpp
+++ b/cpp/src/qpid/broker/FanOutExchange.cpp
@@ -25,15 +25,36 @@ using namespace qpid::broker;
using namespace qpid::framing;
using namespace qpid::sys;
-FanOutExchange::FanOutExchange(const std::string& _name) : Exchange(_name) {}
-FanOutExchange::FanOutExchange(const std::string& _name, bool _durable, const FieldTable& _args) : Exchange(_name, _durable, _args) {}
+FanOutExchange::FanOutExchange(const std::string& _name, Manageable* _parent) :
+ Exchange(_name, _parent)
+{
+ if (mgmtExchange.get() != 0)
+ mgmtExchange->set_type (typeName);
+}
+
+FanOutExchange::FanOutExchange(const std::string& _name, bool _durable,
+ const FieldTable& _args, Manageable* _parent) :
+ Exchange(_name, _durable, _args, _parent)
+{
+ if (mgmtExchange.get() != 0)
+ mgmtExchange->set_type (typeName);
+}
bool FanOutExchange::bind(Queue::shared_ptr queue, const string& /*routingKey*/, const FieldTable* /*args*/){
RWlock::ScopedWlock locker(lock);
+ std::vector<Binding::shared_ptr>::iterator i;
+
// Add if not already present.
- Queue::vector::iterator i = std::find(bindings.begin(), bindings.end(), queue);
+ for (i = bindings.begin (); i != bindings.end(); i++)
+ if ((*i)->queue == queue)
+ break;
+
if (i == bindings.end()) {
- bindings.push_back(queue);
+ Binding::shared_ptr binding (new Binding ("", queue, this));
+ bindings.push_back(binding);
+ if (mgmtExchange.get() != 0) {
+ mgmtExchange->inc_bindings ();
+ }
return true;
} else {
return false;
@@ -42,9 +63,17 @@ bool FanOutExchange::bind(Queue::shared_ptr queue, const string& /*routingKey*/,
bool FanOutExchange::unbind(Queue::shared_ptr queue, const string& /*routingKey*/, const FieldTable* /*args*/){
RWlock::ScopedWlock locker(lock);
- Queue::vector::iterator i = std::find(bindings.begin(), bindings.end(), queue);
+ std::vector<Binding::shared_ptr>::iterator i;
+
+ for (i = bindings.begin (); i != bindings.end(); i++)
+ if ((*i)->queue == queue)
+ break;
+
if (i != bindings.end()) {
bindings.erase(i);
+ if (mgmtExchange.get() != 0) {
+ mgmtExchange->dec_bindings ();
+ }
return true;
} else {
return false;
@@ -53,14 +82,40 @@ bool FanOutExchange::unbind(Queue::shared_ptr queue, const string& /*routingKey*
void FanOutExchange::route(Deliverable& msg, const string& /*routingKey*/, const FieldTable* /*args*/){
RWlock::ScopedRlock locker(lock);
- for(Queue::vector::iterator i = bindings.begin(); i != bindings.end(); ++i){
- msg.deliverTo(*i);
+ uint32_t count(0);
+
+ for(std::vector<Binding::shared_ptr>::iterator i = bindings.begin(); i != bindings.end(); ++i, count++){
+ msg.deliverTo((*i)->queue);
+ if ((*i)->mgmtBinding.get() != 0)
+ (*i)->mgmtBinding->inc_msgMatched ();
+ }
+
+ if (mgmtExchange.get() != 0)
+ {
+ mgmtExchange->inc_msgReceives ();
+ mgmtExchange->inc_byteReceives (msg.contentSize ());
+ if (count == 0)
+ {
+ mgmtExchange->inc_msgDrops ();
+ mgmtExchange->inc_byteDrops (msg.contentSize ());
+ }
+ else
+ {
+ mgmtExchange->inc_msgRoutes (count);
+ mgmtExchange->inc_byteRoutes (count * msg.contentSize ());
+ }
}
}
bool FanOutExchange::isBound(Queue::shared_ptr queue, const string* const, const FieldTable* const)
{
- return std::find(bindings.begin(), bindings.end(), queue) != bindings.end();
+ std::vector<Binding::shared_ptr>::iterator i;
+
+ for (i = bindings.begin (); i != bindings.end(); i++)
+ if ((*i)->queue == queue)
+ break;
+
+ return i != bindings.end();
}