[erlang-questions] beginner: passing messages between supervisor trees
Tue Mar 11 22:29:11 CET 2008
On 11/03/2008, Pinku Surana <suranap@REDACTED> wrote:
> I'm still new to the idea of supervisors in Erlang. Assume I have a client C
> managed by supervisor MC, and server S managed by supervisor MS. When C
> sends a message to S, does the message get routed through MC and MS first?
> Or do C and S communicate directly?
No - C and S communicate directly.
> If so, where in the code are they connected together?
First thing to understand is that a process can use code from many
modules. There is no one-to-one mapping from a process to a module. In
the code which implements the functionality of C, you send a message
to S as follows.
S ! message_to_send
> If C sends a message to S and S fails, will C's message be saved somewhere
> so it can try again after restarting S?
No - any pending messages in the mailbox of S are lost if S exits
before processing them..
> Is this done automatically, or manually by one of the supervisors?
The supervisor's function is to keep a process alive according to its
specification. It is not involved in the message passing. If you want
guaranteed message delivery semantics then you have to implement it at
an application level i.e server S acknowledged every message it
receives to C.
> If S fails repeatedly, then I want to replace it with S2 (a simpler task).
When you create a supervisor specification, you specify how the
process should be started. You have to put such logic in that part of
> How can C's messages be routed to S2 transparently? I don't want C to be
> aware of the failures.
Make sure that S2 registers itself with a name which is the same name
you used for S.
More information about the erlang-questions