distribute/discovery/beam_adapter
BEAM discovery adapter using Erlang node monitoring.
This module provides the reference implementation of DiscoveryAdapter
using the BEAM’s built-in node monitoring (net_kernel, erlang:nodes/0).
It is the default adapter used by the distribute/discovery facade.
Features
- Native BEAM discovery via
erlang:nodes/0andnet_kernel - Automatic node up/down detection via
erlang:monitor_node/2 - Periodic sync with configurable interval
- OTP actor implementation for supervision compatibility
Architecture
The adapter runs as a supervised OTP actor that handles:
- Monitoring connected Erlang nodes
- Emitting PeerUp/PeerDown events to subscribers
- Maintaining a snapshot of known peers
- Periodic background sync
Usage
Typically you don’t use this module directly. Instead, use the
distribute/discovery facade which manages a singleton instance.
For custom configurations:
import distribute/discovery/adapter
import distribute/discovery/beam_adapter
let opts = adapter.default_options("my_discovery")
let adapter = beam_adapter.new()
let assert Ok(handle) = adapter.start(opts)
Types
Values
pub fn child_spec(
options: types.AdapterOptions,
) -> supervision.ChildSpecification(types.AdapterHandle)
Create a child specification for OTP supervision.
Use this when adding the adapter to a supervision tree.
Example
import gleam/otp/static_supervisor as supervisor
supervisor.new(supervisor.OneForOne)
|> supervisor.add(beam_adapter.child_spec(opts))
|> supervisor.start()
pub fn get_handle(
name: String,
) -> Result(types.AdapterHandle, Nil)
Get a handle to a running adapter by name.
This function looks up a previously started adapter by its registered name
and returns a handle that can be used with the DiscoveryAdapter functions.
pub fn new() -> adapter.DiscoveryAdapter
Create a new BEAM discovery adapter instance.
Returns a DiscoveryAdapter record with function pointers for all
adapter operations.
Example
let adapter = beam_adapter.new()
let assert Ok(handle) = adapter.start(options)
let assert Ok(peers) = adapter.snapshot(handle)