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