What is the naming convention for a simple-one-for-one supervisor whose child is a supervisor?
A simple example could be that I have a tcp_session process that is supervised by a tcp_session_sup process. The tcp_session_sup has additional children for assisting with the TCP session. I am going to have multiple TCP sessions that are going to be created dynamically. So, I’d like to create a simple_one_for_one supervisor to spin off TCP sessions. What should I name this supervisor, tcp_session_sup_sup??
In your particular example you could name the top supervisor tcp_sessions_sup since it supervises multiple sessions as opposed to a single session. It follows that the supervisor for a single session could be named tcp_session_sup as it already is.
When I have similar problems this is usually a symptom of the fact that I have not thoroughly thought out the way in which to decompose the particular problem I’m trying to solve.
Yes, this is about naming a process. I appreciate the insights. I like the idea of tcp_sessions_sup, and will move down that path. It is also good to know that it won’t be viewed as crazy if a module ends up being named *_sup_sup, but it makes sense to view that as possible a gap in my solution.
You have to be careful if you name a process after the module running as it restricts to having only ONE instance of that process as the name is unique. I know it is common to do it but avoid it as a rule.
In this case who as started the tcp_sessions_sup_sup process?
There are two problems with naming processes.
One has been noted: only one process can have a
given name (that’s what it means to be a name).
Another is that naming destroys encapsulation.
If a process is not named, it can only receive
messages from a process to which its PID has been
communicated in a controlled way. If a process
is named, any process can send anything it likes
to its named victim.
One of the projects I did for SERC in Melbourne
was to come up with a scheme for module-local
process names, the -pidname declaration. The idea
was to have something intermediate between no-names
and node-global names. At the time, almost all uses
of process names in the OTP sources could have been
Obviously node-global names have their uses, just be
careful with them.