-export([
start_link/4,
- get_channel_sup/1,
- get_user_sup/1
]).
-export([init/1]).
supervisor:start_link(?MODULE,
{Instance, Host, Port, Nick}).
-get_channel_sup(Pid) ->
- get_sup(Pid, channels).
-
-get_user_sup(Pid) ->
- get_sup(Pid, users).
-
-% TODO: should this crash and burn if the child isn't running?
-% i.e. can this become a race condition with the actual
-% respawning of a process?
-get_sup(Pid, Type) ->
- case supervisor:start_child(Pid,
- data_child(Type, ok, []))
- of
- {error, {already_started, Child}} ->
- Child
- end.
-
init({Instance, Host, Port, Nick}) ->
Connection = {connection,
- {irc_conn, start_link, [self(), Instance, Host, Port, Nick]},
- transient, 5, worker, [irc_conn]},
- Children = [data_child(channels, irc_channel_sup, [Instance]),
- data_child(users, irc_user_sup, [Instance]),
- Connection
- ],
- RestartStrategy = {one_for_all, 0, 1}, % TODO
+ {irc_conn, start_link, [Instance, Host, Port, Nick]},
+ permanent, % persistence type ("Restart" in the manual)
+ 5, % shutdown [sends signal, with timeout for response]
+ worker, % it's not a supervisor itself
+ [irc_conn] % modules it uses
+ },
+ Children = [Connection],
+ RestartStrategy = {one_for_all, 5, 60}, % Die if a child dies more than 5
+ % times in 60 seconds.
{ok, {RestartStrategy, Children}}.
-
-data_child(Id, Module, Args) ->
- {Id,
- {Module, start_link, Args},
- permanent,
- 5,
- supervisor,
- [Module]}.
-