summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMatthias Radestock <matthias@lshift.net>2008-11-19 16:45:30 +0000
committerMatthias Radestock <matthias@lshift.net>2008-11-19 16:45:30 +0000
commita54bfb42f0501c82c16cd9a984b67929c29e85ed (patch)
treef609fdb5e591f44696276d14b9c427c08c7aeccb /src
parent6fb1988c83c1a140ad1856963615860e1a58a6e9 (diff)
downloadrabbitmq-server-a54bfb42f0501c82c16cd9a984b67929c29e85ed.tar.gz
refactoring
Diffstat (limited to 'src')
-rw-r--r--src/rabbit_amqqueue.erl9
-rw-r--r--src/rabbit_misc.erl10
-rw-r--r--src/rabbit_networking.erl7
3 files changed, 11 insertions, 15 deletions
diff --git a/src/rabbit_amqqueue.erl b/src/rabbit_amqqueue.erl
index c93ae89a..e2174e11 100644
--- a/src/rabbit_amqqueue.erl
+++ b/src/rabbit_amqqueue.erl
@@ -187,14 +187,7 @@ with_or_die(Name, F) ->
list() -> rabbit_misc:dirty_read_all(amqqueue).
-map(F) ->
- %% TODO: there is scope for optimisation here, e.g. using a
- %% cursor, parallelising the function invocation
- Ref = make_ref(),
- lists:filter(fun (R) -> R =/= Ref end,
- [rabbit_misc:with_exit_handler(
- fun () -> Ref end,
- fun () -> F(Q) end) || Q <- list()]).
+map(F) -> rabbit_misc:filter_exit_map(F, list()).
list_vhost_queues(VHostPath) ->
mnesia:dirty_match_object(
diff --git a/src/rabbit_misc.erl b/src/rabbit_misc.erl
index 7638af58..3c8da720 100644
--- a/src/rabbit_misc.erl
+++ b/src/rabbit_misc.erl
@@ -34,7 +34,7 @@
-export([dirty_read/1]).
-export([r/3, r/2, rs/1]).
-export([enable_cover/0, report_cover/0]).
--export([throw_on_error/2, with_exit_handler/2]).
+-export([throw_on_error/2, with_exit_handler/2, filter_exit_map/2]).
-export([with_user/2, with_vhost/2, with_user_and_vhost/3]).
-export([execute_mnesia_transaction/1]).
-export([ensure_ok/2]).
@@ -80,6 +80,7 @@
-spec(throw_on_error/2 ::
(atom(), thunk({error, any()} | {ok, A} | A)) -> A).
-spec(with_exit_handler/2 :: (thunk(A), thunk(A)) -> A).
+-spec(filter_exit_map/2 :: (fun ((A) -> B), [A]) -> [B]).
-spec(with_user/2 :: (username(), thunk(A)) -> A).
-spec(with_vhost/2 :: (vhost(), thunk(A)) -> A).
-spec(with_user_and_vhost/3 :: (username(), vhost(), thunk(A)) -> A).
@@ -215,6 +216,13 @@ with_exit_handler(Handler, Thunk) ->
Handler()
end.
+filter_exit_map(F, L) ->
+ Ref = make_ref(),
+ lists:filter(fun (R) -> R =/= Ref end,
+ [with_exit_handler(
+ fun () -> Ref end,
+ fun () -> F(I) end) || I <- L]).
+
with_user(Username, Thunk) ->
fun () ->
case mnesia:read({user, Username}) of
diff --git a/src/rabbit_networking.erl b/src/rabbit_networking.erl
index df9b1b69..2ed57d77 100644
--- a/src/rabbit_networking.erl
+++ b/src/rabbit_networking.erl
@@ -168,9 +168,4 @@ tcp_host(IPAddress) ->
{error, _Reason} -> inet_parse:ntoa(IPAddress)
end.
-cmap(F) ->
- Ref = make_ref(),
- lists:filter(fun (R) -> R =/= Ref end,
- [rabbit_misc:with_exit_handler(
- fun () -> Ref end,
- fun () -> F(Q) end) || Q <- connections()]).
+cmap(F) -> rabbit_misc:filter_exit_map(F, connections()).