gproc_sup.erl 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. %% -*- erlang-indent-level: 4;indent-tabs-mode: nil -*-
  2. %% --------------------------------------------------
  3. %% This file is provided to you under the Apache License,
  4. %% Version 2.0 (the "License"); you may not use this file
  5. %% except in compliance with the License. You may obtain
  6. %% a copy of the License at
  7. %%
  8. %% http://www.apache.org/licenses/LICENSE-2.0
  9. %%
  10. %% Unless required by applicable law or agreed to in writing,
  11. %% software distributed under the License is distributed on an
  12. %% "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  13. %% KIND, either express or implied. See the License for the
  14. %% specific language governing permissions and limitations
  15. %% under the License.
  16. %% --------------------------------------------------
  17. %%----------------------------------------------------------------------
  18. %% File : gproc_sup.erl
  19. %% Purpose : GPROC top-level supervisor
  20. %%----------------------------------------------------------------------
  21. -module(gproc_sup).
  22. -behaviour(supervisor).
  23. %% External exports
  24. -export([start_link/1]).
  25. %% supervisor callbacks
  26. -export([init/1]).
  27. %%%----------------------------------------------------------------------
  28. %%% API
  29. %%%----------------------------------------------------------------------
  30. start_link(Args) ->
  31. supervisor:start_link({local, ?MODULE}, ?MODULE, Args).
  32. %%%----------------------------------------------------------------------
  33. %%% Callback functions from supervisor
  34. %%%----------------------------------------------------------------------
  35. %%----------------------------------------------------------------------
  36. %% Func: init/1
  37. %% Returns: {ok, {SupFlags, [ChildSpec]}} |
  38. %% ignore |
  39. %% {error, Reason}
  40. %%----------------------------------------------------------------------
  41. %% @spec(_Args::term()) -> {ok, {supervisor_flags(), child_spec_list()}}
  42. %% @doc The main GPROC supervisor.
  43. init(_Args) ->
  44. %% Hint:
  45. %% Child_spec = [Name, {M, F, A},
  46. %% Restart, Shutdown_time, Type, Modules_used]
  47. GProc =
  48. {gproc, {gproc, start_link, []},
  49. permanent, 2000, worker, [gproc]},
  50. Dist = case application:get_env(gproc_dist) of
  51. undefined -> [];
  52. {ok, false} -> [];
  53. {ok, Env} ->
  54. [{gproc_dist, {gproc_dist, start_link, [Env]},
  55. permanent, 2000, worker, [gproc_dist]}]
  56. end,
  57. Mon = {gproc_monitor, {gproc_monitor, start_link, []},
  58. permanent, 2000, worker, [gproc_monitor]},
  59. BCast = {gproc_bcast, {gproc_bcast, start_link, []},
  60. permanent, 2000, worker, [gproc_bcast]},
  61. Pool = {gproc_pool, {gproc_pool, start_link, []},
  62. permanent, 2000, worker, [gproc_pool]},
  63. {ok,{{one_for_one, 15, 60}, [GProc| Dist] ++ [Mon, BCast, Pool]}}.
  64. %%%----------------------------------------------------------------------
  65. %%% Internal functions
  66. %%%----------------------------------------------------------------------