Packages
Typed distributed messaging for Gleam on the BEAM.
Retired package: Deprecated - The project needs to be redesigned around a much smaller and clearer core.
Current section
Files
Jump to
Current section
Files
src/distribute@cluster@membership.erl
-module(distribute@cluster@membership).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/distribute/cluster/membership.gleam").
-export([start_service/1, stop_service/0, members_with_status/0, alive/0, suspect/0, current_leader/0, metrics/0, metrics_inc/1, metrics_get/1]).
-export_type([status/0]).
-if(?OTP_RELEASE >= 27).
-define(MODULEDOC(Str), -moduledoc(Str)).
-define(DOC(Str), -doc(Str)).
-else.
-define(MODULEDOC(Str), -compile([])).
-define(DOC(Str), -compile([])).
-endif.
-type status() :: alive | suspect | dead.
-file("src/distribute/cluster/membership.gleam", 51).
?DOC(" Start the background membership poller with interval in milliseconds.\n").
-spec start_service(integer()) -> nil.
start_service(Interval_ms) ->
membership_ffi:start(Interval_ms).
-file("src/distribute/cluster/membership.gleam", 56).
?DOC(" Stop the background membership service.\n").
-spec stop_service() -> nil.
stop_service() ->
membership_ffi:stop().
-file("src/distribute/cluster/membership.gleam", 62).
?DOC(
" Return the list of nodes and their status and incarnation according to the background poller.\n"
" Returns a list of tuples `#(NodeName, Status, Incarnation)`.\n"
).
-spec members_with_status() -> list({binary(), status(), integer()}).
members_with_status() ->
Raw = membership_ffi:members_with_status(),
gleam@list:map(Raw, fun(Item) -> case Item of
{N, S, Inc, _} ->
case S of
<<"alive"/utf8>> ->
{N, alive, Inc};
<<"suspect"/utf8>> ->
{N, suspect, Inc};
_ ->
{N, dead, Inc}
end
end end).
-file("src/distribute/cluster/membership.gleam", 77).
?DOC(" Get a list of all nodes currently considered 'alive'.\n").
-spec alive() -> list(binary()).
alive() ->
membership_ffi:alive().
-file("src/distribute/cluster/membership.gleam", 82).
?DOC(" Get a list of all nodes currently considered 'suspect' (potentially failing).\n").
-spec suspect() -> list(binary()).
suspect() ->
membership_ffi:suspect().
-file("src/distribute/cluster/membership.gleam", 86).
-spec current_leader() -> {ok, binary()} | {error, nil}.
current_leader() ->
S = membership_ffi:current_leader(),
case S of
<<""/utf8>> ->
{error, nil};
_ ->
{ok, S}
end.
-file("src/distribute/cluster/membership.gleam", 95).
?DOC(" Return internal metrics as a list of `(name, value)` tuples.\n").
-spec metrics() -> list({binary(), integer()}).
metrics() ->
membership_ffi:metrics().
-file("src/distribute/cluster/membership.gleam", 100).
?DOC(" Increment a named metric (useful in tests).\n").
-spec metrics_inc(binary()) -> nil.
metrics_inc(Name) ->
membership_ffi:metrics_increment(Name).
-file("src/distribute/cluster/membership.gleam", 104).
-spec metrics_get(binary()) -> integer().
metrics_get(Name) ->
membership_ffi:metrics_get(Name).