Raxol.Core.Runtime.Plugins.LifecycleHelper.Behaviour behaviour (Raxol v0.4.0)

View Source

Defines the behaviour for plugin lifecycle management.

This behaviour is responsible for:

  • Loading and unloading plugins
  • Managing plugin dependencies
  • Handling plugin state transitions
  • Coordinating plugin lifecycle events

Summary

Callbacks

cleanup_plugin(plugin_id, state)

@callback cleanup_plugin(plugin_id :: any(), state :: map()) :: :ok | {:error, any()}

Cleans up a plugin with the given plugin_id and state.

handle_state_transition(plugin_id, transition, state)

@callback handle_state_transition(
  plugin_id :: any(),
  transition :: any(),
  state :: map()
) :: {:ok, map()} | {:error, any()}

Handles a state transition for a plugin.

init_plugin(module, opts)

@callback init_plugin(module :: module(), opts :: map()) :: {:ok, map()} | {:error, any()}

Initializes a plugin with the given module and options.

initialize_plugins( plugin_specs, manager_pid, plugin_registry, command_registry_table, api_version, app_config, env )

@callback initialize_plugins(
  plugin_specs :: [map()],
  manager_pid :: pid(),
  plugin_registry :: pid() | atom(),
  command_registry_table :: atom(),
  api_version :: String.t(),
  app_config :: map(),
  env :: atom()
) :: {:ok, {[map()], [map()]}} | {:error, any()}

Initializes plugins based on discovery and dependencies.

load_plugin( plugin_id_or_module, config, plugins, metadata, plugin_states, load_order, command_table, plugin_config )

@callback load_plugin(
  plugin_id_or_module :: String.t() | module(),
  config :: map(),
  plugins :: map(),
  metadata :: map(),
  plugin_states :: map(),
  load_order :: list(),
  command_table :: atom(),
  plugin_config :: map()
) :: {:ok, map()} | {:error, any()}

Loads a plugin by its ID or module.

load_plugin_by_module( plugin_module, config, plugins, metadata, plugin_states, load_order, command_table, plugin_config )

@callback load_plugin_by_module(
  plugin_module :: atom(),
  config :: map(),
  plugins :: map(),
  metadata :: map(),
  plugin_states :: map(),
  load_order :: list(),
  command_table :: atom(),
  plugin_config :: map()
) :: {:ok, map()} | {:error, any()}

Loads a plugin by its module name when the module is already known.

reload_plugin( plugin_id, plugins, metadata, plugin_states, load_order, command_table, plugin_config )

@callback reload_plugin(
  plugin_id :: String.t(),
  plugins :: map(),
  metadata :: map(),
  plugin_states :: map(),
  load_order :: list(),
  command_table :: atom(),
  plugin_config :: map()
) :: {:ok, map()} | {:error, any()}

Reloads a plugin by its ID.

reload_plugin_from_disk( plugin_id, current_state, plugin_spec, manager_pid, plugin_registry, command_registry_table, api_version, loaded_plugins_paths )

@callback reload_plugin_from_disk(
  plugin_id :: atom(),
  current_state :: map() | nil,
  plugin_spec :: map(),
  manager_pid :: pid(),
  plugin_registry :: pid() | atom(),
  command_registry_table :: atom(),
  api_version :: String.t(),
  loaded_plugins_paths :: [String.t()]
) :: {:ok, map()} | {:error, any()}

Reloads a specific plugin from disk.

terminate_plugin(plugin_id, state, reason)

@callback terminate_plugin(
  plugin_id :: any(),
  state :: map(),
  reason :: any()
) :: :ok | {:error, any()}

Terminates a plugin with the given plugin_id, state, and reason.

unload_plugin(plugin_id, plugins, metadata, plugin_states, load_order, command_table)

@callback unload_plugin(
  plugin_id :: String.t(),
  plugins :: map(),
  metadata :: map(),
  plugin_states :: map(),
  load_order :: list(),
  command_table :: atom()
) :: {:ok, map()} | {:error, any()}

Unloads a plugin by its ID.