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

Architecture

The adapter runs as a supervised OTP actor that handles:

  1. Monitoring connected Erlang nodes
  2. Emitting PeerUp/PeerDown events to subscribers
  3. Maintaining a snapshot of known peers
  4. 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

Commands handled by the BEAM discovery adapter actor.

pub opaque type Command

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)
Search Document