For one of my “learning projects” I have a set of erlang processes (different modules implementing gen_server). Each of this processes spawns and supervises a child process which consists in a single module not implementing otp behaviour.
therefore I have the following situation:
gen_server_a <-> module_a
gen_server_b <-> module_b
gen_server_c <-> module_c
Each child process does the same set of things:
- register itself with the name of the module (e.g. module_a)
- does some operations based on configuration parameters passed by parent during spawning
- receives commands from parent using its registered name
Now, I know that this is far from perfect. I would like to abstract the architecture in order to have still 3 gen_servers, but only one beam file for the child part so that I could achieve something like:
gen_server_a <-> module_generic (registered as module_a)
gen_server_b <-> module_generic (registered as module_b)
gen_server_c <-> module_generic (registered as module_c)
how can I achieve something like this? Just passing during the spawning an atom to be used for registering the process? Is there any other option?
In
module_genericbuild an ownstart_link/1which spawns the process function and then registers the Pid: