gproc_sup.erl 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. %%%----------------------------------------------------------------------
  2. %%% File : gproc_sup.erl
  3. %%% Purpose : GPROC top-level supervisor
  4. %%%----------------------------------------------------------------------
  5. -module(gproc_sup).
  6. -behaviour(supervisor).
  7. %% External exports
  8. -export([start_link/1]).
  9. %% supervisor callbacks
  10. -export([init/1]).
  11. %%%----------------------------------------------------------------------
  12. %%% API
  13. %%%----------------------------------------------------------------------
  14. start_link(Args) ->
  15. supervisor:start_link({local, ?MODULE}, ?MODULE, Args).
  16. %%%----------------------------------------------------------------------
  17. %%% Callback functions from supervisor
  18. %%%----------------------------------------------------------------------
  19. %%----------------------------------------------------------------------
  20. %% Func: init/1
  21. %% Returns: {ok, {SupFlags, [ChildSpec]}} |
  22. %% ignore |
  23. %% {error, Reason}
  24. %%----------------------------------------------------------------------
  25. %% @spec(_Args::term()) -> {ok, {supervisor_flags(), child_spec_list()}}
  26. %% @doc The main GPROC supervisor.
  27. init(_Args) ->
  28. %% Hint:
  29. %% Child_spec = [Name, {M, F, A},
  30. %% Restart, Shutdown_time, Type, Modules_used]
  31. GProc =
  32. {gproc, {gproc, start_link, []},
  33. permanent, 2000, worker, [gproc]},
  34. Dist = case application:get_env(gproc_dist) of
  35. undefined -> [];
  36. {ok, false} -> [];
  37. {ok, Env} ->
  38. [{gproc_dist, {gproc_dist, start_link, [Env]},
  39. permanent, 2000, worker, [gproc_dist]}]
  40. end,
  41. {ok,{{one_for_one, 15, 60}, [GProc | Dist]}}.
  42. %%%----------------------------------------------------------------------
  43. %%% Internal functions
  44. %%%----------------------------------------------------------------------