maracuja v0.2.0 Maracuja behaviour

Link to this section Summary

Functions

handle_start reacts to nodeup infos when in state :net_split, as well as to nodedown infos when in state :monitoring and the disconnected node was the old leader_node

handle_stop reacts to :nodedown infos in the states :monitoring and :hosting

This event handler reacts to DOWN or EXIT messages.

Starts the Maracuja singleton wrapper. It will decide whether to start the actual instance using the global name registry.

Callbacks

Called when the wrapper wants the server to be started. The name argument already uses the :global registry, simply pass this to the underlying server module's opts argument.

Link to this section Types

Link to this type

args()
args() :: term()

Link to this type

name()
name() :: atom()

Link to this section Functions

Link to this function

maybe_start(data)

handle_start reacts to nodeup infos when in state :net_split, as well as to nodedown infos when in state :monitoring and the disconnected node was the old leader_node

When it has verified that the net split is over or at least a majority of the nodes are in the current cluster, it will call restart, which will lead to states :monitoring or :hosting

Link to this function

maybe_stop(state, data)

handle_stop reacts to :nodedown infos in the states :monitoring and :hosting

It will decide if the current amount of connected nodes implies a net split.

If a net split was detected, it will stop the process (if it was hosting one), and change to state :net_split

This event handler reacts to DOWN or EXIT messages.

It tries to start the singleton with global name registration.

In case the name is already registered, the server changes to the state :monitoring

Otherwise, the server links to the pid and changes state to :hosting

Link to this function

start_link(module, args, global_name)
start_link(module(), args(), name()) ::
  {:ok, pid()} | {:error, any()} | :ignore

Starts the Maracuja singleton wrapper. It will decide whether to start the actual instance using the global name registry.

Whenever the wrapper wants to start the singleton, it will call the start_server/2 callback.

Link to this section Callbacks

Link to this callback

start_server(args, name)
start_server(args(), name :: {:global, name()}) ::
  {:ok, pid()} | {:error, {:already_started, pid()}} | {:error, any()}

Called when the wrapper wants the server to be started. The name argument already uses the :global registry, simply pass this to the underlying server module's opts argument.

Example if using a GenServer:

def start_server(args, name) do
  GenServer.start_link(__MODULE__, args, [name: name])
end