Horde v0.5.0-rc.8 Horde.Registry behaviour View Source
A distributed process registry.
Horde.Registry implements a distributed Registry backed by an add-wins last-write-wins δ-CRDT (provided by DeltaCrdt.AWLWWMap
). This CRDT is used for both tracking membership of the cluster and implementing the registry functionality itself. Local changes to the registry will automatically be synced to other nodes in the cluster.
Because of the semantics of an AWLWWMap, the guarantees provided by Horde.Registry are more relaxed than those provided by the standard library Registry. Conflicts will be automatically silently resolved by the underlying AWLWWMap.
Cluster membership is managed with Horde.Cluster
. Joining a cluster can be done with Horde.Cluster.set_members/2
. To take a node out of the cluster, call Horde.Cluster.set_members/2
without that node in the list.
Horde.Registry supports the common “via tuple”, described in the documentation for GenServer
.
Module-based Registry
Horde supports module-based registries to enable dynamic runtime configuration.
defmodule MyRegistry do
use Horde.Registry
def init(options) do
{:ok, Keyword.put(options, :members, get_members())}
end
defp get_members() do
# ...
end
end
Then you can use MyRegistry.child_spec/1
and MyRegistry.start_link/1
in the same way as you’d use Horde.Registry.child_spec/1
and Horde.Registry.start_link/1
.
Link to this section Summary
Functions
Child spec to enable easy inclusion into a supervisor
Returns the number of keys in a registry. It runs in constant time
Returns registered keys for pid
Finds the {pid, value}
for the given key
in registry
Reads registry metadata given on start_link/3
Get the process registry of the horde
Register a process under the given name
Starts the registry as a supervised process
unregister the process under the given name
Link to this section Functions
child_spec(options :: list()) :: Supervisor.child_spec()
Child spec to enable easy inclusion into a supervisor.
Example:
supervise([
Horde.Registry
])
Example:
supervise([
{Horde.Registry, [name: MyApp.GlobalRegistry]}
])
count(registry :: Registry.registry()) :: non_neg_integer()
Returns the number of keys in a registry. It runs in constant time.
keys(registry :: Registry.registry(), pid()) :: [Registry.key()]
Returns registered keys for pid
Finds the {pid, value}
for the given key
in registry
meta(registry :: Registry.registry(), key :: Registry.meta_key()) :: {:ok, Registry.meta_value()} | :error
Reads registry metadata given on start_link/3
Get the process registry of the horde
put_meta( registry :: Registry.registry(), key :: Registry.meta_key(), value :: Registry.meta_value() ) :: :ok
register( registry :: GenServer.server(), name :: Registry.key(), value :: Registry.value() ) :: {:ok, pid()} | {:error, :already_registered, pid()}
Register a process under the given name
Starts the registry as a supervised process
stop(Supervisor.supervisor(), reason :: term(), timeout()) :: :ok
unregister(registry :: GenServer.server(), name :: GenServer.name()) :: :ok
unregister the process under the given name