This behavior module provides the server of a client-server
relation. A generic server process (
A
gen_server module Callback module ----------------- --------------- gen_server:start gen_server:start_monitor gen_server:start_link -----> Module:init/1 gen_server:stop -----> Module:terminate/2 gen_server:call gen_server:send_request gen_server:multi_call -----> Module:handle_call/3 gen_server:cast gen_server:abcast -----> Module:handle_cast/2 - -----> Module:handle_info/2 - -----> Module:handle_continue/2 - -----> Module:terminate/2 - -----> Module:code_change/3
If a callback function fails or returns a bad value, the
A
Notice that a
Unless otherwise stated, all functions in this module fail if
the specified
The
If the
If the
For some important information about distributed signals, see the
Name specification to use when starting a
Register the
Register the
Register the
Server specification to use when addressing
a
It can be:
The
The
The
The
The
Options that can be used when starting
a
How many milliseconds the
The
Using spawn option
See the type
Options that can be used when starting
a
Specifies that the
For every entry in
Return value from the
The
A process with the specified
Return value from the
Destination, given to the
A handle that associates a reply to the corresponding request.
An opaque request identifier. See
An opaque collection of request identifiers
(
Used to set a time limit on how long to wait for a response using
either
Timeout relative to current time in milliseconds.
Infinite timeout. That is, the operation will never time out.
An absolute
A map that describes the
New associations may be added to the status map without prior notice.
Sends an asynchronous request to the
For a description of the arguments, see
Makes a synchronous call to the
See also
Before OTP 24, if the caller uses (
Starting with OTP 24,
The return value
This call may exit the calling process
with an exit term on the form
The call was aborted after waiting
The
The
A call to
The server was stopped during the call
by its supervisor. See also
The server stopped during the call by returning
The server process exited during the call,
with reason
Sends an asynchronous request to the
See also
Check if
If
The return value
The function returns an error if the
Check if
The
Compared to
If
If
Makes an existing process a
This function is useful when a more complex
initialization procedure is needed
than the
This function fails if the calling process was not started by a
Makes a synchronous call to all
The function returns a tuple
When a reply
If one of the nodes cannot process monitors, for example,
C or Java nodes, and the
This problem does not exist if all nodes are Erlang nodes.
To prevent late answers (after the time-out) from polluting the message queue of the caller, a middleman process is used to do the calls. Late answers are then discarded when they arrive to a terminated process.
Receive a response corresponding to the request identifier
The return value
The function returns an error if the
The difference between
Receive a response corresponding to a request identifier saved
in
The
Compared to
If
The difference between
If
This function can be used by a
Saves
Returns a new empty request identifier collection. A request identifier collection can be utilized in order the handle multiple outstanding requests.
Request identifiers of requests made by
Returns the amount of request identifiers saved in
Returns a list of
Sends an asynchronous
The call
The
See the type
Sends an asynchronous
The same as calling
Creates a standalone
Other than that see
Creates a
The
Using the argument
See type
See type
Creates a standalone
Other than that see
If the start is not successful,
the caller will be blocked until the monitor's
Orders the generic server specified by
The function returns
If the process does not exist, the call exits
the calling process with reason
Wait for a response corresponding to the request identifier
The return value
The function returns an error if the
The difference between
Wait for a response corresponding to a request identifier saved
in
The
Compared to
If
The difference between
If
The following functions
are to be exported from a
This callback is optional, so callback modules need not export it.
If a release upgrade/downgrade with
This function is called by a
For an upgrade,
If successful, the function must return the updated internal state.
If the function returns
This callback is optional, so callback modules need not
export it. The
If this callback is exported but fails, to hide possibly sensitive
data, the default function will instead return the fact that
This function is called by a
The
This callback is used to limit the status of the process
returned by
The callback gets a map
Two possible use cases for this callback is to remove sensitive information from the state to prevent it from being printed in log files, or to compact large irrelevant status items that would only clutter the logs.
Example:
maps:map(
fun(state,State) ->
maps:remove(private_key, State);
(message,{password, _Pass}) ->
{password, removed};
(_,Value) ->
Value
end, Status).
]]>
This callback is deprecated, in new code use
This callback is optional, so callback modules need not
export it. The
This function is called by a
One of
The
This function is useful for changing the form and
appearance of the
The function is to return
One use for this function is to return compact alternative state representations to avoid that large state terms are printed in log files.
Whenever a
The return value
The
The
The
A reply to the client request has to be created by calling
If an integer
The process goes into hibernation waiting for
the next message to arrive (by calling
The process will execute the
The
Whenever a
For a description of the arguments and possible return values, see
This callback is optional, so callback modules need to
export it only if they return one of the tuples containing
This function is called by a
For a description of the other arguments and possible return values,
see
This callback is optional, so callback modules need not
export it. The
This function is called by a
For a description of the other arguments and possible return values,
see
Whenever a
The return value
Initialization was succesful and
See the corresponding return values from
Initialization failed. An exit signal with reason
is sent to linked processes and ports,
notably to the process starting the gen_server when
This callback is optional, so callback modules need not
export it. The
This function is called by a
If the
The
The shutdown strategy as defined in the child specification
of the supervisor is an integer time-out value, not
Even if the
Otherwise, the
Notice that for any other reason than
When the gen_server process exits, an exit signal with the same reason is sent to linked processes and ports.