Module pobox

Generic process that acts as an external mailbox and a message buffer that will drop requests as required.

Copyright © Fred Hebert, Geoff Cant

Behaviours: gen_statem.

Authors: Fred Hebert (mononcqc@ferd.ca), Geoff Cant (nem@erlang.geek.nz), Eric des Courtis (eric.descourtis@mitel.com).

Description

Generic process that acts as an external mailbox and a message buffer that will drop requests as required. For more information, see README.txt

Data Types

drop()

drop() = non_neg_integer()

filter()

filter() = fun((Msg::term(), State::term()) -> {{ok, NewMsg::term()} | drop, State::term()} | skip)

in()

in() = {post, Msg::term()}

mail()

mail() = {mail, Self::pid(), Msgs::list(), Count::non_neg_integer(), Lost::drop()}

max()

max() = pos_integer()

name()

name() = {local, atom()} | {global, term()} | atom() | pid() | {via, module(), term()}

note()

note() = {mail, Self::pid(), new_data}

Function Index

active/3Forces the buffer into an active state where it will send the data it has accumulated.
callback_mode/0
give_away/3Give away the PO Box ownership to another process.
give_away/4Give away the PO Box ownership to another process.
notify/1Forces the buffer into its notify state, where it will send a single message alerting the Owner of new messages before going back to the passive state.
post/2Sends a message to the PO Box, to be buffered.
post_sync/2Sends a message to the PO Box, to be buffered.
post_sync/3
resize/2Allows to take a given buffer, and make it larger or smaller.
resize/3Allows to take a given buffer, and make it larger or smaller.
start_link/1
start_link/2
start_link/3Starts a new buffer process.
start_link/4
start_link/5
usage/1Get the number of items in the PO Box and the capacity.
usage/2Get the number of items in the PO Box and the capacity.

Function Details

active/3

active(Box::name(), Fun::filter(), State::term()) -> ok

Forces the buffer into an active state where it will send the data it has accumulated. The fun passed needs to have two arguments: A message, and a term for state. The function can return, for each element, a tuple of the form {Res, NewState}, where Res can be: - {ok, Msg} to receive the message in the block that gets shipped - drop to ignore the message - skip to stop removing elements from the stack, and keep them for later.

callback_mode/0

callback_mode() -> any()

give_away/3

give_away(Box::name(), Dest::name(), Timeout::timeout()) -> boolean()

Give away the PO Box ownership to another process. This will send a message in the following form to Dest: {pobox_transfer, BoxPid :: pid(), PreviousOwnerPid :: pid(), undefined, give_away}

give_away/4

give_away(Box::name(), Dest::name(), DestData::term(), Timeout::timeout()) -> boolean()

Give away the PO Box ownership to another process. This will send a message in the following form to Dest: {pobox_transfer, BoxPid :: pid(), PreviousOwnerPid :: pid(), DestData :: term(), give_away}

notify/1

notify(Box::name()) -> ok

Forces the buffer into its notify state, where it will send a single message alerting the Owner of new messages before going back to the passive state.

post/2

post(Box::name(), Msg::term()) -> ok

Sends a message to the PO Box, to be buffered.

post_sync/2

post_sync(Box::name(), Msg::term()) -> ok | full

Sends a message to the PO Box, to be buffered. But give additional feedback about if PO Box is full. This is very useful when combined with the keep_old buffer type because it tells you the message will be dropped.

post_sync/3

post_sync(Box::name(), Msg::term(), Timeout::timeout()) -> ok | full

resize/2

resize(Box::name(), NewMaxSize::max()) -> ok

Allows to take a given buffer, and make it larger or smaller. A buffer can be made larger without overhead, but it may take more work to make it smaller given there could be a need to drop messages that would now be considered overflow.

resize/3

resize(Box::name(), NewMaxSize::max(), Timeout::timeout()) -> ok

Allows to take a given buffer, and make it larger or smaller. A buffer can be made larger without overhead, but it may take more work to make it smaller given there could be a need to drop messages that would now be considered overflow.

start_link/1

start_link(Opts::map() | list()) -> {ok, pid()}

start_link/2

start_link(Name::name(), Opts::map() | list()) -> {ok, pid()}

start_link/3

start_link(Owner::name(), MaxSize::max(), Type::stack | queue | keep_old | {mod, module()}) -> {ok, pid()}

Starts a new buffer process. The implementation can either be a stack or a queue, depending on which messages will be dropped (older ones or newer ones). Note that stack buffers do not guarantee message ordering. The initial state can be either passive or notify, depending on whether the user wants to get notifications of new messages as soon as possible.

start_link/4

start_link(Owner::name(), MaxSize::max(), Type::stack | queue | keep_old | {mod, module()}, StateName::notify | passive) -> {ok, pid()}

start_link/5

start_link(Name::name(), Owner::name(), MaxSize::max(), Type::stack | queue | keep_old | {mod, module()}, StateName::notify | passive) -> {ok, pid()}

usage/1

usage(Box::name()) -> {non_neg_integer(), pos_integer()}

Get the number of items in the PO Box and the capacity.

usage/2

usage(Box::name(), Timeout::timeout()) -> {non_neg_integer(), pos_integer()}

Get the number of items in the PO Box and the capacity.


Generated by EDoc