PacketFlow.Component.Interface behaviour (packetflow v0.1.0)

Standard interfaces for PacketFlow components

This module defines the core interfaces that all PacketFlow components should implement to ensure consistent behavior and interoperability.

Summary

Callbacks

Component initialization interface (use component-specific init functions to avoid GenServer conflicts)

Component configuration interface - get configuration

Component dependency interface - get dependencies

Component monitoring interface - get metrics

Component capability interface - get provided capabilities

Component capability interface - get required capabilities

Component state interface - get current state

Component communication interface - handle message

Component monitoring interface - health check

Component communication interface - send message

Component lifecycle interface - start component

Component lifecycle interface - stop component

Component configuration interface - update configuration

Component state interface - update state

Component dependency interface - validate dependencies

Functions

Macro to implement standard component interface behaviors

Get component interface metadata

Validate that a module implements the component interface

Callbacks

component_init(config)

(optional)
@callback component_init(config :: map()) ::
  {:ok, state :: term()} | {:error, reason :: term()}

Component initialization interface (use component-specific init functions to avoid GenServer conflicts)

get_config()

(optional)
@callback get_config() :: map()

Component configuration interface - get configuration

get_dependencies()

(optional)
@callback get_dependencies() :: [atom()]

Component dependency interface - get dependencies

get_metrics()

(optional)
@callback get_metrics() :: map()

Component monitoring interface - get metrics

get_provided_capabilities()

(optional)
@callback get_provided_capabilities() :: [term()]

Component capability interface - get provided capabilities

get_required_capabilities()

(optional)
@callback get_required_capabilities() :: [term()]

Component capability interface - get required capabilities

get_state()

(optional)
@callback get_state() :: term()

Component state interface - get current state

handle_message(message, state)

(optional)
@callback handle_message(message :: term(), state :: term()) ::
  {:ok, new_state :: term()}
  | {:ok, new_state :: term(), reply :: term()}
  | {:error, reason :: term()}

Component communication interface - handle message

health_check()

(optional)
@callback health_check() :: :healthy | :unhealthy | :degraded

Component monitoring interface - health check

send_message(target, message)

(optional)
@callback send_message(target :: atom(), message :: term()) ::
  :ok | {:error, reason :: term()}

Component communication interface - send message

start_component(config)

(optional)
@callback start_component(config :: map()) :: {:ok, pid()} | {:error, reason :: term()}

Component lifecycle interface - start component

stop_component()

(optional)
@callback stop_component() :: :ok | {:error, reason :: term()}

Component lifecycle interface - stop component

update_config(new_config)

(optional)
@callback update_config(new_config :: map()) :: :ok | {:error, reason :: term()}

Component configuration interface - update configuration

update_state(new_state)

(optional)
@callback update_state(new_state :: term()) :: :ok | {:error, reason :: term()}

Component state interface - update state

validate_dependencies()

(optional)
@callback validate_dependencies() :: :ok | {:error, [atom()]}

Component dependency interface - validate dependencies

Functions

__using__(opts \\ [])

(macro)

Macro to implement standard component interface behaviors

get_interface_metadata(module)

Get component interface metadata

validate_component_interface(module)

Validate that a module implements the component interface