It can sometimes be useful to connect a process or a sub-system,
which has not been designed with the supervision principles in mind,
to a supervisor tree. This can be accomplished by using an
instance of the supervisor_bridge behaviour. A supervisor bridge
is a process which sits in between a supervisor and the
sub-system. It behaves like a real supervisor to its own supervisor,
but has a different interface than a real supervisor to the
sub-system. Note, however, that it does not allow the use of the
sophisticated code changing mechanisms to the sub-system.
An instance of the supervisor_bridge behaviour can be debugged
with the module sys.
In the following, Module is the name of the callback
module that implements the supervisor bridge behaviour.
start_link(Module,StartArgs) -> {ok, Pid} | ignore |
{error, Reason}
start_link(Name,Module,StartArgs) -> {ok, Pid} | ignore |
{error, Reason}
Name = {local, atom()} | {global, atom()}Module = atom()StartArgs = term()Starts a new supervisor bridge process synchronously.
The function Module:init(StartArgs) is called (see below).
If the supervisor bridge is started with Name,
the name is registered locally or globally.
The following functions should
be exported from a supervisor_bridge callback module.
Module:init(StartArgs) -> {ok, Pid, State} | ignore |
{error, Reason}
StartArgs = term()State = term()This function starts the sub-system and
returns the Pid of the main process in the sub-system, and a
State. The State can be any term and it is sent
to the Module:terminate/2 function (see below).
Module:terminate(Reason, State) -> void()
Reason = term()State = term()This function terminates the sub-system. The return value is ignored.
The supervisor_bridge behaviour generates the same system events
as the gen_server behaviour. System events are handled by the
sys module.
gen_server(3), supervisor(3), sys(3)