Tutorials are abound for working with gen_servers that are named in an OTP application. However, I’ve been unable to find a good example of dynamically spawning servers that are not registered (not named). Can someone point to a good, simple example? Not ejabberd, for example, where there is a lot to confuse the core idea I’m trying to get at.
Thanks.
I have some dynamic spawning of workers in a supervision tree going on in http://github.com/noss/iserve. The iserve application has a master registered process that i call
iserve_masterit is supervised together with a simple one for one mode supervisor.The
iserve_masteris for asking iserve to start a http server. It can have multiple iservers, as long as they bind to unique addresses. The started servers construct a name for themself though, but that is to simplify debugging, it generates an atom using the port name.A server is is an “eternal” loop waiting for a
iserve_socketto call back about having accepted a connection. It starts the first one in init.The started socket is not under supervision because it is not able to restart without losing the http socket connection anyway. And I see it as a bit of a feature to not care. Fire and forget.
Its far from perfect, but an architecture that I somewhat like.