Lamina.Server (lamina v0.4.0)
The Lamina configuration server.
This server is the owner of the ETS table used to store the configuration information and handles providers and their states as well as timers for refreshing and expiring the configuration.
Link to this section Summary
Link to this section Types
config_key()
Specs
config_key() :: Lamina.config_key()
lifetime()
Specs
lifetime() :: Lamina.Provider.lifetime()
provider()
Specs
provider() :: Lamina.Provider.t()
provider_state()
Specs
provider_state() :: any()
state()
Specs
state() :: Lamina.Server.State.t()
value()
Specs
value() :: any()
Link to this section Functions
child_spec(init_arg)
Returns a specification to start this module under a supervisor.
See Supervisor
.
get(module, config_key)
Specs
get(module(), config_key()) :: {:ok, value()} | {:error, ConfigNotFoundError.t() | NotRegisteredError.t()}
Retrieve a configuration value.
This is the function which is called by the dynamically generated
configuration functions in the configuration module, ie calling
MyHttpServer.Config.listen_port()
and
Lamina.Server.get(MyHttpServer.Config, :listen_port)
are functionally
identical.
Looks the server pid and ETS table up in Lamina registry, then queries the
table for the best match configuration value. In most cases this should allow
the configuration value to be returned quickly without having to wait for a
GenServer round-trip as both Registry
and the server use ETS tables with
read concurrency enabled.
The only case where a call needs to be made to the server is when the best
configuration value is marked as :volatile
by the provider - ie the value
can theoretically be different each time it's called. This is the case for
the Env
and ApplicationEnv
providers, as both of these provide wrappers
around a potentially volatile store.
Example
iex> Server.get(MyHttpServer.Config, :listen_port)
...> {:ok, 4000}
get!(module, config_key)
Specs
get!(module(), config_key()) :: value() | no_return()
A raising version of get/2
.
init(opts)
Initialise the configuration server.
Initialises the configuration server by calling the callbacks defined by the
Lamina
behaviour on the config module, starts all the module's providers and
loads all the configuration.
If any step in this process fails the server will fail to start.