./ct_report/coverage/mongoose_domain_sup.COVER.html

1 -module(mongoose_domain_sup).
2
3 -behaviour(supervisor).
4
5 -type pair() :: {mongooseim:domain_name(), mongooseim:host_type()}.
6
7 -export([start_link/0, init/1]).
8 -ignore_xref([start_link/0]).
9
10 -export([start_link/2, restart_core/1]).
11 -ignore_xref([start_link/2, restart_core/1]).
12
13 start_link() ->
14 42 supervisor:start_link({local, ?MODULE}, ?MODULE, []).
15
16 start_link(Pairs, AllowedHostTypes) ->
17
:-(
supervisor:start_link({local, ?MODULE}, ?MODULE, [Pairs, AllowedHostTypes]).
18
19 restart_core(Args) ->
20 52 supervisor:terminate_child(?MODULE, mongoose_domain_core),
21 52 supervisor:delete_child(?MODULE, mongoose_domain_core),
22 52 supervisor:start_child(?MODULE, worker_spec(mongoose_domain_core, fill_args(Args))).
23
24 init(Args) ->
25 42 DomainCore = worker_spec(mongoose_domain_core, fill_args(Args)),
26 42 SubdomainCore = worker_spec(mongoose_subdomain_core, []),
27 42 LazyRouting = worker_spec(mongoose_lazy_routing, []),
28 42 {ok, {{one_for_one, 10, 1},
29 [DomainCore, SubdomainCore, LazyRouting]}}.
30
31 worker_spec(Mod, Args) ->
32 178 {Mod, {Mod, start_link, Args}, permanent, timer:seconds(5), worker, [Mod]}.
33
34 %% Domains should be nameprepped using `jid:nameprep'
35 -spec get_static_pairs() -> [pair()].
36 get_static_pairs() ->
37 45 [{H, H} || H <- mongoose_config:get_opt(hosts)].
38
39 fill_args([]) ->
40 45 Pairs = get_static_pairs(),
41 45 AllowedHostTypes = mongoose_config:get_opt(host_types),
42 45 [Pairs, AllowedHostTypes];
43 fill_args([_, _] = Args) ->
44 49 Args.
Line Hits Source