From b4787d760abca28c9dff4cd74327a4b2b92656dd Mon Sep 17 00:00:00 2001 From: Matthias Radestock Date: Wed, 16 May 2012 16:22:02 +0100 Subject: [PATCH 1/5] add missing spec --- src/rabbit_sup.erl | 1 + 1 file changed, 1 insertion(+) diff --git a/src/rabbit_sup.erl b/src/rabbit_sup.erl index bf2b4798ec..9cf3a1fd55 100644 --- a/src/rabbit_sup.erl +++ b/src/rabbit_sup.erl @@ -33,6 +33,7 @@ -spec(start_link/0 :: () -> rabbit_types:ok_pid_or_error()). -spec(start_child/1 :: (atom()) -> 'ok'). +-spec(start_child/2 :: (atom(), [any()]) -> 'ok'). -spec(start_child/3 :: (atom(), atom(), [any()]) -> 'ok'). -spec(start_restartable_child/1 :: (atom()) -> 'ok'). -spec(start_restartable_child/2 :: (atom(), [any()]) -> 'ok'). From ea345d9a3010edcee30673891191ae8ad3607de3 Mon Sep 17 00:00:00 2001 From: Matthias Radestock Date: Wed, 16 May 2012 16:23:41 +0100 Subject: [PATCH 2/5] cosmetic --- src/rabbit_sup.erl | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/src/rabbit_sup.erl b/src/rabbit_sup.erl index 9cf3a1fd55..100312deee 100644 --- a/src/rabbit_sup.erl +++ b/src/rabbit_sup.erl @@ -43,19 +43,17 @@ %%---------------------------------------------------------------------------- -start_link() -> - supervisor:start_link({local, ?SERVER}, ?MODULE, []). +start_link() -> supervisor:start_link({local, ?SERVER}, ?MODULE, []). -start_child(Mod) -> - start_child(Mod, []). +start_child(Mod) -> start_child(Mod, []). -start_child(Mod, Args) -> - start_child(Mod, Mod, Args). +start_child(Mod, Args) -> start_child(Mod, Mod, Args). start_child(ChildId, Mod, Args) -> - child_reply(supervisor:start_child(?SERVER, - {ChildId, {Mod, start_link, Args}, - transient, ?MAX_WAIT, worker, [Mod]})). + child_reply(supervisor:start_child( + ?SERVER, + {ChildId, {Mod, start_link, Args}, + transient, ?MAX_WAIT, worker, [Mod]})). start_restartable_child(Mod) -> start_restartable_child(Mod, []). @@ -74,8 +72,7 @@ stop_child(ChildId) -> E -> E end. -init([]) -> - {ok, {{one_for_all, 0, 1}, []}}. +init([]) -> {ok, {{one_for_all, 0, 1}, []}}. %%---------------------------------------------------------------------------- From 9fef6e6b144a9f5e96d20c8e0ab46ee10131c59d Mon Sep 17 00:00:00 2001 From: Matthias Radestock Date: Wed, 16 May 2012 17:08:03 +0100 Subject: [PATCH 3/5] cosmetic --- src/rabbit_mirror_queue_slave_sup.erl | 6 ++---- src/rabbit_sup.erl | 3 +-- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/src/rabbit_mirror_queue_slave_sup.erl b/src/rabbit_mirror_queue_slave_sup.erl index 8eacb1f3c4..b2e8380313 100644 --- a/src/rabbit_mirror_queue_slave_sup.erl +++ b/src/rabbit_mirror_queue_slave_sup.erl @@ -35,11 +35,9 @@ start() -> transient, infinity, supervisor, [rabbit_mirror_queue_slave_sup]}), ok. -start_link() -> - supervisor2:start_link({local, ?SERVER}, ?MODULE, []). +start_link() -> supervisor2:start_link({local, ?SERVER}, ?MODULE, []). -start_child(Node, Args) -> - supervisor2:start_child({?SERVER, Node}, Args). +start_child(Node, Args) -> supervisor2:start_child({?SERVER, Node}, Args). init([]) -> {ok, {{simple_one_for_one_terminate, 10, 10}, diff --git a/src/rabbit_sup.erl b/src/rabbit_sup.erl index 100312deee..ecc4d816e0 100644 --- a/src/rabbit_sup.erl +++ b/src/rabbit_sup.erl @@ -55,8 +55,7 @@ start_child(ChildId, Mod, Args) -> {ChildId, {Mod, start_link, Args}, transient, ?MAX_WAIT, worker, [Mod]})). -start_restartable_child(Mod) -> - start_restartable_child(Mod, []). +start_restartable_child(Mod) -> start_restartable_child(Mod, []). start_restartable_child(Mod, Args) -> Name = list_to_atom(atom_to_list(Mod) ++ "_sup"), From 3f5026784eb008175b9fbeab4ae8d010037dd4a8 Mon Sep 17 00:00:00 2001 From: Matthias Radestock Date: Wed, 16 May 2012 17:21:29 +0100 Subject: [PATCH 4/5] expand rabbit_sup API with starting of children that are supervisors and use that API throughout the code where appropriate --- src/rabbit.erl | 3 ++- src/rabbit_direct.erl | 12 +++--------- src/rabbit_mirror_queue_slave_sup.erl | 11 +---------- src/rabbit_networking.erl | 13 ++++--------- src/rabbit_sup.erl | 15 +++++++++++++++ 5 files changed, 25 insertions(+), 29 deletions(-) diff --git a/src/rabbit.erl b/src/rabbit.erl index ea9731b68b..e48176f30c 100644 --- a/src/rabbit.erl +++ b/src/rabbit.erl @@ -143,7 +143,8 @@ -rabbit_boot_step({mirror_queue_slave_sup, [{description, "mirror queue slave sup"}, - {mfa, {rabbit_mirror_queue_slave_sup, start, []}}, + {mfa, {rabbit_sup, start_supervisor_child, + [rabbit_mirror_queue_slave_sup]}}, {requires, recovery}, {enables, routing_ready}]}). diff --git a/src/rabbit_direct.erl b/src/rabbit_direct.erl index a471d2826e..c07ad832f0 100644 --- a/src/rabbit_direct.erl +++ b/src/rabbit_direct.erl @@ -47,16 +47,10 @@ %%---------------------------------------------------------------------------- -boot() -> - {ok, _} = - supervisor2:start_child( - rabbit_sup, - {rabbit_direct_client_sup, - {rabbit_client_sup, start_link, +boot() -> rabbit_sup:start_supervisor_child( + rabbit_direct_client_sup, rabbit_client_sup, [{local, rabbit_direct_client_sup}, - {rabbit_channel_sup, start_link, []}]}, - transient, infinity, supervisor, [rabbit_client_sup]}), - ok. + {rabbit_channel_sup, start_link, []}]). force_event_refresh() -> [Pid ! force_event_refresh || Pid<- list()], diff --git a/src/rabbit_mirror_queue_slave_sup.erl b/src/rabbit_mirror_queue_slave_sup.erl index b2e8380313..a2034876b1 100644 --- a/src/rabbit_mirror_queue_slave_sup.erl +++ b/src/rabbit_mirror_queue_slave_sup.erl @@ -18,7 +18,7 @@ -behaviour(supervisor2). --export([start/0, start_link/0, start_child/2]). +-export([start_link/0, start_child/2]). -export([init/1]). @@ -26,15 +26,6 @@ -define(SERVER, ?MODULE). -start() -> - {ok, _} = - supervisor2:start_child( - rabbit_sup, - {rabbit_mirror_queue_slave_sup, - {rabbit_mirror_queue_slave_sup, start_link, []}, - transient, infinity, supervisor, [rabbit_mirror_queue_slave_sup]}), - ok. - start_link() -> supervisor2:start_link({local, ?SERVER}, ?MODULE, []). start_child(Node, Args) -> supervisor2:start_child({?SERVER, Node}, Args). diff --git a/src/rabbit_networking.erl b/src/rabbit_networking.erl index f0c75d23f4..78deea975a 100644 --- a/src/rabbit_networking.erl +++ b/src/rabbit_networking.erl @@ -136,15 +136,10 @@ boot_ssl() -> ok end. -start() -> - {ok,_} = supervisor2:start_child( - rabbit_sup, - {rabbit_tcp_client_sup, - {rabbit_client_sup, start_link, - [{local, rabbit_tcp_client_sup}, - {rabbit_connection_sup,start_link,[]}]}, - transient, infinity, supervisor, [rabbit_client_sup]}), - ok. +start() -> rabbit_sup:start_supervisor_child( + rabbit_tcp_client_sup, rabbit_client_sup, + [{local, rabbit_tcp_client_sup}, + {rabbit_connection_sup,start_link,[]}]). ensure_ssl() -> ok = rabbit_misc:start_applications([crypto, public_key, ssl]), diff --git a/src/rabbit_sup.erl b/src/rabbit_sup.erl index ecc4d816e0..f142d23385 100644 --- a/src/rabbit_sup.erl +++ b/src/rabbit_sup.erl @@ -19,6 +19,8 @@ -behaviour(supervisor). -export([start_link/0, start_child/1, start_child/2, start_child/3, + start_supervisor_child/1, start_supervisor_child/2, + start_supervisor_child/3, start_restartable_child/1, start_restartable_child/2, stop_child/1]). -export([init/1]). @@ -35,6 +37,9 @@ -spec(start_child/1 :: (atom()) -> 'ok'). -spec(start_child/2 :: (atom(), [any()]) -> 'ok'). -spec(start_child/3 :: (atom(), atom(), [any()]) -> 'ok'). +-spec(start_supervisor_child/1 :: (atom()) -> 'ok'). +-spec(start_supervisor_child/2 :: (atom(), [any()]) -> 'ok'). +-spec(start_supervisor_child/3 :: (atom(), atom(), [any()]) -> 'ok'). -spec(start_restartable_child/1 :: (atom()) -> 'ok'). -spec(start_restartable_child/2 :: (atom(), [any()]) -> 'ok'). -spec(stop_child/1 :: (atom()) -> rabbit_types:ok_or_error(any())). @@ -55,6 +60,16 @@ start_child(ChildId, Mod, Args) -> {ChildId, {Mod, start_link, Args}, transient, ?MAX_WAIT, worker, [Mod]})). +start_supervisor_child(Mod) -> start_supervisor_child(Mod, []). + +start_supervisor_child(Mod, Args) -> start_supervisor_child(Mod, Mod, Args). + +start_supervisor_child(ChildId, Mod, Args) -> + child_reply(supervisor:start_child( + ?SERVER, + {ChildId, {Mod, start_link, Args}, + transient, infinity, supervisor, [Mod]})). + start_restartable_child(Mod) -> start_restartable_child(Mod, []). start_restartable_child(Mod, Args) -> From b85e47e6d4a2599992bd2f08d67694223672996f Mon Sep 17 00:00:00 2001 From: Matthias Radestock Date: Wed, 16 May 2012 17:39:07 +0100 Subject: [PATCH 5/5] start supervisor children as, er, supervisors, not workers --- src/rabbit.erl | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/rabbit.erl b/src/rabbit.erl index e48176f30c..df00952946 100644 --- a/src/rabbit.erl +++ b/src/rabbit.erl @@ -60,7 +60,8 @@ -rabbit_boot_step({worker_pool, [{description, "worker pool"}, - {mfa, {rabbit_sup, start_child, [worker_pool_sup]}}, + {mfa, {rabbit_sup, start_supervisor_child, + [worker_pool_sup]}}, {requires, pre_boot}, {enables, external_infrastructure}]}). @@ -539,7 +540,7 @@ boot_error(Format, Args) -> boot_delegate() -> {ok, Count} = application:get_env(rabbit, delegate_count), - rabbit_sup:start_child(delegate_sup, [Count]). + rabbit_sup:start_supervisor_child(delegate_sup, [Count]). recover() -> rabbit_binding:recover(rabbit_exchange:recover(), rabbit_amqqueue:start()).