-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduced socketio_listener and therefore refactored supervision tree.
- Loading branch information
Showing
8 changed files
with
105 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
-module(socketio_listener). | ||
-export([start/1]). | ||
|
||
start(Options) -> | ||
{ok, Pid} = supervisor:start_child(socketio_listener_sup_sup, [Options]), | ||
{dictionary, Dict} = erlang:process_info(Pid, dictionary), | ||
EventMgr = proplists:get_value(event_manager, Dict), | ||
{ok, Pid, EventMgr}. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
-module(socketio_listener_sup). | ||
|
||
-behaviour(supervisor). | ||
|
||
%% API | ||
-export([start_link/1]). | ||
|
||
%% Supervisor callbacks | ||
-export([init/1]). | ||
|
||
%% Helper macro for declaring children of supervisor | ||
-define(CHILD(I, Type), {I, {I, start_link, []}, permanent, 5000, Type, [I]}). | ||
|
||
%% =================================================================== | ||
%% API functions | ||
%% =================================================================== | ||
|
||
start_link(Options) -> | ||
supervisor:start_link({local, ?MODULE}, ?MODULE, [Options]). | ||
|
||
%% =================================================================== | ||
%% Supervisor callbacks | ||
%% =================================================================== | ||
|
||
init([Options]) -> | ||
HttpPort = proplists:get_value(http_port, Options, 80), | ||
DefaultHttpHandler = proplists:get_value(default_http_handler, Options), | ||
{ok, EventMgr} = gen_event:start_link(), | ||
put(event_manager, EventMgr), %% this is ok because it is a write-once value | ||
{ok, { {one_for_one, 5, 10}, [ | ||
{socketio_http, {socketio_http, start_link, [HttpPort, | ||
DefaultHttpHandler, | ||
EventMgr, | ||
self()]}, | ||
permanent, 5000, worker, [socketio_http]}, | ||
{socketio_client_sup, {socketio_client_sup, start_link, []}, | ||
permanent, infinity, supervisor, [socketio_client_sup]} | ||
|
||
|
||
]} }. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
-module(socketio_listener_sup_sup). | ||
|
||
-behaviour(supervisor). | ||
|
||
%% API | ||
-export([start_link/0]). | ||
|
||
%% Supervisor callbacks | ||
-export([init/1]). | ||
|
||
%% Helper macro for declaring children of supervisor | ||
-define(CHILD(I, Type), {I, {I, start_link, []}, permanent, 5000, Type, [I]}). | ||
|
||
%% =================================================================== | ||
%% API functions | ||
%% =================================================================== | ||
|
||
start_link() -> | ||
supervisor:start_link({local, ?MODULE}, ?MODULE, []). | ||
|
||
%% =================================================================== | ||
%% Supervisor callbacks | ||
%% =================================================================== | ||
|
||
init([]) -> | ||
{ok, { {simple_one_for_one, 5, 10}, [ | ||
{socketio_listener_sup, {socketio_listener_sup, start_link, []}, | ||
permanent, infinity, supervisor, [socketio_listener_sup]} | ||
]} }. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43562fd
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.