Erlang/OTP Forums

Author Message

<  Open Telecom Platform (OTP)  ~  How to find a child process efficiently in a supervisor?

diyu01
Posted: Wed Aug 19, 2009 6:16 pm Reply with quote
Joined: 19 Aug 2009 Posts: 7
Hi, I am new to Erlang/OTP and am trying to implement a process that maintains a (dynamic) list of child processes in a supervisor way, and is able to get messages like {ChildName, RealMessage} from outside, and find a child process based on the child name and then pass "RealMessage" to that child process.

The child processes are all similar, but the number is dynamic and might be quite large, so I am planning to use simple_one_for_one strategy in the process. But in that case, how should I register the name->child mapping in the supervisor? I do not see anything like an "internal state" in the supervisor behaviour, and if I use supervisor:which_children and loop through the returned list, it would not only be potentially too slow but also still cannot provide the name->child mapping, since for simple_one_for_one supervisors there is no "ID" for newly added child.

So how should I implement this? Thanks!
View user's profile Send private message
uwiger
Posted: Wed Aug 19, 2009 8:03 pm Reply with quote
User Joined: 03 Jul 2006 Posts: 604 Location: Sweden
diyu01 wrote:
Hi, I am new to Erlang/OTP and am trying to implement a process that maintains a (dynamic) list of child processes in a supervisor way, and is able to get messages like {ChildName, RealMessage} from outside, and find a child process based on the child name and then pass "RealMessage" to that child process.


The rule regarding supervisors is that they do one thing, and one thing only: supervise processes. The only user code that's allowed to run inside a supervisor is either in the init phase or the start function of the child process. The rest, you don't get to touch.

If you want to dispatch messages to processes, you can use something like proc_reg in jungerl, or roll your own: a process that keeps a dictionary mapping child names to pids. Don't mix it up with supervision, if you can help it.

BR,
Ulf W
View user's profile Send private message Visit poster's website
wuji
Posted: Sat Aug 11, 2012 1:46 am Reply with quote
User Joined: 10 Aug 2012 Posts: 654
tate with roughly the same population as the city of of cheap polo shirts of San Antonio, has been a momentum-setter in presidential elections
nearly a century.While Iowa has held its caucus before New New [h4]red bottom shoes[/h4] New Hampshire's primary every year since 1972, Iowa's caucus results
non-binding and delegates are not officially awarded until June, making making cheap designer *beep* making New Hampshire the first state to award delegates in
presidential nominating cycle.Since its first-in-the-nation status became official more than than cheap Christian Louboutin than 30 years ago, only two Republican presidential candidates have
in New Hampshire and gone on to win the nomination.With nomination.With Christian Louboutin Outlet nomination.With Mitt Romney taking a narrow win in Iowa and
a
View user's profile Send private message

Display posts from previous:  

All times are GMT
Page 1 of 1
This forum is locked: you cannot post, reply to, or edit topics.

Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum