OTP behaviours

The gen_server, supervisor and application behaviours are the part of OTP that most Erlang code is made of. This part writes each one by hand and reads the callbacks the runtime calls, then adds the behaviours a system needs beyond them: gen_statem for a protocol with phases, gen_event for a signal with many listeners, and the nested trees, releases and design rules that turn a folder of modules into a service.

The code is standard library only: the behaviours arrive with OTP, and rebar3 builds the release without a package from the network. Each lesson keeps the state of the example small enough to hold in the head while the callbacks run.

9.1 GenServer init, handle_call, handle_cast and handle_info, and the state the loop keeps Open 9.2 Supervisors a child spec, the restart strategy, and the tree that restarts a part Open 9.3 OTP applications the app resource, the application module, and the start and stop of a system Open 9.4 gen_statem a state machine, the state in the callback, a timeout that changes the state, and the event nobody handles Open 9.5 gen_event an event manager, a handler, adding and deleting a handler, and the handler that crashes and is removed Open 9.6 Supervision trees a supervisor of supervisors, the cost of a nested restart, the shutdown order, and the shape of a tree Open 9.7 Releases rebar3 release, the folder it assembles, the manifest, the sys.config, and how a release is started and upgraded Open 9.8 OTP design principles a behaviour as a callback contract, the compiler check, the missing callback, and the checklist Open

Lessons