#Module gproc#
gen_server
.
Authors: Ulf Wiger (ulf.wiger@erlang-consulting.com
).##Description## Extended process registry
This module implements an extended process registry
For a detailed description, see erlang07-wiger.pdf.
##Data Types##
###context()##
context() = {[scope()](#type-scope), [type()](#type-type)} | [type()](#type-type)
Local scope is the default
###headpat()##
headpat() = {[keypat()](#type-keypat), [pidpat()](#type-pidpat), ValPat}
###key()##
key() = {[type()](#type-type), [scope()](#type-scope), any()}
###keypat()##
keypat() = {[sel_type()](#type-sel_type) | [sel_var()](#type-sel_var), l | g | [sel_var()](#type-sel_var), any()}
###pidpat()##
pidpat() = pid() | [sel_var()](#type-sel_var)
selvar() = DollarVar | ''.
###scope()##
scope() = l | g
l = local registration; g = global registration
###sel_pattern()##
sel_pattern() = [{[headpat()](#type-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##
add_global_aggr_counter/1 | Registers a global (unique) aggregated counter. |
add_global_counter/2 | Registers a global (non-unique) counter. |
add_global_name/1 | Registers a global (unique) name. |
add_global_property/2 | Registers a global (non-unique) property. |
add_local_aggr_counter/1 | Registers a local (unique) aggregated counter. |
add_local_counter/2 | Registers a local (non-unique) counter. |
add_local_name/1 | Registers a local (unique) name. |
add_local_property/2 | Registers a local (non-unique) property. |
audit_process/1 | |
await/1 | Equivalent to await(Key, infinity). |
await/2 | Wait for a local name to be registered. |
cancel_wait/2 | |
default/1 | |
first/1 | Behaves as ets:first(Tab) for a given type of registration object. |
get_value/1 | Read the value stored with a key registered to the current process. |
info/1 | Similar to process_info(Pid) but with additional gproc info. |
info/2 | Similar to process_info(Pid, Item), but with additional gproc info. |
last/1 | Behaves as ets:last(Tab) for a given type of registration object. |
lookup_global_aggr_counter/1 | Lookup a global (unique) aggregated counter and returns its value. |
lookup_global_counters/1 | Look up all global (non-unique) instances of a given Counter. |
lookup_global_name/1 | Lookup a global unique name. |
lookup_global_properties/1 | Look up all global (non-unique) instances of a given Property. |
lookup_local_aggr_counter/1 | Lookup a local (unique) aggregated counter and returns its value. |
lookup_local_counters/1 | Look up all local (non-unique) instances of a given Counter. |
lookup_local_name/1 | Lookup a local unique name. |
lookup_local_properties/1 | Look up all local (non-unique) instances of a given Property. |
lookup_pid/1 | Lookup the Pid stored with a key. |
lookup_pids/1 | Returns a list of pids with the published key Key. |
lookup_values/1 | Retrieve the {Pid,Value} pairs corresponding to Key. |
mreg/3 | Register multiple {Key,Value} pairs of a given type and scope. |
nb_wait/1 | Wait for a local name to be registered. |
next/2 | Behaves as ets:next(Tab,Key) for a given type of registration object. |
prev/2 | Behaves as ets:prev(Tab,Key) for a given type of registration object. |
reg/1 | Equivalent to reg(Key, default(Key)). |
reg/2 | Register a name or property for the current process. |
select/1 | Equivalent to select(all, Pat). |
select/2 | Perform a select operation on the process registry. |
select/3 | Like select/2 but returns Limit objects at a time. |
send/2 | Sends a message to the process, or processes, corresponding to Key. |
set_value/2 | Sets the value of the registeration entry given by Key. |
start_link/0 | Starts the gproc server. |
table/1 | Equivalent to table(Context, []). |
table/2 | QLC table generator for the gproc registry. |
unreg/1 | Unregister a name or property. |
update_counter/2 | Updates the counter registered as Key for the current process. |
where/1 | Returns the pid registered as Key. |
##Function Details##
###add_global_aggr_counter/1##
add_global_aggr_counter(Name) -> any()
Equivalent to reg({a, g, Name})
.
Registers a global (unique) aggregated counter.
###add_global_counter/2##
add_global_counter(Name, Initial) -> any()
Registers a global (non-unique) counter. @equiv reg({c,g,Name},Value)
###add_global_name/1##
add_global_name(Name) -> any()
Registers a global (unique) name. @equiv reg({n,g,Name})
###add_global_property/2##
add_global_property(Name, Value) -> any()
Registers a global (non-unique) property. @equiv reg({p,g,Name},Value)
###add_local_aggr_counter/1##
add_local_aggr_counter(Name) -> any()
Equivalent to reg({a, l, Name})
.
Registers a local (unique) aggregated counter.
###add_local_counter/2##
add_local_counter(Name, Initial) -> any()
Registers a local (non-unique) counter. @equiv reg({c,l,Name},Value)
###add_local_name/1##
add_local_name(Name) -> any()
Registers a local (unique) name. @equiv reg({n,l,Name})
###add_local_property/2##
add_local_property(Name, Value) -> any()
Registers a local (non-unique) property. @equiv reg({p,l,Name},Value)
###audit_process/1##
audit_process(Pid) -> any()
###await/1##
await(Key::[key()](#type-key)) -> {pid(), Value}
Equivalent to await(Key, infinity)
.
###await/2##
await(Key::[key()](#type-key), Timeout) -> {pid(), Value}
* Timeout = integer() | infinity
Wait for a local name to be registered. The function raises an exception if the timeout expires. Timeout must be either an interger > 0 or 'infinity'. A small optimization: we first perform a lookup, to see if the name is already registered. This way, the cost of the operation will be roughly the same as of where/1 in the case where the name is already registered (the difference: await/2 also returns the value).
###cancel_wait/2##
cancel_wait(Key, Ref) -> any()
###default/1##
default(X1) -> any()
###first/1##
first(Type::[type()](#type-type)) -> [key()](#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
* ProcessInfo = [{gproc, [{Key, Value}]} | 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()](#type-context)) -> [key()](#type-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_global_aggr_counter/1##
lookup_global_aggr_counter(Name::any()) -> integer()
Equivalent to where({a, g, Name})
.
Lookup a global (unique) aggregated counter and returns its value.
Fails if there is no such object.
###lookup_global_counters/1##
lookup_global_counters(Counter::any()) -> [{pid(), Value::integer()}]
Equivalent to lookup_values({c, g, Counter})
.
Look up all global (non-unique) instances of a given Counter.
Returns a list of {Pid, Value} tuples for all matching objects.
###lookup_global_name/1##
lookup_global_name(Name::any()) -> pid()
Equivalent to where({n, g, Name})
.
Lookup a global unique name. Fails if there is no such name.
###lookup_global_properties/1##
lookup_global_properties(Property::any()) -> [{pid(), Value}]
Equivalent to lookup_values({p, g, Property})
.
Look up all global (non-unique) instances of a given Property.
Returns a list of {Pid, Value} tuples for all matching objects.
###lookup_local_aggr_counter/1##
lookup_local_aggr_counter(Name::any()) -> integer()
Equivalent to where({a, l, Name})
.
Lookup a local (unique) aggregated counter and returns its value.
Fails if there is no such object.
###lookup_local_counters/1##
lookup_local_counters(Counter::any()) -> [{pid(), Value::integer()}]
Equivalent to lookup_values({c, l, Counter})
.
Look up all local (non-unique) instances of a given Counter.
Returns a list of {Pid, Value} tuples for all matching objects.
###lookup_local_name/1##
lookup_local_name(Name::any()) -> pid()
Equivalent to where({n, l, Name})
.
Lookup a local unique name. Fails if there is no such name.
###lookup_local_properties/1##
lookup_local_properties(Property::any()) -> [{pid(), Value}]
Equivalent to lookup_values({p, l, Property})
.
Look up all local (non-unique) instances of a given Property.
Returns a list of {Pid, Value} tuples for all matching objects.
###lookup_pid/1##
lookup_pid(Key) -> Pid
Lookup the Pid stored with a key.
###lookup_pids/1##
lookup_pids(Key::[key()](#type-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.
###lookup_values/1##
lookup_values(Key::[key()](#type-key)) -> [{pid(), Value}]
Retrieve the {Pid,Value}
pairs corresponding to Key.
Key refer to any type of registry object. If it refers to a unique object, the list will be of length 0 or 1. If it refers to a non-unique object, the return value can be a list of any length.
###mreg/3##
mreg(T::[type()](#type-type), X2::[scope()](#type-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.
###nb_wait/1##
nb_wait(Key::[key()](#type-key)) -> Ref
Wait for a local name to be registered. The caller can expect to receive a message, {gproc, Ref, registered, {Key, Pid, Value}}, once the name is registered.
###next/2##
next(Context::[context()](#type-context), Key::[key()](#type-key)) -> [key()](#type-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()](#type-context), Key::[key()](#type-key)) -> [key()](#type-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()](#type-key)) -> true
Equivalent to reg(Key, default(Key))
.
###reg/2##
reg(Key::[key()](#type-key), Value) -> true
Register a name or property for the current process
###select/1##
select(Pat::[select_pattern()](#type-select_pattern)) -> list([sel_object()](#type-sel_object))
Equivalent to select(all, Pat)
.
###select/2##
select(Type::[sel_type()](#type-sel_type), Pat::[sel_pattern()](#type-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()](#type-sel_type), Pat::[sel_patten()](#type-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()](#type-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()](#type-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() -> {ok, pid()}
Starts the gproc server.
This function is intended to be called from gproc_sup, as part of starting the gproc application.
###table/1##
table(Context::[context()](#type-context)) -> any()
Equivalent to table(Context, [])
.
###table/2##
table(Context::[context()](#type-context), Opts) -> any()
QLC table generator for the gproc registry.
Context specifies which subset of the registry should be queried.
See http://www.erlang.org/doc/man/qlc.html
.
###unreg/1##
unreg(Key::[key()](#type-key)) -> true
Unregister a name or property.
###update_counter/2##
update_counter(Key::[key()](#type-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()](#type-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, Oct 23 2010, 20:54:23.