gproc.html 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  2. <html>
  3. <head>
  4. <title>Module gproc</title>
  5. <link rel="stylesheet" type="text/css" href="stylesheet.css" title="EDoc">
  6. </head>
  7. <body bgcolor="white">
  8. <div class="navbar"><a name="#navbar_top"></a><table width="100%" border="0" cellspacing="0" cellpadding="2" summary="navigation bar"><tr><td><a href="overview-summary.html" target="overviewFrame">Overview</a></td><td><a href="http://www.erlang.org/"><img src="erlang.png" align="right" border="0" alt="erlang logo"></a></td></tr></table></div>
  9. <hr>
  10. <h1>Module gproc</h1>
  11. <ul class="index"><li><a href="#description">Description</a></li><li><a href="#types">Data Types</a></li><li><a href="#index">Function Index</a></li><li><a href="#functions">Function Details</a></li></ul>Extended process registry.
  12. <p><b>Behaviours:</b> <a href="gen_server.html"><tt>gen_server</tt></a>.</p>
  13. <p><b>Authors:</b> Ulf Wiger (<a href="mailto:ulf.wiger@ericsson.com"><tt>ulf.wiger@ericsson.com</tt></a>).</p>
  14. <h2><a name="description">Description</a></h2>Extended process registry
  15. <p>This module implements an extended process registry</p>
  16. <p>For a detailed description, see gproc/doc/erlang07-wiger.pdf.</p>
  17. <h2><a name="types">Data Types</a></h2>
  18. <h3 class="typedecl"><a name="type-context">context()</a></h3>
  19. <p><tt>context() = {<a href="#type-scope">scope()</a>, <a href="#type-type">type()</a>} | <a href="#type-type">type()</a></tt></p>
  20. <p>Local scope is the default</p>
  21. <h3 class="typedecl"><a name="type-headpat">headpat()</a></h3>
  22. <p><tt>headpat() = {<a href="#type-keypat">keypat()</a>, <a href="#type-pidpat">pidpat()</a>, ValPat}</tt></p>
  23. <h3 class="typedecl"><a name="type-key">key()</a></h3>
  24. <p><tt>key() = {<a href="#type-type">type()</a>, <a href="#type-scope">scope()</a>, any()}</tt></p>
  25. <h3 class="typedecl"><a name="type-keypat">keypat()</a></h3>
  26. <p><tt>keypat() = {<a href="#type-sel_type">sel_type()</a> | <a href="#type-sel_var">sel_var()</a>, l | g | <a href="#type-sel_var">sel_var()</a>, any()}</tt></p>
  27. <h3 class="typedecl"><a name="type-pidpat">pidpat()</a></h3>
  28. <p><tt>pidpat() = pid() | <a href="#type-sel_var">sel_var()</a></tt></p>
  29. <p>sel_var() = DollarVar | '_'.</p>
  30. <h3 class="typedecl"><a name="type-scope">scope()</a></h3>
  31. <p><tt>scope() = l | g</tt></p>
  32. <p>l = local registration; g = global registration</p>
  33. <h3 class="typedecl"><a name="type-sel_pattern">sel_pattern()</a></h3>
  34. <p><tt>sel_pattern() = [{<a href="#type-headpat">headpat()</a>, Guards, Prod}]</tt></p>
  35. <h3 class="typedecl"><a name="type-sel_type">sel_type()</a></h3>
  36. <p><tt>sel_type() = n | p | c | a | names | props | counters | aggr_counters</tt></p>
  37. <h3 class="typedecl"><a name="type-type">type()</a></h3>
  38. <p><tt>type() = n | p | c | a</tt></p>
  39. <p>n = name; p = property; c = counter;
  40. a = aggregate_counter</p>
  41. <h2><a name="index">Function Index</a></h2>
  42. <table width="100%" border="1" cellspacing="0" cellpadding="2" summary="function index"><tr><td valign="top"><a href="#first-1">first/1</a></td><td>Behaves as ets:first(Tab) for a given type of registration object.</td></tr>
  43. <tr><td valign="top"><a href="#get_value-1">get_value/1</a></td><td>Read the value stored with a key registered to the current process.</td></tr>
  44. <tr><td valign="top"><a href="#info-1">info/1</a></td><td>Similar to <code>process_info(Pid)</code> but with additional gproc info.</td></tr>
  45. <tr><td valign="top"><a href="#info-2">info/2</a></td><td>Similar to process_info(Pid, Item), but with additional gproc info.</td></tr>
  46. <tr><td valign="top"><a href="#last-1">last/1</a></td><td>Behaves as ets:last(Tab) for a given type of registration object.</td></tr>
  47. <tr><td valign="top"><a href="#lookup_pid-1">lookup_pid/1</a></td><td>Lookup the Pid stored with a key.</td></tr>
  48. <tr><td valign="top"><a href="#lookup_pids-1">lookup_pids/1</a></td><td>Returns a list of pids with the published key Key.</td></tr>
  49. <tr><td valign="top"><a href="#mreg-3">mreg/3</a></td><td>Register multiple {Key,Value} pairs of a given type and scope.</td></tr>
  50. <tr><td valign="top"><a href="#next-2">next/2</a></td><td>Behaves as ets:next(Tab,Key) for a given type of registration object.</td></tr>
  51. <tr><td valign="top"><a href="#prev-2">prev/2</a></td><td>Behaves as ets:prev(Tab,Key) for a given type of registration object.</td></tr>
  52. <tr><td valign="top"><a href="#reg-1">reg/1</a></td><td>Equivalent to <a href="#reg-2"><tt>reg(Key, undefined)</tt></a>.
  53. </td></tr>
  54. <tr><td valign="top"><a href="#reg-2">reg/2</a></td><td>Register a name or property for the current process.</td></tr>
  55. <tr><td valign="top"><a href="#select-1">select/1</a></td><td>Equivalent to <a href="#select-2"><tt>select(all, Pat)</tt></a>.
  56. </td></tr>
  57. <tr><td valign="top"><a href="#select-2">select/2</a></td><td>Perform a select operation on the process registry.</td></tr>
  58. <tr><td valign="top"><a href="#select-3">select/3</a></td><td>Like <a href="#select-2"><code>select/2</code></a> but returns Limit objects at a time.</td></tr>
  59. <tr><td valign="top"><a href="#send-2">send/2</a></td><td>Sends a message to the process, or processes, corresponding to Key.</td></tr>
  60. <tr><td valign="top"><a href="#set_value-2">set_value/2</a></td><td>Sets the value of the registeration entry given by Key.</td></tr>
  61. <tr><td valign="top"><a href="#start_link-0">start_link/0</a></td><td></td></tr>
  62. <tr><td valign="top"><a href="#table-1">table/1</a></td><td></td></tr>
  63. <tr><td valign="top"><a href="#table-2">table/2</a></td><td></td></tr>
  64. <tr><td valign="top"><a href="#unreg-1">unreg/1</a></td><td>Unregister a name or property.</td></tr>
  65. <tr><td valign="top"><a href="#update_counter-2">update_counter/2</a></td><td>Updates the counter registered as Key for the current process.</td></tr>
  66. <tr><td valign="top"><a href="#where-1">where/1</a></td><td>Returns the pid registered as Key.</td></tr>
  67. </table>
  68. <h2><a name="functions">Function Details</a></h2>
  69. <h3 class="function"><a name="first-1">first/1</a></h3>
  70. <div class="spec">
  71. <p><tt>first(Type::<a href="#type-type">type()</a>) -&gt; <a href="#type-key">key()</a> | '$end_of_table'</tt></p>
  72. </div><p><p>Behaves as ets:first(Tab) for a given type of registration object.</p>
  73. See <a href="http://www.erlang.org/doc/man/ets.html#first-1" target="_top"><tt>http://www.erlang.org/doc/man/ets.html#first-1</tt></a>.
  74. The registry behaves as an ordered_set table.</p>
  75. <h3 class="function"><a name="get_value-1">get_value/1</a></h3>
  76. <div class="spec">
  77. <p><tt>get_value(Key) -&gt; Value</tt></p>
  78. </div><p><p>Read the value stored with a key registered to the current process.</p>
  79. If no such key is registered to the current process, this function exits.</p>
  80. <h3 class="function"><a name="info-1">info/1</a></h3>
  81. <div class="spec">
  82. <p><tt>info(Pid::pid()) -&gt; ProcessInfo</tt>
  83. <ul class="definitions"><li><tt>ProcessInfo = [{gproc, [{Key, Value}]} | ProcessInfo]</tt></li>
  84. </ul></p>
  85. </div><p><p>Similar to <code>process_info(Pid)</code> but with additional gproc info.</p>
  86. Returns the same information as process_info(Pid), but with the
  87. addition of a <code>gproc</code> information item, containing the <code>{Key,Value}</code>
  88. pairs registered to the process.</p>
  89. <h3 class="function"><a name="info-2">info/2</a></h3>
  90. <div class="spec">
  91. <p><tt>info(Pid::pid(), Item::atom()) -&gt; {Item, Info}</tt></p>
  92. </div><p><p>Similar to process_info(Pid, Item), but with additional gproc info.</p>
  93. For <code>Item = gproc</code>, this function returns a list of <code>{Key, Value}</code> pairs
  94. registered to the process Pid. For other values of Item, it returns the
  95. same as <a href="http://www.erlang.org/doc/man/erlang.html#process_info-2" target="_top"><tt>http://www.erlang.org/doc/man/erlang.html#process_info-2</tt></a>.</p>
  96. <h3 class="function"><a name="last-1">last/1</a></h3>
  97. <div class="spec">
  98. <p><tt>last(Context::<a href="#type-context">context()</a>) -&gt; <a href="#type-key">key()</a> | '$end_of_table'</tt></p>
  99. </div><p><p>Behaves as ets:last(Tab) for a given type of registration object.</p>
  100. See <a href="http://www.erlang.org/doc/man/ets.html#last-1" target="_top"><tt>http://www.erlang.org/doc/man/ets.html#last-1</tt></a>.
  101. The registry behaves as an ordered_set table.</p>
  102. <h3 class="function"><a name="lookup_pid-1">lookup_pid/1</a></h3>
  103. <div class="spec">
  104. <p><tt>lookup_pid(Key) -&gt; Pid</tt></p>
  105. </div><p>Lookup the Pid stored with a key.
  106. </p>
  107. <h3 class="function"><a name="lookup_pids-1">lookup_pids/1</a></h3>
  108. <div class="spec">
  109. <p><tt>lookup_pids(Key::<a href="#type-key">key()</a>) -&gt; [pid()]</tt></p>
  110. </div><p><p>Returns a list of pids with the published key Key</p>
  111. If the type of registration entry is either name or aggregated counter,
  112. this function will return either an empty list, or a list of one pid.
  113. For non-unique types, the return value can be a list of any length.</p>
  114. <h3 class="function"><a name="mreg-3">mreg/3</a></h3>
  115. <div class="spec">
  116. <p><tt>mreg(T::<a href="#type-type">type()</a>, X2::<a href="#type-scope">scope()</a>, KVL::[{Key::any(), Value::any()}]) -&gt; true</tt></p>
  117. </div><p><p>Register multiple {Key,Value} pairs of a given type and scope.</p>
  118. This function is more efficient than calling <a href="#reg-2"><code>reg/2</code></a> repeatedly.</p>
  119. <h3 class="function"><a name="next-2">next/2</a></h3>
  120. <div class="spec">
  121. <p><tt>next(Context::<a href="#type-context">context()</a>, Key::<a href="#type-key">key()</a>) -&gt; <a href="#type-key">key()</a> | '$end_of_table'</tt></p>
  122. </div><p><p>Behaves as ets:next(Tab,Key) for a given type of registration object.</p>
  123. See <a href="http://www.erlang.org/doc/man/ets.html#next-2" target="_top"><tt>http://www.erlang.org/doc/man/ets.html#next-2</tt></a>.
  124. The registry behaves as an ordered_set table.</p>
  125. <h3 class="function"><a name="prev-2">prev/2</a></h3>
  126. <div class="spec">
  127. <p><tt>prev(Context::<a href="#type-context">context()</a>, Key::<a href="#type-key">key()</a>) -&gt; <a href="#type-key">key()</a> | '$end_of_table'</tt></p>
  128. </div><p><p>Behaves as ets:prev(Tab,Key) for a given type of registration object.</p>
  129. See <a href="http://www.erlang.org/doc/man/ets.html#prev-2" target="_top"><tt>http://www.erlang.org/doc/man/ets.html#prev-2</tt></a>.
  130. The registry behaves as an ordered_set table.</p>
  131. <h3 class="function"><a name="reg-1">reg/1</a></h3>
  132. <div class="spec">
  133. <p><tt>reg(Key::<a href="#type-key">key()</a>) -&gt; true</tt></p>
  134. </div><p>Equivalent to <a href="#reg-2"><tt>reg(Key, undefined)</tt></a>.</p>
  135. <h3 class="function"><a name="reg-2">reg/2</a></h3>
  136. <div class="spec">
  137. <p><tt>reg(Key::<a href="#type-key">key()</a>, Value) -&gt; true</tt></p>
  138. </div><p><p>Register a name or property for the current process</p>
  139. </p>
  140. <h3 class="function"><a name="select-1">select/1</a></h3>
  141. <div class="spec">
  142. <p><tt>select(Pat::<a href="#type-select_pattern">select_pattern()</a>) -&gt; list(<a href="#type-sel_object">sel_object()</a>)</tt></p>
  143. </div><p>Equivalent to <a href="#select-2"><tt>select(all, Pat)</tt></a>.</p>
  144. <h3 class="function"><a name="select-2">select/2</a></h3>
  145. <div class="spec">
  146. <p><tt>select(Type::<a href="#type-sel_type">sel_type()</a>, Pat::<a href="#type-sel_pattern">sel_pattern()</a>) -&gt; [{Key, Pid, Value}]</tt></p>
  147. </div><p><p>Perform a select operation on the process registry.</p>
  148. The physical representation in the registry may differ from the above,
  149. but the select patterns are transformed appropriately.</p>
  150. <h3 class="function"><a name="select-3">select/3</a></h3>
  151. <div class="spec">
  152. <p><tt>select(Type::<a href="#type-sel_type">sel_type()</a>, Pat::<a href="#type-sel_patten">sel_patten()</a>, Limit::integer()) -&gt; [{Key, Pid, Value}]</tt></p>
  153. </div><p><p>Like <a href="#select-2"><code>select/2</code></a> but returns Limit objects at a time.</p>
  154. See <a href="http://www.erlang.org/doc/man/ets.html#select-3" target="_top"><tt>http://www.erlang.org/doc/man/ets.html#select-3</tt></a>.</p>
  155. <h3 class="function"><a name="send-2">send/2</a></h3>
  156. <div class="spec">
  157. <p><tt>send(Key::<a href="#type-key">key()</a>, Msg::any()) -&gt; Msg</tt></p>
  158. </div><p><p>Sends a message to the process, or processes, corresponding to Key.</p>
  159. If Key belongs to a unique object (name or aggregated counter), this
  160. function will send a message to the corresponding process, or fail if there
  161. is no such process. If Key is for a non-unique object type (counter or
  162. property), Msg will be send to all processes that have such an object.</p>
  163. <h3 class="function"><a name="set_value-2">set_value/2</a></h3>
  164. <div class="spec">
  165. <p><tt>set_value(Key::<a href="#type-key">key()</a>, Value) -&gt; true</tt></p>
  166. </div><p><p>Sets the value of the registeration entry given by Key</p>
  167. <p>Key is assumed to exist and belong to the calling process.
  168. If it doesn't, this function will exit.</p>
  169. Value can be any term, unless the object is a counter, in which case
  170. it must be an integer.</p>
  171. <h3 class="function"><a name="start_link-0">start_link/0</a></h3>
  172. <div class="spec">
  173. <p><tt>start_link() -&gt; any()</tt></p>
  174. </div>
  175. <h3 class="function"><a name="table-1">table/1</a></h3>
  176. <div class="spec">
  177. <p><tt>table(Type) -&gt; any()</tt></p>
  178. </div>
  179. <h3 class="function"><a name="table-2">table/2</a></h3>
  180. <div class="spec">
  181. <p><tt>table(T, Opts) -&gt; any()</tt></p>
  182. </div>
  183. <h3 class="function"><a name="unreg-1">unreg/1</a></h3>
  184. <div class="spec">
  185. <p><tt>unreg(Key::<a href="#type-key">key()</a>) -&gt; true</tt></p>
  186. </div><p>Unregister a name or property.</p>
  187. <h3 class="function"><a name="update_counter-2">update_counter/2</a></h3>
  188. <div class="spec">
  189. <p><tt>update_counter(Key::<a href="#type-key">key()</a>, Incr::integer()) -&gt; integer()</tt></p>
  190. </div><p><p>Updates the counter registered as Key for the current process.</p>
  191. This function works like ets:update_counter/3
  192. (see <a href="http://www.erlang.org/doc/man/ets.html#update_counter-3" target="_top"><tt>http://www.erlang.org/doc/man/ets.html#update_counter-3</tt></a>), but
  193. will fail if the type of object referred to by Key is not a counter.</p>
  194. <h3 class="function"><a name="where-1">where/1</a></h3>
  195. <div class="spec">
  196. <p><tt>where(Key::<a href="#type-key">key()</a>) -&gt; pid()</tt></p>
  197. </div><p><p>Returns the pid registered as Key</p>
  198. The type of registration entry must be either name or aggregated counter.
  199. Otherwise this function will exit. Use <a href="#lookup_pids-1"><code>lookup_pids/1</code></a> in these
  200. cases.</p>
  201. <hr>
  202. <div class="navbar"><a name="#navbar_bottom"></a><table width="100%" border="0" cellspacing="0" cellpadding="2" summary="navigation bar"><tr><td><a href="overview-summary.html" target="overviewFrame">Overview</a></td><td><a href="http://www.erlang.org/"><img src="erlang.png" align="right" border="0" alt="erlang logo"></a></td></tr></table></div>
  203. <p><i>Generated by EDoc, Sep 20 2009, 09:15:40.</i></p>
  204. </body>
  205. </html>