Module gproc

Extended process registry.

Behaviours: gen_server.

Authors: Ulf Wiger (ulf.wiger@ericsson.com).

Description

Extended process registry

This module implements an extended process registry

For a detailed description, see gproc/doc/erlang07-wiger.pdf.

Data Types

context()

context() = {scope(), type()} | type()

Local scope is the default

headpat()

headpat() = {keypat(), pidpat(), ValPat}

key()

key() = {type(), scope(), any()}

keypat()

keypat() = {sel_type() | sel_var(), l | g | sel_var(), any()}

pidpat()

pidpat() = pid() | sel_var()

sel_var() = DollarVar | '_'.

scope()

scope() = l | g

l = local registration; g = global registration

sel_pattern()

sel_pattern() = [{headpat(), Guards, Prod}]

sel_type()

sel_type() = n | p | c | a | names | props | counters | aggr_counters

type()

type() = n | p | c | a

n = name; p = property; c = counter; a = aggregate_counter

Function Index

first/1Behaves as ets:first(Tab) for a given type of registration object.
get_value/1Read the value stored with a key registered to the current process.
info/1Similar to process_info(Pid) but with additional gproc info.
info/2Similar to process_info(Pid, Item), but with additional gproc info.
last/1Behaves as ets:last(Tab) for a given type of registration object.
lookup_pid/1Lookup the Pid stored with a key.
lookup_pids/1Returns a list of pids with the published key Key.
mreg/3Register multiple {Key,Value} pairs of a given type and scope.
next/2Behaves as ets:next(Tab,Key) for a given type of registration object.
prev/2Behaves as ets:prev(Tab,Key) for a given type of registration object.
reg/1Equivalent to reg(Key, undefined).
reg/2Register a name or property for the current process.
select/1Equivalent to select(all, Pat).
select/2Perform a select operation on the process registry.
select/3Like select/2 but returns Limit objects at a time.
send/2Sends a message to the process, or processes, corresponding to Key.
set_value/2Sets the value of the registeration entry given by Key.
start_link/0
table/1
table/2
unreg/1Unregister a name or property.
update_counter/2Updates the counter registered as Key for the current process.
where/1Returns the pid registered as Key.

Function Details

first/1

first(Type::type()) -> key() | '$end_of_table'

Behaves as ets:first(Tab) for a given type of registration object.

See http://www.erlang.org/doc/man/ets.html#first-1. The registry behaves as an ordered_set table.

get_value/1

get_value(Key) -> Value

Read the value stored with a key registered to the current process.

If no such key is registered to the current process, this function exits.

info/1

info(Pid::pid()) -> ProcessInfo

Similar to process_info(Pid) but with additional gproc info.

Returns the same information as process_info(Pid), but with the addition of a gproc information item, containing the {Key,Value} pairs registered to the process.

info/2

info(Pid::pid(), Item::atom()) -> {Item, Info}

Similar to process_info(Pid, Item), but with additional gproc info.

For Item = gproc, this function returns a list of {Key, Value} pairs registered to the process Pid. For other values of Item, it returns the same as http://www.erlang.org/doc/man/erlang.html#process_info-2.

last/1

last(Context::context()) -> key() | '$end_of_table'

Behaves as ets:last(Tab) for a given type of registration object.

See http://www.erlang.org/doc/man/ets.html#last-1. The registry behaves as an ordered_set table.

lookup_pid/1

lookup_pid(Key) -> Pid

Lookup the Pid stored with a key.

lookup_pids/1

lookup_pids(Key::key()) -> [pid()]

Returns a list of pids with the published key Key

If the type of registration entry is either name or aggregated counter, this function will return either an empty list, or a list of one pid. For non-unique types, the return value can be a list of any length.

mreg/3

mreg(T::type(), X2::scope(), KVL::[{Key::any(), Value::any()}]) -> true

Register multiple {Key,Value} pairs of a given type and scope.

This function is more efficient than calling reg/2 repeatedly.

next/2

next(Context::context(), Key::key()) -> key() | '$end_of_table'

Behaves as ets:next(Tab,Key) for a given type of registration object.

See http://www.erlang.org/doc/man/ets.html#next-2. The registry behaves as an ordered_set table.

prev/2

prev(Context::context(), Key::key()) -> key() | '$end_of_table'

Behaves as ets:prev(Tab,Key) for a given type of registration object.

See http://www.erlang.org/doc/man/ets.html#prev-2. The registry behaves as an ordered_set table.

reg/1

reg(Key::key()) -> true

Equivalent to reg(Key, undefined).

reg/2

reg(Key::key(), Value) -> true

Register a name or property for the current process

select/1

select(Pat::select_pattern()) -> list(sel_object())

Equivalent to select(all, Pat).

select/2

select(Type::sel_type(), Pat::sel_pattern()) -> [{Key, Pid, Value}]

Perform a select operation on the process registry.

The physical representation in the registry may differ from the above, but the select patterns are transformed appropriately.

select/3

select(Type::sel_type(), Pat::sel_patten(), Limit::integer()) -> [{Key, Pid, Value}]

Like select/2 but returns Limit objects at a time.

See http://www.erlang.org/doc/man/ets.html#select-3.

send/2

send(Key::key(), Msg::any()) -> Msg

Sends a message to the process, or processes, corresponding to Key.

If Key belongs to a unique object (name or aggregated counter), this function will send a message to the corresponding process, or fail if there is no such process. If Key is for a non-unique object type (counter or property), Msg will be send to all processes that have such an object.

set_value/2

set_value(Key::key(), Value) -> true

Sets the value of the registeration entry given by Key

Key is assumed to exist and belong to the calling process. If it doesn't, this function will exit.

Value can be any term, unless the object is a counter, in which case it must be an integer.

start_link/0

start_link() -> any()

table/1

table(Type) -> any()

table/2

table(T, Opts) -> any()

unreg/1

unreg(Key::key()) -> true

Unregister a name or property.

update_counter/2

update_counter(Key::key(), Incr::integer()) -> integer()

Updates the counter registered as Key for the current process.

This function works like ets:update_counter/3 (see http://www.erlang.org/doc/man/ets.html#update_counter-3), but will fail if the type of object referred to by Key is not a counter.

where/1

where(Key::key()) -> pid()

Returns the pid registered as Key

The type of registration entry must be either name or aggregated counter. Otherwise this function will exit. Use lookup_pids/1 in these cases.


Generated by EDoc, Sep 20 2009, 09:15:40.