Added supervisor structure

This commit is contained in:
Jonatan Pålsson 2011-02-16 16:50:57 +01:00
parent b0be23c0a5
commit ae1856e1f2
3 changed files with 62 additions and 0 deletions

14
src/ggs_app.erl Normal file
View file

@ -0,0 +1,14 @@
-module(ggs_app).
-behaviour(application).
-export([start/2, stop/1]).
start(_StartType, _StartArgs) ->
case ggs_sup:start_link(9000) of
{ok, Pid} ->
{ok, Pid};
Other ->
{error, Other}
end.
stop(_State) ->
ok.

41
src/ggs_sup.erl Normal file
View file

@ -0,0 +1,41 @@
-module(ggs_sup).
-behaviour(supervisor).
%% API
-export([start/1, start_link/1]).
%% Supervisor callbacks
-export([init/1]).
-define(SERVER, ?MODULE).
start(Port) ->
[FirstArg] = Port,
{IntPort, _} = string:to_integer(FirstArg),
start_link(IntPort).
start_link(Port) ->
supervisor:start_link({local, ?SERVER}, ?MODULE, [Port]).
init([Port]) ->
Dispatcher = {ggs_dispatcher,
{ggs_dispatcher, start_link, [Port]},
permanent,
2000,
worker,
[ggs_dispatcher]
},
Coordinator = {ggs_coordinator,
{ggs_coordinator, start_link, []},
permanent,
2000,
worker,
[ggs_dispatcher]
},
Children = [Dispatcher, Coordinator],
RestartStrategy = { one_for_one, % Restart only crashing child
10, % Allow ten crashes per..
1 % 1 second, then crash supervisor.
},
{ok, {RestartStrategy, Children}}.

7
src/start_ggs.erl Normal file
View file

@ -0,0 +1,7 @@
-module(start_ggs).
-export([start/0]).
start() ->
application:start(inets),
application:start(erlang_js),
application:start(ggs).