./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 93 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 51 supervisor:terminate_child(?MODULE, mongoose_domain_core),
21 51 supervisor:delete_child(?MODULE, mongoose_domain_core),
22 51 supervisor:start_child(?MODULE, worker_spec(mongoose_domain_core, fill_args(Args))).
23
24 init(Args) ->
25 93 DomainCore = worker_spec(mongoose_domain_core, fill_args(Args)),
26 93 SubdomainCore = worker_spec(mongoose_subdomain_core, []),
27 93 LazyRouting = worker_spec(mongoose_lazy_routing, []),
28 93 {ok, {{one_for_one, 10, 1},
29 [DomainCore, SubdomainCore, LazyRouting]}}.
30
31 worker_spec(Mod, Args) ->
32 330 {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 95 [{H, H} || H <- mongoose_config:get_opt(hosts)].
38
39 fill_args([]) ->
40 95 Pairs = get_static_pairs(),
41 95 AllowedHostTypes = mongoose_config:get_opt(host_types),
42 95 [Pairs, AllowedHostTypes];
43 fill_args([_, _] = Args) ->
44 49 Args.
Line Hits Source