diff options
author | Gordon Sim <gsim@apache.org> | 2009-01-07 10:46:53 +0000 |
---|---|---|
committer | Gordon Sim <gsim@apache.org> | 2009-01-07 10:46:53 +0000 |
commit | bb0bd254b0df35a1890ffb3f59e159945ccdf0bb (patch) | |
tree | ce0cd6a64409473e3c3c156bc825d02f5cbc1fb7 | |
parent | e76832c5d237446129ad90232ea8ef5c61fe18db (diff) | |
download | qpid-python-bb0bd254b0df35a1890ffb3f59e159945ccdf0bb.tar.gz |
QPID-1560: add support for a qpid.exclusive-binding option on direct exchange that causes the binding specified to be the only one for the given key. I.e. if there is already a binding at this exchange with this key it will be atomically updated to bind the new queue.
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk/qpid@732297 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r-- | cpp/src/qpid/broker/DirectExchange.cpp | 17 | ||||
-rw-r--r-- | cpp/src/qpid/sys/CopyOnWriteArray.h | 12 | ||||
-rw-r--r-- | cpp/src/tests/ClientSessionTest.cpp | 22 |
3 files changed, 48 insertions, 3 deletions
diff --git a/cpp/src/qpid/broker/DirectExchange.cpp b/cpp/src/qpid/broker/DirectExchange.cpp index 2eb488de67..d1d9ad07e4 100644 --- a/cpp/src/qpid/broker/DirectExchange.cpp +++ b/cpp/src/qpid/broker/DirectExchange.cpp @@ -33,6 +33,7 @@ namespace const std::string qpidFedOp("qpid.fed.op"); const std::string qpidFedTags("qpid.fed.tags"); const std::string qpidFedOrigin("qpid.fed.origin"); +const std::string qpidExclusiveBinding("qpid.exclusive-binding"); const std::string fedOpBind("B"); const std::string fedOpUnbind("U"); @@ -56,15 +57,25 @@ DirectExchange::DirectExchange(const string& _name, bool _durable, bool DirectExchange::bind(Queue::shared_ptr queue, const string& routingKey, const FieldTable* args) { - string fedOp(args ? args->getAsString(qpidFedOp) : fedOpBind); - string fedTags(args ? args->getAsString(qpidFedTags) : ""); - string fedOrigin(args ? args->getAsString(qpidFedOrigin) : ""); + string fedOp(fedOpBind); + string fedTags; + string fedOrigin; + bool exclusiveBinding = false; + if (args) { + fedOp = args->getAsString(qpidFedOp); + fedTags = args->getAsString(qpidFedTags); + fedOrigin = args->getAsString(qpidFedOrigin); + exclusiveBinding = args->get(qpidExclusiveBinding); + } + bool propagate = false; if (args == 0 || fedOp.empty() || fedOp == fedOpBind) { Mutex::ScopedLock l(lock); Binding::shared_ptr b(new Binding(routingKey, queue, this, FieldTable(), fedOrigin)); BoundKey& bk = bindings[routingKey]; + if (exclusiveBinding) bk.queues.clear(); + if (bk.queues.add_unless(b, MatchQueue(queue))) { propagate = bk.fedBinding.addOrigin(fedOrigin); if (mgmtExchange != 0) { diff --git a/cpp/src/qpid/sys/CopyOnWriteArray.h b/cpp/src/qpid/sys/CopyOnWriteArray.h index c5bdcc0942..a09ee9d441 100644 --- a/cpp/src/qpid/sys/CopyOnWriteArray.h +++ b/cpp/src/qpid/sys/CopyOnWriteArray.h @@ -64,6 +64,18 @@ public: } } + bool clear() + { + Mutex::ScopedLock l(lock); + if (array && !array->empty()) { + ArrayPtr copy; + array = copy; + return true; + } else { + return false; + } + } + template <class F> bool add_unless(T& t, F f) { diff --git a/cpp/src/tests/ClientSessionTest.cpp b/cpp/src/tests/ClientSessionTest.cpp index 5d047dcd0e..454632dd39 100644 --- a/cpp/src/tests/ClientSessionTest.cpp +++ b/cpp/src/tests/ClientSessionTest.cpp @@ -447,6 +447,28 @@ QPID_AUTO_TEST_CASE(testExclusiveSubscribe) } +QPID_AUTO_TEST_CASE(testExclusiveBinding) { + FieldTable options; + options.setString("qpid.exclusive-binding", "anything"); + ClientSessionFixture fix; + fix.session.queueDeclare(arg::queue="queue-1", arg::exclusive=true, arg::autoDelete=true); + fix.session.queueDeclare(arg::queue="queue-2", arg::exclusive=true, arg::autoDelete=true); + fix.session.exchangeBind(arg::exchange="amq.direct", arg::queue="queue-1", arg::bindingKey="my-key", arg::arguments=options); + fix.session.messageTransfer(arg::destination="amq.direct", arg::content=Message("message1", "my-key")); + fix.session.exchangeBind(arg::exchange="amq.direct", arg::queue="queue-2", arg::bindingKey="my-key", arg::arguments=options); + fix.session.messageTransfer(arg::destination="amq.direct", arg::content=Message("message2", "my-key")); + + Message got; + BOOST_CHECK(fix.subs.get(got, "queue-1")); + BOOST_CHECK_EQUAL("message1", got.getData()); + BOOST_CHECK(!fix.subs.get(got, "queue-1")); + + BOOST_CHECK(fix.subs.get(got, "queue-2")); + BOOST_CHECK_EQUAL("message2", got.getData()); + BOOST_CHECK(!fix.subs.get(got, "queue-2")); +} + + QPID_AUTO_TEST_SUITE_END() |