[erlang-questions] Supervision trees and child startup ordering

Youngkin, Rich <>
Wed Apr 30 20:59:50 CEST 2014


Hi,

I'm using a supervision tree to manage multiple sets of gen_servers.  I've
got a situation where gen_servers in one supervision tree (e.g., Tree-B)
are clients of gen_servers in another supervision tree (e.g., Tree-A).  I'd
like Tree-A and all of it's children to complete their initialization
processing before starting any of the children in Tree-B.

                        Root Supervisor
                              |
              ----------------------------------
              |                                |
         Supervisor-A                     Supervisor-B
              |                                |
      -----------------                  -------------
      |       |       |                  |           |
      1       2       3                  4           5

So given this diagram, A and its children 1,2 and 3 start and complete
initialization before B and children 4 and 5 are started and complete
initialization. Furthermore, initialization in this case means that in
module:init/1 the child casts itself a message to complete initialization.
E.g.,

    ...

    init([]) ->
       gen_server:cast(?MODULE, complete_initialization),
       {ok, []}.

    ...

During Child 4's initialization it calls a function on Child 1 (which has
an init/1 implementation as described above).

In reading http://www.erlang.org/doc/man/supervisor.html#start_link-2 I
understand that Supervisor-A and all it's children will be started and
available before Supervisor-B and its children are started.  It's also my
understanding that when a child casts itself a message in its init/1
function that that message is guaranteed to be the first message in its
mailbox. Is my understanding of this correct and if so, is this a
reasonable way to do what I'm trying to accomplish?

Thanks,
Rich
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20140430/f9c8a2de/attachment.html>


More information about the erlang-questions mailing list