diff options
author | Matthew Sackman <matthew@rabbitmq.com> | 2011-02-07 16:09:06 +0000 |
---|---|---|
committer | Matthew Sackman <matthew@rabbitmq.com> | 2011-02-07 16:09:06 +0000 |
commit | 4cd34e45f12e31ef0090b0033c55be419cf47d69 (patch) | |
tree | 8619b6828dc531f0cc9bd5b559a04a97a66b5c43 /src/delegate_sup.erl | |
parent | 709ed272ed055c1a6473f577cfffe772d040c55a (diff) | |
download | rabbitmq-server-4cd34e45f12e31ef0090b0033c55be419cf47d69.tar.gz |
Abstract out the rabbit from delegate (also improve robustness)
Diffstat (limited to 'src/delegate_sup.erl')
-rw-r--r-- | src/delegate_sup.erl | 32 |
1 files changed, 25 insertions, 7 deletions
diff --git a/src/delegate_sup.erl b/src/delegate_sup.erl index e0ffa7c8..96515ff4 100644 --- a/src/delegate_sup.erl +++ b/src/delegate_sup.erl @@ -18,7 +18,8 @@ -behaviour(supervisor). --export([start_link/0]). +-export([start_link/1, count/1]). +-export([boot/0]). -export([init/1]). @@ -28,20 +29,37 @@ -ifdef(use_specs). --spec(start_link/0 :: () -> {'ok', pid()} | {'error', any()}). +-spec(start_link/1 :: (integer()) -> {'ok', pid()} | {'error', any()}). +-spec(count/1 :: ([node()]) -> integer()). + +-spec(boot/0 :: () -> 'ok'). -endif. %%---------------------------------------------------------------------------- -start_link() -> - supervisor:start_link({local, ?SERVER}, ?MODULE, []). +start_link(Count) -> + supervisor:start_link({local, ?SERVER}, ?MODULE, [Count]). + +count([]) -> + 1; +count([Node | Nodes]) -> + try + length(supervisor:which_children({?SERVER, Node})) + catch exit:{{R, _}, _} when R =:= nodedown; R =:= shutdown -> + count(Nodes); + exit:{R, _} when R =:= noproc; R =:= normal; R =:= shutdown -> + count(Nodes) + end. + +boot() -> + {ok, Count} = application:get_env(rabbit, delegate_count), + rabbit_sup:start_child(delegate_sup, [Count]). %%---------------------------------------------------------------------------- -init(_Args) -> - DCount = delegate:delegate_count([node()]), +init([Count]) -> {ok, {{one_for_one, 10, 10}, [{Num, {delegate, start_link, [Num]}, transient, 16#ffffffff, worker, [delegate]} || - Num <- lists:seq(0, DCount - 1)]}}. + Num <- lists:seq(0, Count - 1)]}}. |