ExESDB.StoreNaming (ex_esdb_gater v0.8.0)
Helper module for creating store-specific GenServer names.
This module provides utilities for generating store-specific names for GenServers, allowing multiple ExESDB instances to run on the same node with different stores.
Usage
Instead of using name: __MODULE__
in GenServer registration, use:
name: ExESDB.StoreNaming.genserver_name(__MODULE__, store_id)
This will create store-specific names like :"ex_esdb_store_my_store"
when
a store_id is provided, or fall back to the module name for backward compatibility.
Valid Process Names
This module ensures that all generated names are valid for use with GenServers, Supervisors, and other OTP processes. The generated names are simple atoms that can be registered locally, which is compatible with Elixir's process naming requirements.
Summary
Functions
Generate a store-specific child spec id.
Extract store_id from options.
Generate a store-specific name for a GenServer.
Generate a store-specific name for partition supervisors like StreamsWriters, etc.
Functions
Generate a store-specific child spec id.
This function creates unique child spec IDs based on the module and store_id, allowing multiple instances of the same supervisor child to run with different stores.
Parameters
module
- The GenServer module (typically__MODULE__
)store_id
- The store identifier (string or atom)
Examples
iex> ExESDB.StoreNaming.child_spec_id(ExESDB.Store, "my_store")
:"ex_esdb_store_my_store"
iex> ExESDB.StoreNaming.child_spec_id(ExESDB.Store, nil)
ExESDB.Store
Extract store_id from options.
This is a convenience function to extract the store_id from the standard options keyword list passed to GenServers.
Examples
iex> ExESDB.StoreNaming.extract_store_id([store_id: "my_store", timeout: 5000])
"my_store"
iex> ExESDB.StoreNaming.extract_store_id([timeout: 5000])
nil
Generate a store-specific name for a GenServer.
This function creates unique GenServer names based on the module and store_id, allowing multiple instances of the same GenServer to run with different stores.
The function returns a valid process name that can be used for GenServers, Supervisors, and other OTP processes. When a store_id is provided, it creates a unique atom by combining the module name with the store_id. When no store_id is provided, it falls back to the module name for backward compatibility.
Parameters
module
- The GenServer module (typically__MODULE__
)store_id
- The store identifier (string or atom)
Examples
iex> ExESDB.StoreNaming.genserver_name(ExESDB.Store, "my_store")
:"ex_esdb_store_my_store"
iex> ExESDB.StoreNaming.genserver_name(ExESDB.Store, nil)
ExESDB.Store
iex> ExESDB.StoreNaming.genserver_name(ExESDB.LeaderWorker, "cluster_store")
:"ex_esdb_leader_worker_cluster_store"
Generate a store-specific name for partition supervisors like StreamsWriters, etc.
This function creates unique names for global resources that would otherwise conflict between multiple ExESDB instances.
Parameters
base_name
- The base name atom (e.g., ExESDB.StreamsWriters)store_id
- The store identifier (string or atom)
Examples
iex> ExESDB.StoreNaming.partition_name(ExESDB.StreamsWriters, "my_store")
:"exesdb_streamswriters_my_store"
iex> ExESDB.StoreNaming.partition_name(ExESDB.StreamsWriters, nil)
ExESDB.StreamsWriters