Packages

Elects master node from Erlang/Elixir cluster that is agreed by all nodes.

Current section

Files

Jump to
elector src elector_sup.erl
Raw

src/elector_sup.erl

%%%-----------------------------------------------------------------------------
%% @doc elector top level supervisor.
%% @private
%% @end
%%%-----------------------------------------------------------------------------
-module(elector_sup).
%%------------------------------------------------------------------------------
%% Behaviours
%%------------------------------------------------------------------------------
-behaviour(supervisor).
%%------------------------------------------------------------------------------
%% Exported API
%%------------------------------------------------------------------------------
-export([start_link/0]).
-export([init/1]).
%%------------------------------------------------------------------------------
%% Definitions
%%------------------------------------------------------------------------------
-define(SERVER, ?MODULE).
%%------------------------------------------------------------------------------
%% Exported functions
%%------------------------------------------------------------------------------
%% @doc Starts the supervisor process.
start_link() ->
supervisor:start_link({local, ?SERVER}, ?MODULE, []).
%%------------------------------------------------------------------------------
%% Callback functions
%%------------------------------------------------------------------------------
init([]) ->
Candidate = #{id => elector_candidate, start => {elector_candidate, start_link, []}},
ElectionState = #{id => elector_state, start => {elector_state, start_link, []}},
CommissionOverviewer =
#{id => elector_overviewer, start => {elector_overviewer, start_link, []}},
SupFlags = #{strategy => one_for_all, intensity => 0, period => 1},
ChildSpecs = [Candidate, ElectionState, CommissionOverviewer],
{ok, {SupFlags, ChildSpecs}}.