summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthew Sackman <matthew@rabbitmq.com>2011-01-13 15:10:02 +0000
committerMatthew Sackman <matthew@rabbitmq.com>2011-01-13 15:10:02 +0000
commit0cac631d4359aed966c307636c24781c42e923ce (patch)
tree2e1587d6a8d544f95d1cac0bd3e3896630db24a6
parent801ceca09c3567f181d833f32888aed52ebdf64d (diff)
downloadrabbitmq-server-0cac631d4359aed966c307636c24781c42e923ce.tar.gz
Some refactorings
-rw-r--r--src/rabbit_amqqueue.erl18
-rw-r--r--src/rabbit_binding.erl14
-rw-r--r--src/rabbit_misc.erl41
-rw-r--r--src/rabbit_vhost.erl5
4 files changed, 31 insertions, 47 deletions
diff --git a/src/rabbit_amqqueue.erl b/src/rabbit_amqqueue.erl
index 56fc64fe..44bf0ba2 100644
--- a/src/rabbit_amqqueue.erl
+++ b/src/rabbit_amqqueue.erl
@@ -215,11 +215,10 @@ declare(QueueName, Durable, AutoDelete, Args, Owner) ->
internal_declare(Q = #amqqueue{name = QueueName}, Recover) ->
rabbit_misc:execute_mnesia_tx_with_tail(
fun () ->
- {ReturnArg, TailFun} =
case Recover of
true ->
ok = store_queue(Q),
- {Q, fun rabbit_misc:const_ok/1};
+ rabbit_misc:const(Q);
false ->
case mnesia:wread({rabbit_queue, QueueName}) of
[] ->
@@ -227,17 +226,16 @@ internal_declare(Q = #amqqueue{name = QueueName}, Recover) ->
QueueName}) of
[] -> ok = store_queue(Q),
B = add_default_binding(Q),
- {Q, B};
- %% Q exists on stopped node
- [_] -> {not_found, fun rabbit_misc:const_ok/1}
+ fun (Tx) ->
+ B(Tx),
+ Q
+ end;
+ [_] -> %% Q exists on stopped node
+ rabbit_misc:const(not_found)
end;
[ExistingQ] ->
- {ExistingQ, fun rabbit_misc:const_ok/1}
+ rabbit_misc:const(ExistingQ)
end
- end,
- fun (Tx) ->
- TailFun(Tx),
- ReturnArg
end
end).
diff --git a/src/rabbit_binding.erl b/src/rabbit_binding.erl
index 93f9dc27..740af5ac 100644
--- a/src/rabbit_binding.erl
+++ b/src/rabbit_binding.erl
@@ -148,7 +148,7 @@ add(Binding, InnerFun) ->
not Tx,
binding_created, info(B))
end;
- [_] -> fun (_Tx) -> ok end
+ [_] -> fun rabbit_misc:const_ok/1
end;
{error, _} = Err ->
rabbit_misc:const(Err)
@@ -177,13 +177,11 @@ remove(Binding, InnerFun) ->
E
end
end,
- fun (Tx) ->
- case Result of
- {ok, Deletions} ->
- ok = process_deletions(Deletions, Tx);
- {error, _} = Err ->
- Err
- end
+ case Result of
+ {error, _} = Err ->
+ rabbit_misc:const(Err);
+ {ok, Deletions} ->
+ fun (Tx) -> ok = process_deletions(Deletions, Tx) end
end
end).
diff --git a/src/rabbit_misc.erl b/src/rabbit_misc.erl
index dbc09e7f..9e8ba91b 100644
--- a/src/rabbit_misc.erl
+++ b/src/rabbit_misc.erl
@@ -49,7 +49,6 @@
-export([with_user/2, with_user_and_vhost/3]).
-export([execute_mnesia_transaction/1]).
-export([execute_mnesia_transaction/2]).
--export([execute_mnesia_transaction/3]).
-export([execute_mnesia_tx_with_tail/1]).
-export([ensure_ok/2]).
-export([makenode/1, nodeparts/1, cookie_hash/0, tcp_name/3]).
@@ -148,8 +147,6 @@
-spec(execute_mnesia_transaction/1 :: (thunk(A)) -> A).
-spec(execute_mnesia_transaction/2 ::
(thunk(A), fun ((A, boolean()) -> B)) -> B).
--spec(execute_mnesia_transaction/3 ::
- (thunk(A), fun ((A) -> B), fun ((A) -> B)) -> B).
-spec(execute_mnesia_tx_with_tail/1 ::
(thunk(fun ((boolean()) -> B))) -> B | (fun ((boolean()) -> B))).
-spec(ensure_ok/2 :: (ok_or_error(), atom()) -> 'ok').
@@ -391,40 +388,30 @@ execute_mnesia_transaction(TxFun) ->
%% Like execute_mnesia_transaction/1 with additional Pre- and Post-
-%% commit functions
-execute_mnesia_transaction(TxFun, PreCommit, PostCommit) ->
+%% commit function
+execute_mnesia_transaction(TxFun, PrePostCommitFun) ->
case mnesia:is_transaction() of
true -> throw(unexpected_transaction);
false -> ok
end,
- PostCommit(execute_mnesia_transaction(
- fun () ->
- PreCommit(TxFun())
- end)).
-
-%% Like execute_mnesia_transaction/3 with similar Pre- and PostCommit funs
-execute_mnesia_transaction(TxFun, PrePostCommitFun) ->
- execute_mnesia_transaction(TxFun,
- fun (Result) ->
- PrePostCommitFun(Result, true),
- Result
- end,
- fun (Result) ->
- PrePostCommitFun(Result, false)
- end).
+ PrePostCommitFun(execute_mnesia_transaction(
+ fun () ->
+ Result = TxFun(),
+ PrePostCommitFun(Result, true),
+ Result
+ end), false).
%% Like execute_mnesia_transaction/2, but TxFun is expected to return a
%% TailFun which gets called immediately before and after the tx commit
execute_mnesia_tx_with_tail(TxFun) ->
case mnesia:is_transaction() of
true -> execute_mnesia_transaction(TxFun);
- false -> TailFun =
- execute_mnesia_transaction(
- fun () ->
- TailFun = TxFun(),
- TailFun(true),
- TailFun
- end),
+ false -> TailFun = execute_mnesia_transaction(
+ fun () ->
+ TailFun1 = TxFun(),
+ TailFun1(true),
+ TailFun1
+ end),
TailFun(false)
end.
diff --git a/src/rabbit_vhost.erl b/src/rabbit_vhost.erl
index f5de0cf6..16ae193a 100644
--- a/src/rabbit_vhost.erl
+++ b/src/rabbit_vhost.erl
@@ -59,8 +59,9 @@ add(VHostPath) ->
[_] -> mnesia:abort({vhost_already_exists, VHostPath})
end
end,
- fun rabbit_misc:const_ok/1,
- fun (ok) ->
+ fun (ok, true) ->
+ ok;
+ (ok, false) ->
[rabbit_exchange:declare(
rabbit_misc:r(VHostPath, exchange, Name),
Type, true, false, false, []) ||