erps v0.7.0 Erps.Daemon View Source

A Process which sits on a TCP port and listens to inbound connections, handing them off to Erps.Server modules when an connection arrives.

The Daemon also manages putting those server processes into supervision trees, usually a DynamicSupervisor. Each server will be seeded with a common initial data and common options, though they may incur specialization once handed off to the Erps.Server module's start_link/2 and init/1 functions.

Example:

this invocation will initialize the Erps.Server MyServer with an empty map, supervised by the DynamicSupervisor named ServerSupervisor. See start_link/2 for more supervision options.

Erps.Daemon.start_link(MyServer, %{}, port: <port_number>, server_supervisor: ServerSupervisor)

Typically, you will also want to supervise Erps.Daemon itself, in which case you should use the following form, passing it into a static Supervisor:

children = [{Erps.Daemon, {MyServer, %{}, port: <port_number>, server_supervisor: ServerSupervisor}}]

You may override the standard child_spec parameters [:id, :restart, :shutdown] in the options list of the tuple.

Link to this section Summary

Functions

Returns a specification to start this module under a supervisor.

retrieve the TCP port that the erps daemon is bound to.

launches a Erps Daemon, linked to the calling process

Link to this section Types

Link to this section Functions

Returns a specification to start this module under a supervisor.

See Supervisor.

retrieve the TCP port that the erps daemon is bound to.

Useful for tests - when we want to assign it a port of 0 so that it gets "any free port" of the system.

Link to this function

start(server_module, data, options \\ []) View Source
start(module(), term(), keyword()) :: GenServer.on_start()

see start_link/2

Link to this function

start_link(server_module, data, options! \\ []) View Source
start_link(module(), term(), keyword()) :: GenServer.on_start()

launches a Erps Daemon, linked to the calling process

You can pass these general options which will propagate to the Erps.Servers. You may also want to specify the supervision tree using the :server_supervisor option as follows:

  • server_supervisor: pid_or_name assumes the supervisor is DynamicSupervisor (or equivalent) and calls DynamicSupervisor.start_child/2
  • server_supervisor: {module, name} allows you to use a generic module for supervision and calls module.start_child/2 with the server module and the arity-2 parameters for the server_module.start_link/2 function.
  • forward_callers: true causes the daemon and its spawned servers to adopt the universe of the caller. see Multiverses for details

other options you may want to override:

  • :port, sets the TCP port the daemon will listen on. Defaults to 0, which means that a random port will be selected, and must be retrieved using port/1
  • :transport, useful for mocking with TCP instead of TLS in tests
  • :tls_opts, useful for specifiying TLS parameters shared by all server processes