Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I don't have a precise drawing to explain it, but I have <a href="http://learnyousomeerlang.com/what-is-otp#the-common-process-abstracted" rel="noreferrer">this chapter</a> and the one after showing how to build gen_server starting with the abstraction principles behind it.</p> <p>To help with the individual components:</p> <h3>behaviour implementation</h3> <p>The behaviour itself is a bit like what is shown in the chapter I linked before. It's a module with a bunch of functions doing all the generic stuff for you: receiving messages, defining functions and hidden protocols to communicate, etc. Advanced OTP stuff contains special kinds of messages used to do software upgrades and also special code for tracing options.</p> <h3>behaviour container</h3> <p>I'm not sure what this is supposed to be. Maybe just the module with the name of the behaviour?</p> <h3>behaviour interface</h3> <p>In the same module your behaviour implementation is, you have to define a <code>behaviour_info/1</code> function. That function will let the Erlang compiler know that some callbacks are expected from any module that has <code>-behaviour(SomeModuleName)</code> in it. The <code>SomeModuleName</code> is equivalent to a <code>SomeModuleName.erl</code> (and <code>.beam</code>) file that contains the implementation and the behaviour_info function.</p> <h3>callback module</h3> <p>The module that will contain all the specific code, handling all the custom stuff.</p> <h3>callback functions</h3> <p>Everything that isn't generic gets to be delegated to the callback module in the form of <code>YourModule:SomeCall(Args)</code>. These are provided by your module, the one that has the <code>-behaviour(gen_server).</code> line in it.</p> <h3>API functions</h3> <p>The callback module has two interfaces, if you want: the one for the <code>gen_server</code> behaviour (init/0, handle_call/3, handle_info/2, handle_cast/2, terminate/2, code_change/3), and the one for the user (start the server, send some information, ask for some information back).</p> <p>I could try to describe it that way</p> <pre><code>--------------------------------------------------------------------- | some process | server process | ------------------------+-------------------------------------------- [client] | [callback] : [behaviour] | : callback:start &gt;-------|---------------------:--&gt; starting the process | : V | : | | init() &lt;-----:-----------` | | : | `-----------:------&gt; initial state {ok, Pid} &lt;----------|---------------------:----------,/ | : callback:store &gt;------|---------------------:--&gt; handles message (calls the process) | (formats msg) : V | : | | handle_call() &lt;--:-----------` | | : | `----------:--&gt; updates state, sends reply | : V | : | gets result &lt;--------|---------------------:--------` | : </code></pre> <p>All the generic parts are on the right of the server process, within the behaviour, and all the specific parts are on the left (callback). The client uses the callback module's API/interface to contact the server process and have effects on it.</p> <p>You have to see the behaviour as some kind of very generic code segment that sometimes gives up its execution flow (for more precise parts, like receiving and sending messages) to the specific code (how to react to these messages).</p> <p>Hopefully this helps.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload