jonnify·bcs /bcs/elixir-core/otp-application/the-application

B2.1.4 · dive 4 of 6 · module B2.1

The application boots the contract.

EchoData.Application.start/2: seed the lock-free Snowflake, prove the branded-id contract against a committed vector, then root the tree. Thirteen lines, in that order.

Boot in three steps: Snowflake, the contract self-check, the one_for_one root. Select a step.
Snowflake.start()lock-free node seeded BrandedId.self_check!placement USR0KHTOWnGLuC = 234878118returns {:ok, codec mode} one_for_one Supervisorthe tree’s root
readout · Select a step. The application starts the Snowflake, proves the branded-id contract (placement USR0KHTOWnGLuC = 234878118), then roots a one_for_one supervisor.
§1

The idea

echo_data · application.ex

The OTP application is a system’s first breath, and EchoData.Application.start/2 does three things in order. It starts the lock-free Snowflake so ids can be minted; it runs the branded-id self-check, which proves the codec-and-hash contract before a single system exists; and only then does it root a one_for_one supervisor. The boot proves the contract or it refuses to start — thirteen lines, and the order is the point.

The self-check is the contract made executable. It mints, encodes, decodes, and hashes a known id and asserts the result against a committed vector — the same placement(USR0KHTOWnGLuC) = 234878118 the figures cite — and returns the codec mode, native or the pure-Elixir fallback, so the log records which path served. A node that cannot reproduce the vector never reaches its first message.

Codemojex starts the same way. Before a room can be supervised, the application has proven that every node mints and decodes branded ids identically; a room on one machine and a worker on another agree on what a player’s id means because the contract was checked at boot, not assumed. The application is where the law stops being a claim and becomes a running guarantee.

§2

The source

echo_data · committed, verbatim

echo_data/lib/echo_data/application.ex — complete, 13 lines

defmodule EchoData.Application do
  @moduledoc false
  use Application
  require Logger

  @impl true
  def start(_type, _args) do
    :ok = EchoData.Snowflake.start()
    {:ok, mode} = EchoData.BrandedId.self_check!()
    Logger.info("EchoData: contract self-check passed, codec=#{mode}")
    Supervisor.start_link([], strategy: :one_for_one, name: EchoData.Supervisor)
  end
end
§4

The doors

the sibling courses
§3

References

sources · related

Sources

Related