Feline.Processor behaviour (feline v0.1.0-rc.1)

Copy Markdown View Source

Behaviour for pipeline processors.

Each processor implements callbacks to receive frames, transform them, and push results downstream or upstream. Use use Feline.Processor to adopt the behaviour and generate a child_spec/1 that wraps the module in a Feline.Processor.Server GenServer.

Callbacks

  • init/1 — initialize processor state from keyword options
  • handle_frame/4 — process a frame, return {:ok, state}, {:push, frame, direction, state}, or {:push_many, frames, state}
  • handle_info/3 — handle non-frame messages (optional)
  • handle_setup/2 — called once after pipeline linking (optional)
  • handle_cleanup/1 — called on processor shutdown (optional)

Summary

Types

direction()

@type direction() :: :downstream | :upstream

push_fn()

@type push_fn() :: (struct(), direction() -> :ok)

state()

@type state() :: term()

Callbacks

handle_cleanup(state)

(optional)
@callback handle_cleanup(state()) :: :ok

handle_frame(frame, direction, push_fn, state)

@callback handle_frame(frame :: struct(), direction(), push_fn(), state()) ::
  {:ok, state()}
  | {:push, struct(), direction(), state()}
  | {:push_many, [{struct(), direction()}], state()}

handle_info(msg, push_fn, state)

(optional)
@callback handle_info(msg :: term(), push_fn(), state()) :: {:ok, state()}

handle_setup(setup, state)

(optional)
@callback handle_setup(setup :: map(), state()) :: {:ok, state()}

init(opts)

@callback init(opts :: keyword()) :: {:ok, state()}

Functions

link(processor, next_processor)

queue_frame(pid, frame, direction \\ :downstream)

setup(pid, setup)