summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Radestock <matthias@rabbitmq.com>2010-12-20 12:36:06 +0000
committerMatthias Radestock <matthias@rabbitmq.com>2010-12-20 12:36:06 +0000
commit24e9bc07ec0bb467fca4566ef197c5855a4c8e80 (patch)
treeefce0f1c6890507b3320d8ce944390bcc4f57846
parent6ebc164ce657ab51668a6744fc19ed935c6ca5d0 (diff)
downloadrabbitmq-server-24e9bc07ec0bb467fca4566ef197c5855a4c8e80.tar.gz
cosmetic and minor refactor
-rw-r--r--ebin/rabbit_app.in6
-rw-r--r--src/delegate.erl44
2 files changed, 20 insertions, 30 deletions
diff --git a/ebin/rabbit_app.in b/ebin/rabbit_app.in
index da388800..25d630c0 100644
--- a/ebin/rabbit_app.in
+++ b/ebin/rabbit_app.in
@@ -32,8 +32,4 @@
{server_properties, []},
{collect_statistics, none},
{auth_mechanisms, ['PLAIN', 'AMQPLAIN']},
- {delegate_count, 16}
- ]
- }
- ]
-}.
+ {delegate_count, 16}]}]}.
diff --git a/src/delegate.erl b/src/delegate.erl
index a6758b86..3814edcf 100644
--- a/src/delegate.erl
+++ b/src/delegate.erl
@@ -82,24 +82,20 @@ invoke(Pids, Fun) when is_list(Pids) ->
%% the sending. Thus calls can't overtake preceding calls/casts.
{Replies, BadNodes} =
case orddict:fetch_keys(Grouped) of
- [] ->
- {[], []};
- RemoteNodes ->
- gen_server2:multi_call(
- RemoteNodes, delegate(), {invoke, Fun, Grouped}, infinity)
+ [] -> {[], []};
+ RemoteNodes -> gen_server2:multi_call(RemoteNodes, delegate(),
+ {invoke, Fun, Grouped},
+ infinity)
end,
- BadPids = lists:foldl(
- fun (BadNode, Acc) ->
- [{Pid, {exit, badnode, []}} ||
- Pid <- orddict:fetch(BadNode, Grouped)] ++ Acc
- end, [], BadNodes),
+ BadPids = [{Pid, {exit, badnode, []}} ||
+ BadNode <- BadNodes,
+ Pid <- orddict:fetch(BadNode, Grouped)],
ResultsNoNode = lists:append([safe_invoke(LocalPids, Fun) |
[Results || {_Node, Results} <- Replies]]),
- lists:foldl(fun ({ok, Pid, Result}, {Good, Bad}) ->
- {[{Pid, Result} | Good], Bad};
- ({error, Pid, Error}, {Good, Bad}) ->
- {Good, [{Pid, Error} | Bad]}
- end, {[], BadPids}, ResultsNoNode).
+ lists:foldl(
+ fun ({ok, Pid, Result}, {Good, Bad}) -> {[{Pid, Result} | Good], Bad};
+ ({error, Pid, Error}, {Good, Bad}) -> {Good, [{Pid, Error} | Bad]}
+ end, {[], BadPids}, ResultsNoNode).
invoke_no_result(Pid, Fun) when is_pid(Pid) andalso node(Pid) =:= node() ->
safe_invoke(Pid, Fun), %% we don't care about any error
@@ -111,8 +107,8 @@ invoke_no_result(Pids, Fun) when is_list(Pids) ->
{LocalPids, Grouped} = group_pids_by_node(Pids),
case orddict:fetch_keys(Grouped) of
[] -> ok;
- RemoteNodes -> gen_server2:abcast(
- RemoteNodes, delegate(), {invoke, Fun, Grouped})
+ RemoteNodes -> gen_server2:abcast(RemoteNodes, delegate(),
+ {invoke, Fun, Grouped})
end,
safe_invoke(LocalPids, Fun), %% must not die
ok.
@@ -139,12 +135,11 @@ delegate_name(Hash) ->
delegate() ->
case get(delegate) of
- undefined ->
- Name = delegate_name(erlang:phash2(self(), delegate_count())),
- put(delegate, Name),
- Name;
- Name ->
- Name
+ undefined -> Name = delegate_name(
+ erlang:phash2(self(), delegate_count())),
+ put(delegate, Name),
+ Name;
+ Name -> Name
end.
safe_invoke(Pids, Fun) when is_list(Pids) ->
@@ -152,8 +147,7 @@ safe_invoke(Pids, Fun) when is_list(Pids) ->
safe_invoke(Pid, Fun) when is_pid(Pid) ->
try
{ok, Pid, Fun(Pid)}
- catch
- Class:Reason ->
+ catch Class:Reason ->
{error, Pid, {Class, Reason, erlang:get_stacktrace()}}
end.