diff options
author | Simon MacMullen <simon@rabbitmq.com> | 2012-04-24 18:06:52 +0100 |
---|---|---|
committer | Simon MacMullen <simon@rabbitmq.com> | 2012-04-24 18:06:52 +0100 |
commit | 9072f224cf0460760d776d5c5d343b8961d4a8da (patch) | |
tree | 92abc108df1397150f0b9470af41b95604e133e5 | |
parent | 119431ae9862d7a62292e25a17c0c96b3b0aeab1 (diff) | |
download | rabbitmq-server-9072f224cf0460760d776d5c5d343b8961d4a8da.tar.gz |
Add an abstraction for reading the scratch
-rw-r--r-- | src/rabbit_exchange.erl | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/src/rabbit_exchange.erl b/src/rabbit_exchange.erl index 7291da8d..ac2f2610 100644 --- a/src/rabbit_exchange.erl +++ b/src/rabbit_exchange.erl @@ -20,7 +20,7 @@ -export([recover/0, callback/4, declare/6, assert_equivalence/6, assert_args_equivalence/2, check_type/1, - lookup/1, lookup_or_die/1, list/1, update_scratch/2, + lookup/1, lookup_or_die/1, list/1, lookup_scratch/1, update_scratch/2, info_keys/0, info/1, info/2, info_all/1, info_all/2, route/2, delete/2]). %% these must be run inside a mnesia tx @@ -60,6 +60,9 @@ (name()) -> rabbit_types:exchange() | rabbit_types:channel_exit()). -spec(list/1 :: (rabbit_types:vhost()) -> [rabbit_types:exchange()]). +-spec(lookup_scratch/1 :: (name()) -> + rabbit_types:ok(term()) | + rabbit_types:error('not_found')). -spec(update_scratch/2 :: (name(), fun((any()) -> any())) -> 'ok'). -spec(info_keys/0 :: () -> rabbit_types:info_keys()). -spec(info/1 :: (rabbit_types:exchange()) -> rabbit_types:infos()). @@ -234,6 +237,12 @@ list(VHostPath) -> rabbit_exchange, #exchange{name = rabbit_misc:r(VHostPath, exchange), _ = '_'}). +lookup_scratch(Name) -> + case lookup(Name) of + {ok, #exchange{scratch = Scratch}} -> {ok, Scratch}; + {error, not_found} -> {error, not_found} + end. + update_scratch(Name, Fun) -> rabbit_misc:execute_mnesia_transaction( fun() -> |