summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Radestock <matthias@rabbitmq.com>2011-04-08 22:08:38 +0100
committerMatthias Radestock <matthias@rabbitmq.com>2011-04-08 22:08:38 +0100
commit9456939f2ad57435fa19975bc552762ed722d83b (patch)
tree1464b131e2e592844289e476c4a3eb693cc1341b
parentde9c5b5bd077da91ab3dd09b1654e4d0bd650452 (diff)
downloadrabbitmq-server-9456939f2ad57435fa19975bc552762ed722d83b.tar.gz
cosmetic changes and minor tweaks to rabbit_binding:{add,remove}
- align 'add' and 'remove' structurally, with the isomorphic final phases extracted into helper funs - call 'read' instead of 'match_object' to check for binding presence in 'remove' - cleaner and possibly slightly more efficient
-rw-r--r--src/rabbit_binding.erl64
1 files changed, 26 insertions, 38 deletions
diff --git a/src/rabbit_binding.erl b/src/rabbit_binding.erl
index 7d13ea29..0fb0639a 100644
--- a/src/rabbit_binding.erl
+++ b/src/rabbit_binding.erl
@@ -124,8 +124,6 @@ exists(Binding) ->
add(Binding) -> add(Binding, fun (_Src, _Dst) -> ok end).
-remove(Binding) -> remove(Binding, fun (_Src, _Dst) -> ok end).
-
add(Binding, InnerFun) ->
binding_action(
Binding,
@@ -134,56 +132,46 @@ add(Binding, InnerFun) ->
%% in general, we want to fail on that in preference to
%% anything else
case InnerFun(Src, Dst) of
- ok -> add(Src, Dst, B);
+ ok -> case mnesia:read({rabbit_route, B}) of
+ [] -> add(Src, Dst, B);
+ [_] -> fun rabbit_misc:const_ok/1
+ end;
{error, _} = Err -> rabbit_misc:const(Err)
end
end).
add(Src, Dst, B) ->
- case mnesia:read({rabbit_route, B}) of
- [] -> Durable = all_durable([Src, Dst]),
- case (not Durable orelse
- mnesia:read({rabbit_durable_route, B}) =:= []) of
- true -> ok = sync_binding(B, Durable, fun mnesia:write/3),
- fun (Tx) ->
- ok = rabbit_exchange:callback(
- Src, add_binding, [Tx, Src, B]),
- rabbit_event:notify_if(
- not Tx, binding_created, info(B))
- end;
- false -> rabbit_misc:const(not_found)
- end;
- [_] -> fun rabbit_misc:const_ok/1
+ Durable = all_durable([Src, Dst]),
+ case (not Durable orelse mnesia:read({rabbit_durable_route, B}) =:= []) of
+ true -> ok = sync_binding(B, Durable, fun mnesia:write/3),
+ fun (Tx) -> ok = rabbit_exchange:callback(Src, add_binding,
+ [Tx, Src, B]),
+ rabbit_event:notify_if(not Tx, binding_created,
+ info(B))
+ end;
+ false -> rabbit_misc:const(not_found)
end.
+remove(Binding) -> remove(Binding, fun (_Src, _Dst) -> ok end).
+
remove(Binding, InnerFun) ->
binding_action(
Binding,
fun (Src, Dst, B) ->
- Result =
- case mnesia:match_object(rabbit_route, #route{binding = B},
- write) of
- [] ->
- {error, binding_not_found};
- [_] ->
- case InnerFun(Src, Dst) of
- ok ->
- ok = sync_binding(B, all_durable([Src, Dst]),
- fun mnesia:delete_object/3),
- {ok, maybe_auto_delete(B#binding.source,
- [B], new_deletions())};
- {error, _} = E ->
- E
- end
- end,
- case Result of
- {error, _} = Err ->
- rabbit_misc:const(Err);
- {ok, Deletions} ->
- fun (Tx) -> ok = process_deletions(Deletions, Tx) end
+ case mnesia:read(rabbit_route, B, write) of
+ [] -> rabbit_misc:const({error, binding_not_found});
+ [_] -> case InnerFun(Src, Dst) of
+ ok -> remove(Src, Dst, B);
+ {error, _} = Err -> rabbit_misc:const(Err)
+ end
end
end).
+remove(Src, Dst, B) ->
+ ok = sync_binding(B, all_durable([Src, Dst]), fun mnesia:delete_object/3),
+ Deletions = maybe_auto_delete(B#binding.source, [B], new_deletions()),
+ fun (Tx) -> ok = process_deletions(Deletions, Tx) end.
+
list(VHostPath) ->
VHostResource = rabbit_misc:r(VHostPath, '_'),
Route = #route{binding = #binding{source = VHostResource,