MPP.Session.Store behaviour (mpp v0.15.0)

Copy Markdown View Source

Behaviour and dispatch helpers for pluggable session-channel persistence.

Updates are atomic read-modify-write operations. A backend must invoke the callback and persist its successful result without another update to the same channel interleaving between those steps.

MPP.Session.ETSStore is the application-started single-node default.

Summary

Callbacks

Delete channel state.

Look up a channel by ID.

Insert or replace channel state.

Atomically update channel state.

Functions

Return the application-started ETS store.

Delete a channel through a store reference.

Look up a channel through a store reference.

Insert or replace a channel through a store reference.

Atomically update a channel through a store reference.

Types

store_ref()

@type store_ref() :: module() | {module(), keyword()}

update_fun()

@type update_fun() :: (MPP.Session.Channel.t() | :not_found ->
                   {:ok, MPP.Session.Channel.t()} | {:error, term()})

Callbacks

delete(channel_id)

@callback delete(channel_id :: String.t()) :: :ok | {:error, term()}

Delete channel state.

get(channel_id)

@callback get(channel_id :: String.t()) ::
  {:ok, MPP.Session.Channel.t()} | :not_found | {:error, term()}

Look up a channel by ID.

put(channel)

@callback put(channel :: MPP.Session.Channel.t()) :: :ok | {:error, term()}

Insert or replace channel state.

update(channel_id, fun)

@callback update(channel_id :: String.t(), fun :: update_fun()) ::
  {:ok, MPP.Session.Channel.t()} | {:error, term()}

Atomically update channel state.

Functions

default_store()

@spec default_store() :: module()

Return the application-started ETS store.

delete(store, channel_id)

@spec delete(store_ref(), String.t()) :: :ok | {:error, term()}

Delete a channel through a store reference.

get(store, channel_id)

@spec get(store_ref(), String.t()) ::
  {:ok, MPP.Session.Channel.t()} | :not_found | {:error, term()}

Look up a channel through a store reference.

put(store, channel)

@spec put(store_ref(), MPP.Session.Channel.t()) :: :ok | {:error, term()}

Insert or replace a channel through a store reference.

update(store, channel_id, fun)

@spec update(store_ref(), String.t(), update_fun()) ::
  {:ok, MPP.Session.Channel.t()} | {:error, term()}

Atomically update a channel through a store reference.