Fact.Registry (Fact v0.2.0)

View Source

Registry 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's Fact.Context by 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.Context for a database under both its :database_id and :database_name, and
  • the :database_id under 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

get_context(id_or_name)

(since 0.1.0)
@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.

get_database_id(name)

(since 0.1.0)
@spec get_database_id(Fact.database_name()) :: Fact.database_id()

Get the :database_id for a running database by its :database_name.

lookup(database_id, key)

(since 0.1.0)
@spec lookup(Fact.database_id(), atom()) :: [{pid(), term()}]

Wrapper around Registry.lookup/2 to simplify lookup of Fact database processes.

pubsub(database_id)

(since 0.1.0)
@spec pubsub(Fact.database_id()) :: atom()

Gets the name of the PubSub process for the specified database.

register(context)

(since 0.1.0)

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.

registry(database_id)

(since 0.1.0)
@spec registry(Fact.database_id()) :: atom()

Gets the name of the Registry process for the specified database.

supervisor(database_id)

(since 0.1.0)
@spec supervisor(Fact.database_id()) :: atom()

Gets the name of the Supervisor process for the specified database.

via(database_id, key)

(since 0.1.0)
@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.