diff options
| author | Francesco Mazzoli <francesco@rabbitmq.com> | 2012-07-12 15:14:31 +0100 |
|---|---|---|
| committer | Francesco Mazzoli <francesco@rabbitmq.com> | 2012-07-12 15:14:31 +0100 |
| commit | d8b79de606a90dc020d15d41fd6c6abb36ce0677 (patch) | |
| tree | b59ca1d99f8fc98caa317aa1caf749c6471492c9 | |
| parent | 6f2fbcbb753c045bf7bb0320d187dd087c25e4de (diff) | |
| download | rabbitmq-server-git-d8b79de606a90dc020d15d41fd6c6abb36ce0677.tar.gz | |
merge `is_abnormal_termination' and `is_benign_exit'
| -rw-r--r-- | src/rabbit_amqqueue.erl | 9 | ||||
| -rw-r--r-- | src/rabbit_misc.erl | 35 |
2 files changed, 19 insertions, 25 deletions
diff --git a/src/rabbit_amqqueue.erl b/src/rabbit_amqqueue.erl index c51acbdf4b..f601efb1aa 100644 --- a/src/rabbit_amqqueue.erl +++ b/src/rabbit_amqqueue.erl @@ -677,10 +677,11 @@ safe_delegate_call_ok(F, Pids) -> fun () -> ok end, fun () -> F(Pid) end) end), - case lists:filter( - fun ({_Pid, {exit, R, _}}) -> not rabbit_misc:is_benign_exit(R); - (_) -> false - end, Bads) of + case lists:filter(fun ({_Pid, {exit, {R, _}, _}}) -> + rabbit_misc:is_abnormal_termination(R); + ({_Pid, _}) -> + false + end, Bads) of [] -> ok; Bads1 -> {error, Bads1} end. diff --git a/src/rabbit_misc.erl b/src/rabbit_misc.erl index 6ce1d06848..f0ea4e1382 100644 --- a/src/rabbit_misc.erl +++ b/src/rabbit_misc.erl @@ -29,9 +29,8 @@ -export([enable_cover/1, report_cover/1]). -export([start_cover/1]). -export([confirm_to_sender/2]). --export([throw_on_error/2, is_benign_exit/1, with_exit_handler/2, +-export([throw_on_error/2, with_exit_handler/2, is_abnormal_termination/1, filter_exit_map/2]). --export([is_abnormal_termination/1]). -export([with_user/2, with_user_and_vhost/3]). -export([execute_mnesia_transaction/1]). -export([execute_mnesia_transaction/2]). @@ -137,10 +136,9 @@ -spec(report_cover/1 :: ([file:filename() | atom()]) -> 'ok'). -spec(throw_on_error/2 :: (atom(), thunk(rabbit_types:error(any()) | {ok, A} | A)) -> A). --spec(is_benign_exit/1 :: (any()) -> boolean()). -spec(with_exit_handler/2 :: (thunk(A), thunk(A)) -> A). --spec(filter_exit_map/2 :: (fun ((A) -> B), [A]) -> [B]). -spec(is_abnormal_termination/1 :: (any()) -> boolean()). +-spec(filter_exit_map/2 :: (fun ((A) -> B), [A]) -> [B]). -spec(with_user/2 :: (rabbit_types:username(), thunk(A)) -> A). -spec(with_user_and_vhost/3 :: (rabbit_types:username(), rabbit_types:vhost(), thunk(A)) @@ -421,28 +419,28 @@ throw_on_error(E, Thunk) -> Res -> Res end. -%% Note the code duplication between this and `with_exit_handler/2' below - we -%% can't use arbitrary functions in guards, and we can't re-throw runtime -%% errors. -is_benign_exit({R, _}) when R =:= noproc; R =:= nodedown; R =:= normal; - R =:= shutdown -> - true; -is_benign_exit({{R, _}, _}) when R =:= nodedown; R =:= shutdown -> - true; -is_benign_exit(_) -> - false. - with_exit_handler(Handler, Thunk) -> try Thunk() catch - exit:{R, _} when R =:= noproc; R =:= nodedown; + exit:{R, _} when R =:= noproc; R =:= noconnection; R =:= nodedown; R =:= normal; R =:= shutdown -> Handler(); exit:{{R, _}, _} when R =:= nodedown; R =:= shutdown -> Handler() end. +%% Note the code duplication between this and `with_exit_handler/2' above - we +%% can't use arbitrary functions in guards, and we can't re-throw runtime +%% errors. +is_abnormal_termination(R) when R =:= noproc; R =:= noconnection; + R =:= nodedown; R =:= normal; R =:= shutdown -> + false; +is_abnormal_termination({R, _}) when R =:= nodedown; R =:= shutdown -> + false; +is_abnormal_termination(_) -> + true. + filter_exit_map(F, L) -> Ref = make_ref(), lists:filter(fun (R) -> R =/= Ref end, @@ -450,11 +448,6 @@ filter_exit_map(F, L) -> fun () -> Ref end, fun () -> F(I) end) || I <- L]). -is_abnormal_termination(Reason) - when Reason =:= noproc; Reason =:= noconnection; - Reason =:= normal; Reason =:= shutdown -> false; -is_abnormal_termination({shutdown, _}) -> false; -is_abnormal_termination(_) -> true. with_user(Username, Thunk) -> fun () -> |
