diff options
| -rw-r--r-- | src/rabbit_sup.erl | 18 | ||||
| -rw-r--r-- | src/supervisor2.erl | 26 |
2 files changed, 19 insertions, 25 deletions
diff --git a/src/rabbit_sup.erl b/src/rabbit_sup.erl index bf29d5426e..97613d17a5 100644 --- a/src/rabbit_sup.erl +++ b/src/rabbit_sup.erl @@ -31,7 +31,7 @@ -module(rabbit_sup). --behaviour(supervisor2). +-behaviour(supervisor). -export([start_link/0, start_child/1, start_child/2, start_child/3, start_restartable_child/1, start_restartable_child/2, stop_child/1]). @@ -43,7 +43,7 @@ -define(SERVER, ?MODULE). start_link() -> - supervisor2:start_link({local, ?SERVER}, ?MODULE, []). + supervisor:start_link({local, ?SERVER}, ?MODULE, []). start_child(Mod) -> start_child(Mod, []). @@ -52,9 +52,9 @@ start_child(Mod, Args) -> start_child(Mod, Mod, Args). start_child(ChildId, Mod, Args) -> - {ok, _} = supervisor2:start_child(?SERVER, - {ChildId, {Mod, start_link, Args}, - intrinsic, ?MAX_WAIT, worker, [Mod]}), + {ok, _} = supervisor:start_child(?SERVER, + {ChildId, {Mod, start_link, Args}, + transient, ?MAX_WAIT, worker, [Mod]}), ok. start_restartable_child(Mod) -> @@ -62,16 +62,16 @@ start_restartable_child(Mod) -> start_restartable_child(Mod, Args) -> Name = list_to_atom(atom_to_list(Mod) ++ "_sup"), - {ok, _} = supervisor2:start_child( + {ok, _} = supervisor:start_child( ?SERVER, {Name, {rabbit_restartable_sup, start_link, [Name, {Mod, start_link, Args}]}, - intrinsic, infinity, supervisor, [rabbit_restartable_sup]}), + transient, infinity, supervisor, [rabbit_restartable_sup]}), ok. stop_child(ChildId) -> - case supervisor2:terminate_child(?SERVER, ChildId) of - ok -> supervisor2:delete_child(?SERVER, ChildId); + case supervisor:terminate_child(?SERVER, ChildId) of + ok -> supervisor:delete_child(?SERVER, ChildId); E -> E end. diff --git a/src/supervisor2.erl b/src/supervisor2.erl index c373f2a47c..3ded5d7f1b 100644 --- a/src/supervisor2.erl +++ b/src/supervisor2.erl @@ -31,13 +31,10 @@ %% the MaxT and MaxR parameters to permit the child to be %% restarted. This may require waiting for longer than Delay. %% -%% 4) Added an 'intrinsic' restart type. This type means that the -%% child should never be restarted (same as temporary) but whenever -%% such a child exits, it will cause the entire supervisor to exit -%% (i.e. the child's existence is intrinsic to the supervisor's -%% existence). Because such children are never restarted, the -%% supervisor's restart strategy, MaxT and MaxR have no bearing on -%% such children. +%% 4) Added an 'intrinsic' restart type. Like the transient type, this +%% type means the child should only be restarted if the child exits +%% abnormally. Unlike the transient type, if the child exits +%% normally, the supervisor itself also exits normally. %% %% All modifications are (C) 2010 Rabbit Technologies Ltd. %% @@ -533,12 +530,6 @@ restart_child(Pid, Reason, State) -> {ok, State} end. -do_restart(intrinsic, Reason, Child, State = #state{name = Name}) -> - case Reason of - normal -> ok; - _ -> report_error(child_terminated, Reason, Child, Name) - end, - {shutdown, remove_child(Child, State)}; do_restart({RestartType, Delay}, Reason, Child, State) -> case restart1(Child, State) of {ok, NState} -> @@ -549,6 +540,8 @@ do_restart({RestartType, Delay}, Reason, Child, State) -> [self(), {{RestartType, Delay}, Reason, Child}]), {ok, NState} end; +do_restart(intrinsic, normal, Child, State) -> + {shutdown, state_del_child(Child, State)}; do_restart(permanent, Reason, Child, State) -> report_error(child_terminated, Reason, Child, State#state.name), restart(Child, State); @@ -558,7 +551,8 @@ do_restart(_, normal, Child, State) -> do_restart(_, shutdown, Child, State) -> NState = state_del_child(Child, State), {ok, NState}; -do_restart(transient, Reason, Child, State) -> +do_restart(Type, Reason, Child, State) when Type =:= transient orelse + Type =:= intrinsic -> report_error(child_terminated, Reason, Child, State#state.name), restart(Child, State); do_restart(temporary, Reason, Child, State) -> @@ -851,8 +845,8 @@ supname(N,_) -> N. %%% {Name, Func, RestartType, Shutdown, ChildType, Modules} %%% where Name is an atom %%% Func is {Mod, Fun, Args} == {atom, atom, list} -%%% RestartType is permanent | temporary | transient | -%%% intrinsic | {permanent, Delay} | +%%% RestartType is intrinsic | permanent | temporary | +%%% transient | {permanent, Delay} | %%% {transient, Delay} where Delay >= 0 %%% Shutdown = integer() | infinity | brutal_kill %%% ChildType = supervisor | worker |
