|
@@ -23,12 +23,11 @@
|
|
%% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
%% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
%% THE SOFTWARE.
|
|
%% THE SOFTWARE.
|
|
%% ==========================================================================================================
|
|
%% ==========================================================================================================
|
|
--module(syn_scopes_sup).
|
|
|
|
|
|
+-module(syn_scope_sup).
|
|
-behaviour(supervisor).
|
|
-behaviour(supervisor).
|
|
|
|
|
|
%% API
|
|
%% API
|
|
--export([start_link/0]).
|
|
|
|
--export([get_node_scopes/0, add_node_to_scope/1]).
|
|
|
|
|
|
+-export([start_link/1]).
|
|
|
|
|
|
%% Supervisor callbacks
|
|
%% Supervisor callbacks
|
|
-export([init/1]).
|
|
-export([init/1]).
|
|
@@ -36,51 +35,23 @@
|
|
%% ===================================================================
|
|
%% ===================================================================
|
|
%% API
|
|
%% API
|
|
%% ===================================================================
|
|
%% ===================================================================
|
|
--spec start_link() -> {ok, pid()} | {already_started, pid()} | shutdown.
|
|
|
|
-start_link() ->
|
|
|
|
- supervisor:start_link({local, ?MODULE}, ?MODULE, []).
|
|
|
|
-
|
|
|
|
--spec get_node_scopes() -> [atom()].
|
|
|
|
-get_node_scopes() ->
|
|
|
|
- case application:get_env(syn, syn_custom_scopes) of
|
|
|
|
- undefined -> [default];
|
|
|
|
- {ok, Scopes} -> [default] ++ maps:keys(Scopes)
|
|
|
|
- end.
|
|
|
|
-
|
|
|
|
--spec add_node_to_scope(Scope :: atom()) -> ok.
|
|
|
|
-add_node_to_scope(Scope) ->
|
|
|
|
- error_logger:info_msg("SYN[~s] Adding node to scope '~s'", [node(), Scope]),
|
|
|
|
- %% save to ENV (failsafe if sup is restarted)
|
|
|
|
- CustomScopes0 = case application:get_env(syn, syn_custom_scopes) of
|
|
|
|
- undefined -> #{};
|
|
|
|
- {ok, Scopes} -> Scopes
|
|
|
|
- end,
|
|
|
|
- CustomScopes = CustomScopes0#{Scope => #{}},
|
|
|
|
- application:set_env(syn, syn_custom_scopes, CustomScopes),
|
|
|
|
- %% create ETS tables
|
|
|
|
- syn_backbone:create_tables_for_scope(Scope),
|
|
|
|
- %% start children
|
|
|
|
- supervisor:start_child(?MODULE, scope_child_spec(syn_registry, Scope)),
|
|
|
|
- supervisor:start_child(?MODULE, scope_child_spec(syn_groups, Scope)),
|
|
|
|
- ok.
|
|
|
|
|
|
+-spec start_link(Scope :: atom()) -> {ok, pid()} | {already_started, pid()} | shutdown.
|
|
|
|
+start_link(Scope) ->
|
|
|
|
+ supervisor:start_link(?MODULE, [Scope]).
|
|
|
|
|
|
%% ===================================================================
|
|
%% ===================================================================
|
|
%% Callbacks
|
|
%% Callbacks
|
|
%% ===================================================================
|
|
%% ===================================================================
|
|
--spec init([]) ->
|
|
|
|
|
|
+-spec init([Scope :: atom()]) ->
|
|
{ok, {{supervisor:strategy(), non_neg_integer(), pos_integer()}, [supervisor:child_spec()]}}.
|
|
{ok, {{supervisor:strategy(), non_neg_integer(), pos_integer()}, [supervisor:child_spec()]}}.
|
|
-init([]) ->
|
|
|
|
- %% empty on application start, but populated if the supervisor is restarted
|
|
|
|
- Children = lists:foldl(fun(Scope, Acc) ->
|
|
|
|
- %% create ETS tables
|
|
|
|
- syn_backbone:create_tables_for_scope(Scope),
|
|
|
|
- %% add to specs
|
|
|
|
- [
|
|
|
|
- scope_child_spec(syn_registry, Scope),
|
|
|
|
- scope_child_spec(syn_groups, Scope)
|
|
|
|
- | Acc
|
|
|
|
- ]
|
|
|
|
- end, [], get_node_scopes()),
|
|
|
|
|
|
+init([Scope]) ->
|
|
|
|
+ %% create ETS tables
|
|
|
|
+ syn_backbone:create_tables_for_scope(Scope),
|
|
|
|
+ %% set children
|
|
|
|
+ Children = [
|
|
|
|
+ scope_child_spec(syn_registry, Scope),
|
|
|
|
+ scope_child_spec(syn_groups, Scope)
|
|
|
|
+ ],
|
|
{ok, {{one_for_one, 10, 10}, Children}}.
|
|
{ok, {{one_for_one, 10, 10}, Children}}.
|
|
|
|
|
|
%% ===================================================================
|
|
%% ===================================================================
|