Raxol.Core.Behaviours.Lifecycle behaviour (Raxol v2.0.1)

View Source

Common behavior for lifecycle management across different components.

This behavior defines a consistent interface for components that have initialization, start, stop, and cleanup phases.

Summary

Callbacks

Checks if the component is healthy and running.

Initializes the component with the given options.

Restarts the component. Default implementation stops then starts.

Starts the component. Called after successful initialization.

Stops the component gracefully.

Cleans up resources. Always called during shutdown.

Functions

Default implementations for optional callbacks.

Types

opts()

@type opts() :: keyword()

reason()

@type reason() :: term()

state()

@type state() :: any()

Callbacks

health_check(state)

(optional)
@callback health_check(state()) :: :ok | {:error, reason()}

Checks if the component is healthy and running.

init(opts)

@callback init(opts()) :: {:ok, state()} | {:error, reason()}

Initializes the component with the given options.

restart(state, opts)

(optional)
@callback restart(state(), opts()) :: {:ok, state()} | {:error, reason()}

Restarts the component. Default implementation stops then starts.

start(state, opts)

@callback start(state(), opts()) :: {:ok, state()} | {:error, reason()}

Starts the component. Called after successful initialization.

stop(state, reason)

@callback stop(state(), reason()) :: {:ok, state()} | {:error, reason()}

Stops the component gracefully.

terminate(state, reason)

@callback terminate(state(), reason()) :: :ok

Cleans up resources. Always called during shutdown.

Functions

__using__(opts)

(macro)

Default implementations for optional callbacks.