Fact.Registry (Fact v0.2.0)
View SourceRegistry utilities for process discovery and naming within the Fact system.
Fact.Registry provides two related layers of process registration:
- the global
Fact.Registry, which tracks running databases and exposes lookup helpers for resolving a database'sFact.Contextby identifier or name - database-specific registries, one per database instance, which are used for naming and locating processes that belong to that database.
The global registry stores:
- the
Fact.Contextfor a database under both its:database_idand:database_name, and - the
:database_idunder the:database_name.
Helper functions such as get_context/1 and get_database_id/1 provide
convenient access to this information.
For database-local processes, this module exposes helpers like registry/1,
via/2, and lookup/2, which construct or reference the appropriate
database-specific Registry module for the given database_id. It also
provides pubsub/1 and supervisor/1 to derive the corresponding PubSub
and supervisor module names for that database.
Summary
Functions
Get the Fact.Context for a running database by its :database_id or :database_name.
Get the :database_id for a running database by its :database_name.
Wrapper around Registry.lookup/2 to simplify lookup of Fact database processes.
Gets the name of the PubSub process for the specified database.
This registers the supplied Fact.Context with the Fact.Registry keyed by Fact.database_id/0
and Fact.database_name/0.
Gets the name of the Registry process for the specified database.
Gets the name of the Supervisor process for the specified database.
Utility method to create Fact database specific {:via, Registry, {registry, key}} tuples.
This is used extensively for process lookup for messaging within Fact.
Functions
@spec get_context(Fact.database_id() | Fact.database_name()) :: {:ok, Fact.Context.t()} | {:error, :not_found}
Get the Fact.Context for a running database by its :database_id or :database_name.
@spec get_database_id(Fact.database_name()) :: Fact.database_id()
Get the :database_id for a running database by its :database_name.
@spec lookup(Fact.database_id(), atom()) :: [{pid(), term()}]
Wrapper around Registry.lookup/2 to simplify lookup of Fact database processes.
@spec pubsub(Fact.database_id()) :: atom()
Gets the name of the PubSub process for the specified database.
This registers the supplied Fact.Context with the Fact.Registry keyed by Fact.database_id/0
and Fact.database_name/0.
This is an internal function used by Fact.DatabaseSupervisor when it is initialized. If the process
terminates for any reason these registry entries will be automagically cleaned up.
@spec registry(Fact.database_id()) :: atom()
Gets the name of the Registry process for the specified database.
@spec supervisor(Fact.database_id()) :: atom()
Gets the name of the Supervisor process for the specified database.
@spec via(Fact.database_id(), atom()) :: {:via, Registry, {atom(), atom()}}
Utility method to create Fact database specific {:via, Registry, {registry, key}} tuples.
This is used extensively for process lookup for messaging within Fact.