Packages
eventstore
0.13.0
1.4.8
1.4.7
1.4.6
1.4.4
1.4.3
1.4.2
1.4.1
1.4.0
1.3.2
1.3.1
1.3.0
1.2.3
1.2.2
1.2.1
1.2.0
1.1.0
1.0.3
1.0.2
1.0.1
1.0.0
1.0.0-rc.0
0.17.0
0.16.2
0.16.1
0.16.0
0.15.1
0.15.0
0.14.0
0.14.0-rc.0
0.13.2
0.13.1
0.13.0
0.12.1
0.12.0
0.11.0
0.11.0-rc.0
0.10.1
0.10.0
0.9.0
0.8.1
0.8.0
0.7.4
0.7.3
0.7.2
0.7.1
0.7.0
0.6.2
0.6.1
0.6.0
0.5.2
0.5.1
0.5.0
0.4.3
0.4.2
0.4.1
0.4.0
0.3.0
0.2.1
0.2.0
0.1.0
0.0.5
0.0.4
0.0.3
0.0.2
0.0.1
Event store using PostgreSQL for persistence.
Current section
Files
Jump to
Current section
Files
lib/event_store/registration/registration.ex
defmodule EventStore.Registration do
@moduledoc """
Process registry specification
"""
@doc """
Return an optional supervisor spec for the registry
"""
@callback child_spec() :: [:supervisor.child_spec()]
@doc """
Starts a uniquely named child process of a supervisor using the given module and args.
Registers the pid with the given name.
"""
@callback start_child(name :: term(), supervisor :: module(), args :: [any()]) :: {:ok, pid()} | {:error, reason :: term()}
@doc """
Sends a message to the given dest and returns `:ok`.
"""
@callback multi_send(dest :: atom(), message :: any()) :: :ok
@doc """
Get the pid of a registered name.
Returns `:undefined` if the name is unregistered.
"""
@callback whereis_name(name :: term()) :: pid() | :undefined
@doc """
Return a `:via` tuple to route a message to a process by its registered name
"""
@callback via_tuple(name :: term()) :: {:via, module(), name :: term()}
@doc false
@spec child_spec() :: [:supervisor.child_spec()]
def child_spec, do: registry_provider().child_spec()
@doc false
@callback start_child(name :: term(), supervisor :: module(), args :: [any()]) :: {:ok, pid()} | {:error, reason :: term()}
def start_child(name, supervisor, args), do: registry_provider().start_child(name, supervisor, args)
@doc false
@spec multi_send(server :: atom(), message :: any()) :: :ok
def multi_send(server, message), do: registry_provider().multi_send(server, message)
@doc false
@spec whereis_name(term()) :: pid() | :undefined
def whereis_name(name), do: registry_provider().whereis_name(name)
@doc false
@spec via_tuple(name :: term()) :: {:via, module(), name :: term()}
def via_tuple(name), do: registry_provider().via_tuple(name)
@doc """
Get the configured registry provider, defaults to `:local` if not configured
"""
def registry_provider do
case Application.get_env(:eventstore, :registry, :local) do
:local -> EventStore.Registration.LocalRegistry
:distributed -> EventStore.Registration.DistributedRegistry
unknown -> raise ArgumentError, message: "Unknown `:registry` setting in config: #{inspect unknown}"
end
end
@doc """
Use the `EventStore.Registration` module to import the `registry_provider/0` and `via_tuple/1` functions.
"""
defmacro __using__(_) do
quote location: :keep do
@before_compile unquote(__MODULE__)
import unquote(__MODULE__), only: [registry_provider: 0, via_tuple: 1]
alias unquote(__MODULE__)
end
end
@doc """
Allow a registry provider to handle the standard `GenServer` callback functions
"""
defmacro __before_compile__(_env) do
quote location: :keep do
@doc false
def handle_call(request, from, state), do: registry_provider().handle_call(request, from, state)
@doc false
def handle_cast(request, state), do: registry_provider().handle_cast(request, state)
@doc false
def handle_info(msg, state), do: registry_provider().handle_info(msg, state)
end
end
end