1 %%%-------------------------------------------------------------------
2 %%% File : etorrent_acceptor_sup.erl
3 %%% Author : Jesper Louis Andersen <>
4 %%% Description : Supervise a set of acceptor processes.
6 %%% Created : 25 Aug 2007 by Jesper Louis Andersen <>
7 %%%-------------------------------------------------------------------
8 -module(etorrent_acceptor_sup
).
10 -behaviour(supervisor
).
13 -export([start_link
/1]).
15 %% Supervisor callbacks
18 -define(DEFAULT_AMOUNT_OF_ACCEPTORS
, 5).
19 -define(SERVER
, ?MODULE
).
21 %%====================================================================
23 %%====================================================================
24 %%--------------------------------------------------------------------
25 %% Function: start_link(PeerId) -> {ok,Pid} | ignore | {error,Error}
26 %% Description: Starts the supervisor
27 %%--------------------------------------------------------------------
29 supervisor:start_link({local
, ?SERVER
}, ?MODULE
, [PeerId
]).
31 %%====================================================================
32 %% Supervisor callbacks
33 %%====================================================================
34 %%--------------------------------------------------------------------
35 %% Func: init(Args) -> {ok, {SupFlags, [ChildSpec]}} |
38 %% Description: Whenever a supervisor is started using
39 %% supervisor:start_link/[2,3], this function is called by the new process
40 %% to find out about restart strategy, maximum restart frequency and child
42 %%--------------------------------------------------------------------
44 Children
= build_children(PeerId
, ?DEFAULT_AMOUNT_OF_ACCEPTORS
),
45 {ok
, {{one_for_one
, 1, 60}, Children
}}.
47 %%====================================================================
49 %%====================================================================
51 build_children(_PeerId
, 0) -> [];
52 build_children(PeerId
, N
) ->
55 {etorrent_acceptor
, start_link
, [PeerId
]},
56 permanent
, 2000, worker
, [etorrent_acceptor
]},
57 [ChildSpec
| build_children(PeerId
, N
-1)].