diff options
author | Matthias Radestock <matthias@rabbitmq.com> | 2010-09-07 11:03:41 +0100 |
---|---|---|
committer | Matthias Radestock <matthias@rabbitmq.com> | 2010-09-07 11:03:41 +0100 |
commit | 58521b28c6eb7f98695e548ca54398a26204822e (patch) | |
tree | 55ec1f2334c630b4185bca9bd71b0cec8b364380 | |
parent | 5a33028f8982c30f02bd17fdf0735173d661e7f2 (diff) | |
download | rabbitmq-server-58521b28c6eb7f98695e548ca54398a26204822e.tar.gz |
flesh out binding API a little further
-rw-r--r-- | src/rabbit_binding.erl | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/src/rabbit_binding.erl b/src/rabbit_binding.erl index 6caf7302..a0d4ad59 100644 --- a/src/rabbit_binding.erl +++ b/src/rabbit_binding.erl @@ -32,7 +32,7 @@ -module(rabbit_binding). -include("rabbit.hrl"). --export([recover/0, add/1, remove/1, add/2, remove/2, list/1]). +-export([recover/0, exists/1, add/1, remove/1, add/2, remove/2, list/1]). -export([list_for_exchange/1, list_for_queue/1, list_for_exchange_and_queue/2]). -export([info_keys/0, info/1, info/2, info_all/1, info_all/2]). %% these must all be run inside a mnesia tx @@ -47,15 +47,17 @@ -type(key() :: binary()). --type(bind_res() :: rabbit_types:ok_or_error('queue_not_found' | - 'exchange_not_found' | - 'exchange_and_queue_not_found')). +-type(bind_errors() :: rabbit_types:error('queue_not_found' | + 'exchange_not_found' | + 'exchange_and_queue_not_found')). +-type(bind_res() :: 'ok' | bind_errors()). -type(inner_fun() :: fun((rabbit_types:exchange(), queue()) -> rabbit_types:ok_or_error(rabbit_types:amqp_error()))). -type(bindings() :: [rabbit_types:binding()]). -spec(recover/0 :: () -> [rabbit_types:binding()]). +-spec(exists/1 :: (rabbit_types:binding()) -> boolean() | bind_errors()). -spec(add/1 :: (rabbit_types:binding()) -> bind_res()). -spec(remove/1 :: (rabbit_types:binding()) -> bind_res() | rabbit_types:error('binding_not_found')). @@ -96,6 +98,11 @@ recover() -> [B | Acc] end, [], rabbit_durable_route). +exists(Binding) -> + binding_action( + Binding, + fun (_X, _Q, B) -> not(mnesia:read({rabbit_route, B}) == []) end). + add(Binding) -> add(Binding, fun (_X, _Q) -> ok end). remove(Binding) -> remove(Binding, fun (_X, _Q) -> ok end). |