[erlang-questions] Using gen_server or writing a new behavior

Ciprian Dorin, Craciun ciprian.craciun@REDACTED
Fri Jan 16 16:21:11 CET 2009


    Hello all!

    I have a somehow philosophycal question about OTP, mainly about
gen_server...

    I want to write my own HTTP framework, the main focus now being
the request handlers... So:
    * I created a request handler supervisor, which managed the
request handlers;
    * each connection handler after resolving the request handler,
delegates the request to it;

    Now my question is the following:
    * I could implement the request handlers as being normal
gen_server instances (first option);
    * or (second option) I could define a new behavior (let's call it
ws_handler), that defines handle_process callback (resembling somehow
handle_call), and thus create a new gen_server like process "class"...
(actually my handler is just a normal gen_server, that delegates the a
special message to this callback);

    The advantages of the second solution is that it simplifies the
handler development, but it adds (for now) unnecessary wrapping (as it
is a gen_server behind scenes). Also the disadvantage is that there is
no straight-forward way to create a new gen_server like behavior
without wrapping it inside a gen_server.

    So the question is which of the two options would be the preferred
one? Or what are your thoughts about this issue?

    Thanks all,
    Ciprian Craciun.



More information about the erlang-questions mailing list