[erlang-questions] Pass Name to Dynamic Supervisors
tom kelly
ttom.kelly@REDACTED
Thu Sep 8 10:56:14 CEST 2011
Hi Chris,
We do something like this in our application.
First, in our "static" supervision tree we start a dynamic supervisor:
init(Args) ->
{ok, {
{one_for_one, 5, 5},
[
{dynamic_supervisor_id,
{dynamic_supervisor, start_link, [Args]},
permanent,
infinity,
supervisor,
[dynamic_supervisor]},
Where the dynamic_supervisor module has the functions:
start_link(Args) ->
supervisor:start_link({local,?MODULE}, ?MODULE, [Args]).
init(_Args) ->
{ok, {
{one_for_one, 5, 5},
[]
}}.
Then in our code we can dynamically start supervised processes with
registered names, ProcName:
supervisor:start_child(dynamic_supervisor,
{ProcName,
{gen_server, start_link,
[{local, ProcName}, ?MODULE, [StartArgs], []]},
permanent,
10000,
worker,
[?MODULE]
})
And shut them down with:
supervisor:terminate_child(dynamic_supervisor,PName),
supervisor:delete_child(dynamic_supervisor,PName),
This is just a few clippings from our code base here with the names made
more generic, so there might be a syntax error or two but I think it helps
do what you want.
//Tom.
On Thu, Sep 8, 2011 at 3:09 AM, Christopher Wilson <wilsoncj1@REDACTED>wrote:
> Is there a way to pass a name/ID into the call to supervisor:start_child,
> more specifically to init()? I'd like to specify the name of the worker or
> supervisor such that when I ran supervisor:which_children I could identify
> what's what.
>
> Also, I've tried [unsuccessfully] to dynamically create a child spec and
> add pass that in. Are there any decent examples out there on how to do this
> outside of the man pages?
>
> Thank you.
>
> -Chris
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20110908/c083036e/attachment.htm>
More information about the erlang-questions
mailing list