[erlang-questions] Supervision Tree
Richard O'Keefe
ok@REDACTED
Thu Nov 29 01:30:02 CET 2012
(1) When I paste your code into a file and compile it with erlc,
there are no complaints.
(2) Your start_link()
calls supervisor:start_link(ch_sup, [])
which calls ch_sup:init([])
^^arg1 ^^arg2
If you called supervisor:start_link(robots, [gort,r2d2])
it would call back to robots:init([gort,r2d2]).
This is explained in the documentation for the supervisor: module
http://www.erlang.org/doc/man/supervisor.html#start_link-2
which says
Module is the name of the callback module.
Args is an arbitrary term which is passed as the argument to
Module:init/1.
For a non-trivial example, I looked in the OTP sources
and found snmpm_supervisor.erl, which has
start_link(Type, Opts) ->
?d("start_link -> entry with"
"~n Opts: ~p", [Opts]),
SupName = {local, ?MODULE},
supervisor:start_link(SupName, ?MODULE, [Type, Opts]).
...
init([Opts]) when is_list(Opts) -> %% OTP-5963: Due to the addition
init([normal, Opts]); %% OTP-5963: of server_sup
init([Type, Opts]) ->
?d("init -> entry with"
"~n Type: ~p"
"~n Opts: ~p", [Type, Opts]),
Restart = get_restart(Opts),
Flags = {one_for_all, 0, 3600},
Config = worker_spec(snmpm_config, [Opts], Restart, [gen_server]),
MiscSup = sup_spec(snmpm_misc_sup, [], Restart),
ServerSup = sup_spec(snmpm_server_sup, [Type, Opts], Restart),
Sups = [Config, MiscSup, ServerSup],
{ok, {Flags, Sups}}.
More information about the erlang-questions
mailing list