PacketFlow.Component (packetflow v0.1.0)

Component lifecycle management for PacketFlow

This module provides:

  • Component initialization
  • Component state management
  • Component dependency injection
  • Component cleanup
  • Component health monitoring

Summary

Functions

Check component health

Returns a specification to start this module under a supervisor.

Get component health

Get component information

Callback implementation for GenServer.init/1.

List all components

Unregister a component

Unwatch component lifecycle events

Update component configuration

Update component state

Watch component lifecycle events

Types

component_config()

@type component_config() :: map()

component_id()

@type component_id() :: atom()

component_info()

@type component_info() :: %{
  id: component_id(),
  module: module(),
  state: component_state(),
  config: component_config(),
  dependencies: [component_id()],
  health: :healthy | :unhealthy | :degraded,
  last_heartbeat: integer()
}

component_state()

@type component_state() :: map()

Functions

add_component_dependency(id, dependency_id)

@spec add_component_dependency(component_id(), component_id()) ::
  :ok | {:error, String.t()}

Add component dependency

check_component_health(id)

@spec check_component_health(component_id()) :: :ok | {:error, String.t()}

Check component health

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

get_component_health(id)

@spec get_component_health(component_id()) :: :healthy | :unhealthy | :degraded | nil

Get component health

get_component_info(id)

@spec get_component_info(component_id()) :: component_info() | nil

Get component information

init(opts)

Callback implementation for GenServer.init/1.

list_components()

@spec list_components() :: [component_id()]

List all components

register_component(id, module, config \\ %{})

@spec register_component(component_id(), module(), component_config()) ::
  {:ok, component_info()} | {:error, String.t()}

Register a component

remove_component_dependency(id, dependency_id)

@spec remove_component_dependency(component_id(), component_id()) ::
  :ok | {:error, String.t()}

Remove component dependency

start_link(opts \\ [])

unregister_component(id)

@spec unregister_component(component_id()) :: :ok | {:error, String.t()}

Unregister a component

unwatch_component(id, pid)

@spec unwatch_component(component_id(), pid()) :: :ok

Unwatch component lifecycle events

update_component_config(id, config)

@spec update_component_config(component_id(), component_config()) ::
  :ok | {:error, String.t()}

Update component configuration

update_component_state(id, state)

@spec update_component_state(component_id(), component_state()) ::
  :ok | {:error, String.t()}

Update component state

watch_component(id, pid)

@spec watch_component(component_id(), pid()) :: :ok

Watch component lifecycle events