<?xml version="1.0" encoding="latin1" ?>
<!DOCTYPE erlref SYSTEM "erlref.dtd">

<erlref>
  <header>
    <copyright>
      <year>1996</year>
      <year>2007</year>
      <holder>Ericsson AB, All Rights Reserved</holder>
    </copyright>
    <legalnotice>
  The contents of this file are subject to the Erlang Public License,
  Version 1.1, (the "License"); you may not use this file except in
  compliance with the License. You should have received a copy of the
  Erlang Public License along with this software. If not, it can be
  retrieved online at http://www.erlang.org/.

  Software distributed under the License is distributed on an "AS IS"
  basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
  the License for the specific language governing rights and limitations
  under the License.

  The Initial Developer of the Original Code is Ericsson AB.
    </legalnotice>

    <title>pg</title>
    <prepared></prepared>
    <docno></docno>
    <date></date>
    <rev></rev>
  </header>
  <module>pg</module>
  <modulesummary>Distributed, Named Process Groups</modulesummary>
  <description>
    <p>This (experimental) module implements process groups. A process
      group is a group of processes that can be accessed by a common
      name. For example, a group named <c>foobar</c> can include a set
      of processes as members of this group and they can be located on
      different nodes.</p>
    <p>When messages are sent to the named group, all members of
      the group receive the message. The messages are serialized. If
      the process <c>P1</c> sends the message <c>M1</c> to the group,
      and process <c>P2</c> simultaneously sends message <c>M2</c>, then
      all members of the group receive the two messages in the same
      order. If members of a group terminate, they are automatically 
      removed from the group.</p>
    <p>This module is not complete. The module is inspired by the ISIS
      system and the causal order protocol of the ISIS system should 
      also be implemented. At the moment, all messages are serialized
      by sending them through a group master process.</p>
  </description>
  <funcs>
    <func>
      <name>create(PgName) -> ok | {error, Reason}</name>
      <fsummary>Create an empty group</fsummary>
      <type>
        <v>PgName = term()</v>
        <v>Reason = already_created | term()</v>
      </type>
      <desc>
        <p>Creates an empty group named <c>PgName</c> on the current
          node.</p>
      </desc>
    </func>
    <func>
      <name>create(PgName, Node) -> ok | {error, Reason}</name>
      <fsummary>Create an empty group on another node</fsummary>
      <type>
        <v>PgName = term()</v>
        <v>Node = node()</v>
        <v>Reason = already_created | term()</v>
      </type>
      <desc>
        <p>Creates an empty group named <c>PgName</c> on the node
          <c>Node</c>.</p>
      </desc>
    </func>
    <func>
      <name>join(PgName, Pid) -> Members</name>
      <fsummary>Join a pid to a process group</fsummary>
      <type>
        <v>PgName = term()</v>
        <v>Pid = pid()</v>
        <v>Members = [pid()]</v>
      </type>
      <desc>
        <p>Joins the pid <c>Pid</c> to the process group <c>PgName</c>.
          Returns a list of all old members of the group.</p>
      </desc>
    </func>
    <func>
      <name>send(PgName, Msg) -> void()</name>
      <fsummary>Send a message to all members of a process group</fsummary>
      <type>
        <v>PgName = Msg = term()</v>
      </type>
      <desc>
        <p>Sends the tuple <c>{pg_message, From, PgName, Msg}</c> to
          all members of the process group <c>PgName</c>.</p>
        <p>Failure: <c>{badarg, {PgName, Msg}}</c> if <c>PgName</c> is
          not a process group (a globally registered name).</p>
      </desc>
    </func>
    <func>
      <name>esend(PgName, Msg) -> void()</name>
      <fsummary>Send a message to all members of a process group, except ourselves</fsummary>
      <type>
        <v>PgName = Msg = term()</v>
      </type>
      <desc>
        <p>Sends the tuple <c>{pg_message, From, PgName, Msg}</c> to
          all members of the process group <c>PgName</c>, except
          ourselves.</p>
        <p>Failure: <c>{badarg, {PgName, Msg}}</c> if <c>PgName</c> is
          not a process group (a globally registered name).</p>
      </desc>
    </func>
    <func>
      <name>members(PgName) -> Members</name>
      <fsummary>Return a list of all members of a process group</fsummary>
      <type>
        <v>PgName = term()</v>
        <v>Members = [pid()]</v>
      </type>
      <desc>
        <p>Returns a list of all members of the process group
          <c>PgName</c>.</p>
      </desc>
    </func>
  </funcs>
</erlref>

