View Source ProcessHub.Service.HookManager (ProcessHub v0.4.0-beta)

The hook manager service provides API functions for managing hook dispatching, registration, and lookup.

Summary

Functions

Executes the hook handlers and lets each handler modify the hook data.

Dispatches the hook to the registered handlers and passes the hook data as an argument.

Dispatches multiple hooks to the registered handlers.

Returns all registered hook handlers for the given hook key

Types

@type handler_id() :: atom() | String.t()
@type handler_priority() :: integer()
@type hook_handlers() :: %{required(hook_key()) => [t()]}
@type hook_key() ::
  :pre_cluster_join_hook
  | :post_cluster_join_hook
  | :pre_cluster_leave_hook
  | :post_cluster_leave_hook
  | :registry_pid_insert_hook
  | :registry_pid_remove_hook
  | :children_migrated_hook
  | :forwarded_migration_hook
  | :priority_state_updated_hook
  | :pre_nodes_redistribution_hook
  | :post_nodes_redistribution_hook
  | :pre_children_start_hook
  | :post_children_start_hook
  | :pre_children_redistribution_hook
  | :coordinator_shutdown_hook
  | :process_startups_hook
@type t() :: %ProcessHub.Service.HookManager{
  a: [any()],
  f: atom(),
  id: handler_id(),
  m: module(),
  p: handler_priority() | nil
}

Functions

Link to this function

cancel_handler(hook_table, hook_key, handler_id)

View Source
@spec cancel_handler(:ets.tid(), hook_key(), handler_id()) :: :ok

Cancels a hook handler.

Link to this function

dispatch_alter_hook(hook_table, hook_key, hook_data)

View Source
@spec dispatch_alter_hook(:ets.tid(), hook_key(), any()) :: any()

Executes the hook handlers and lets each handler modify the hook data.

It is possible to register a hook handler with a wildcard argument :_ which will be replaced with the hook data when the hook is dispatched.

Works similar to dispatch_hook/3 but each handler is expected to return the modified hook data. The hook data is passed to the next handler in the chain.

Link to this function

dispatch_hook(hook_table, hook_key, hook_data)

View Source
@spec dispatch_hook(:ets.tid(), hook_key(), any()) :: :ok

Dispatches the hook to the registered handlers and passes the hook data as an argument.

It is possible to register a hook handler with a wildcard argument :_ which will be replaced with the hook data when the hook is dispatched.

Link to this function

dispatch_hooks(hook_table, hooks)

View Source
@spec dispatch_hooks(:ets.tid(), [t()]) :: :ok

Dispatches multiple hooks to the registered handlers.

Link to this function

register_handler(hook_table, hook_key, hook_handler)

View Source
@spec register_handler(:ets.tid(), hook_key(), t()) ::
  :ok | {:error, :handler_id_not_unique}

Registers a new hook handler.

Link to this function

register_handlers(hook_table, hook_key, hook_handlers)

View Source
@spec register_handlers(:ets.tid(), hook_key(), [t()]) ::
  :ok | {:error, {:handler_id_not_unique, [handler_id()]}}

Registers a new hook handlers.

Link to this function

registered_handlers(hook_table, hook_key)

View Source
@spec registered_handlers(:ets.tid(), hook_key()) :: [t()]

Returns all registered hook handlers for the given hook key