1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170
|
.TH pg2 3 "kernel 2.12.3" "Ericsson AB" "ERLANG MODULE DEFINITION"
.SH MODULE
pg2 \- Distributed Named Process Groups
.SH DESCRIPTION
.LP
This module implements process groups\&. The groups in this module differ from the groups in the module \fIpg\fR in several ways\&. In \fIpg\fR, each message is sent to all members in the group\&. In this module, each message may be sent to one, some, or all members\&.
.LP
A group of processes can be accessed by a common name\&. For example, if there is a group named \fIfoobar\fR, there can be a set of processes (which can be located on different nodes) which are all members of the group \fIfoobar\fR\&. There is no special functions for sending a message to the group\&. Instead, client functions should be written with the functions \fIget_members/1\fR and \fIget_local_members/1\fR to find out which processes are members of the group\&. Then the message can be sent to one or more members of the group\&.
.LP
If a member terminates, it is automatically removed from the group\&.
.SS Warning:
.LP
This module is used by the \fIdisk_log\fR module for managing distributed disk logs\&. The disk log names are used as group names, which means that some action may need to be taken to avoid name clashes\&.
.SH EXPORTS
.LP
.B
create(Name) -> void()
.br
.RS
.TP
Types
Name = term()
.br
.RE
.RS
.LP
Creates a new, empty process group\&. The group is globally visible on all nodes\&. If the group exists, nothing happens\&.
.RE
.LP
.B
delete(Name) -> void()
.br
.RS
.TP
Types
Name = term()
.br
.RE
.RS
.LP
Deletes a process group\&.
.RE
.LP
.B
get_closest_pid(Name) -> Pid | {error, Reason}
.br
.RS
.TP
Types
Name = term()
.br
Pid = pid()
.br
Reason = {no_process, Name} | {no_such_group, Name}
.br
.RE
.RS
.LP
This is a useful dispatch function which can be used from client functions\&. It returns a process on the local node, if such a process exist\&. Otherwise, it chooses one randomly\&.
.RE
.LP
.B
get_members(Name) -> [Pid] | {error, Reason}
.br
.RS
.TP
Types
Name = term()
.br
Pid = pid()
.br
Reason = {no_such_group, Name}
.br
.RE
.RS
.LP
Returns all processes in the group \fIName\fR\&. This function should be used from within a client function that accesses the group\&. It is therefore optimized for speed\&.
.RE
.LP
.B
get_local_members(Name) -> [Pid] | {error, Reason}
.br
.RS
.TP
Types
Name = term()
.br
Pid = pid()
.br
Reason = {no_such_group, Name}
.br
.RE
.RS
.LP
Returns all processes running on the local node in the group \fIName\fR\&. This function should to be used from within a client function that accesses the group\&. It is therefore optimized for speed\&.
.RE
.LP
.B
join(Name, Pid) -> ok | {error, Reason}
.br
.RS
.TP
Types
Name = term()
.br
Pid = pid()
.br
Reason = {no_such_group, Name}
.br
.RE
.RS
.LP
Joins the process \fIPid\fR to the group \fIName\fR\&. A process can join a group several times; it must then leave the group the same number of times\&.
.RE
.LP
.B
leave(Name, Pid) -> ok | {error, Reason}
.br
.RS
.TP
Types
Name = term()
.br
Pid = pid()
.br
Reason = {no_such_group, Name}
.br
.RE
.RS
.LP
Makes the process \fIPid\fR leave the group \fIName\fR\&. If the process is not a member of the group, \fIok\fR is returned\&.
.RE
.LP
.B
which_groups() -> [Name]
.br
.RS
.TP
Types
Name = term()
.br
.RE
.RS
.LP
Returns a list of all known groups\&.
.RE
.LP
.B
start()
.br
.B
start_link() -> {ok, Pid} | {error, Reason}
.br
.RS
.TP
Types
Pid = pid()
.br
Reason = term()
.br
.RE
.RS
.LP
Starts the pg2 server\&. Normally, the server does not need to be started explicitly, as it is started dynamically if it is needed\&. This is useful during development, but in a target system the server should be started explicitly\&. Use configuration parameters for \fIkernel\fR for this\&.
.RE
.SH SEE ALSO
.LP
kernel(6), pg(3)
|