Questions about gen_server
Enrique Marcote Peña
mpquique@REDACTED
Fri Feb 14 15:09:08 CET 2003
Hello,
I've been doing my first module using gen_server and after some moments
of euphoria, I'm just about to question everything I've done.
I decided to implement a receipt dispenser using the gen_server
behavior. , Even though my sample is just a very simple module that
exports 4 functions, I'd like you to think about it as a driver that
interacts with a real dispenser (using whatever protocol over TCP/IP):
start_link() -> {ok, Pid}
stamp(Request) -> {ok, Receipt} | {error, Reason}
price(Request) -> {ok, float()} | {error, Reason}
stop() -> ok
Requests are solved:
dispenser:start_link().
...later on ...
dispenser:stamp(Request).
...done...
dispenser:stop().
Well, once finished with the implementation I'm not sure if it makes
sense to use gen_server in such a case. Does it make sense to use this
behavior if no State is carried on by the server? I mean, what about
servers using mnesia to store the "state", is it correct to conceive
them as gen_servers? I'm asking so course I realize that, even the
dispenser above mentioned is (in concept) a server, it could also be
implemented as a simple module exporting the functions stamp/1 and
price/1 (without using the gen_server). To use this module a direct
call to dispenser:stamp/1 or dispenser:price/1 could be done when
needed. What are the advantages of using the gen_server behavior? When
should be used?
Is it reasonable to implement a server that expands a worker for every
incoming request? Up to a limited number of course (some kind of pool
of workers). Would such a pool fit into a gen_server? How? Are these
workers gen_servers also? Do I see gen_servers everywhere?
Thanks in advance.
Best regards,
Quique
More information about the erlang-questions
mailing list