You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

34 lines
1.8 KiB

  1. -module(eTpf_sup).
  2. -behaviour(supervisor).
  3. -export([
  4. start_link/0
  5. , init/1
  6. ]).
  7. -define(SERVER, ?MODULE).
  8. -define(ChildSpec(Id, Type), #{id => Id, start => {Id, start_link, []}, restart => permanent, shutdown => 5000, type => Type, modules => [Id]}).
  9. start_link() ->
  10. supervisor:start_link({local, ?SERVER}, ?MODULE, []).
  11. % 主管的孩子被定义为孩子规格列表 。当主管启动时,将根据此列表从左到右依次启动子进程。主管终止时,它首先以相反的启动顺序从右到左终止其子进程。
  12. % sup_flags() =
  13. % #{
  14. % strategy => strategy(), % optional one_for_one | one_for_all | rest_for_one | simple_one_for_one
  15. % intensity => non_neg_integer(), % optional MaxR 周期时间内最大重启次数
  16. % period => pos_integer() % optional MaxT 重启时间周期 MaxT里重启次数大于MaxR
  17. % }
  18. % child_spec() =
  19. % #{
  20. % id => child_id(), % mandatory Id用来内部标识子规范
  21. % start => mfargs(), % mandatory {M,F,A}
  22. % restart => restart(), % optional permanent(总是重启) | transient(异常关闭会重启即关闭原因非 normal,shutdown,{shutdown,Term}) | temporary(不会重启)
  23. % shutdown => shutdown(), % optional brutal_kill | infinity | integer
  24. % type => worker(), % optional supervisor | worker
  25. % modules => modules() % optional [Module] 假如子进程是supervisor、gen_server 或 gen_fsm,那么Module 是回调模块的名称;假如子进程是gen_event,那么Modules 应该是dynamic
  26. % }
  27. init([]) ->
  28. SupFlags = #{strategy => one_for_one, intensity => 5, period => 10},
  29. ChildSpecs = [?ChildSpec(tpMsgHole, worker)],
  30. {ok, {SupFlags, ChildSpecs}}.