game_sup.erl 1.4 KB

12345678910111213141516171819202122232425262728
  1. -module(game_sup).
  2. -behaviour(supervisor).
  3. -export([start_link/0, stop/0]).
  4. -export([init/1, start/0, start_game/3, stop_game/2]).
  5. -define(SERVER, ?MODULE).
  6. start() -> supervisor:start({local, ?SERVER}, ?MODULE, []).
  7. start_link() -> supervisor:start_link({local, ?SERVER}, ?MODULE, []).
  8. stop() -> exit(?SERVER, shutdown).
  9. start_game(Sup,Mod,Par) -> supervisor:start_child(Sup,[Mod,Par]).
  10. stop_game(Sup,Pid) -> supervisor:terminate_child(Sup,Pid).
  11. init([]) ->
  12. RestartStrategy = one_for_one,
  13. MaxRestarts = 100,
  14. MaxSecondsBetweenRestarts = 3600,
  15. SupFlags = {RestartStrategy, MaxRestarts, MaxSecondsBetweenRestarts},
  16. Restart = permanent,
  17. Shutdown = 2000,
  18. IdGen = {id_generator, {id_generator, start_link, []}, Restart, Shutdown, worker, [id_generator]},
  19. AuthServer = {auth_server, {auth_server, start_link, []}, Restart, Shutdown, worker, [auth_server]},
  20. GameLog = {game_log, {game_log, start_link, []}, Restart, Shutdown, worker, [game_log]},
  21. GameStats = {game_stats, {game_stats, start_link, []}, Restart, Shutdown, worker, [game_stats]},
  22. TavlaSup = {tavla_sup, {tavla_sup, start_link, []}, Restart, Shutdown, supervisor, [tavla_sup]},
  23. OkeySup = {okey_sup, {okey_sup, start_link, []}, Restart, Shutdown, supervisor, [okey_sup]},
  24. LuckySup = {lucky_sup, {lucky_sup, start_link, []}, Restart, Shutdown, supervisor, [lucky_sup]},
  25. {ok, {SupFlags, [IdGen,LuckySup,AuthServer,GameLog,GameStats,TavlaSup,OkeySup]}}.