View Source Distrimon.SingletonResolver behaviour (Distrimon v0.1.0)
This module let's you define a resolver for your singleton process.
Usage:
- Define a resolver module.
defmodule MyApp.MyResolver do
use Distrimon.SingletonResolver
@impl true
def resolve(name, pid1, pid2) do
# Resolve the conflict here.
# You should return either `pid1` or `pid2`.
# NOTE: This runs in a separate process, so it's safe to send messages
# to either `pid1` or `pid2` and expect something back.
end
end- In your supervision tree, use your resolver.
# ...
children = [
{MyApp.MyResolver, name: SomeGlobalName, start: {GenServer, :start_link, option1: "value1", option2: "value2"}}
]
# ...Options
You can use these options when using Distrimon.SingletonResolver to define a resolver.
kill_reason: In case a race condition happens and some nodes start the process and can't register it under the given name, this is used to kill the process. Defaults to:normal.
These are options when you're adding your resolver to your supervision tree.
name: The name to register the process under. Should be an atom.start: A{module, function, args}tuple that starts a process. Return value should be the same as other OTP behaviors,{:ok, pid}or{:error, reason}. Note that this assumes the semantics are the same as OTPstart_link/1, in that this links the started process to the caller (which is handled by nearly allstart_link/1functions of OTP behaviors).
Link to this section Summary
Callbacks
This is your resolver callback. It receives the name that conflict happened on and the pid of the proceses. It should kill one process and keep another one, and return the pid of the process being kept.
Link to this section Callbacks
Specs
This is your resolver callback. It receives the name that conflict happened on and the pid of the proceses. It should kill one process and keep another one, and return the pid of the process being kept.
This is exactly the same as the third argument of :global.register_name/3. For
more information, look at the documentation of the function.