Lamina.Server (lamina v0.2.2)

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

Functions

Returns a specification to start this module under a supervisor.

Retrieve a configuration value.

A raising version of get/2.

Initialise the configuration server.

Link to this section Types

Link to this type

config_key()

Specs

config_key() :: Lamina.config_key()

Specs

lifetime() :: Lamina.Provider.lifetime()

Specs

provider() :: Lamina.Provider.t()
Link to this type

provider_state()

Specs

provider_state() :: any()

Specs

state() :: Lamina.Server.State.t()

Specs

value() :: any()

Link to this section Functions

Link to this function

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

Link to this function

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}
Link to this function

get!(module, config_key)

Specs

get!(module(), config_key()) :: value() | no_return()

A raising version of get/2.

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.