Vlad, thanks for your explanations but you missed the point :)<br>I was writing about other task. I understood quite clearly (I think) what you have proposed. <br>But I have also a task (for testing purposes) to write a worker emulator (apart from actual workers) or maybe a couple of emulators with a different logic. And those emulators should act like normal workers (which will be gen_server+API) so they must implement
<span class="q">handle_call({work,Data}) and I can not use some behavior to declare API common to both "normal" worker and worker emulator.<br>Maybe just Java coding at day time plays role here and I want to use interfaces every time. :)
<br><br>Regards,<br>Kirill.<br></span><br><div><span class="gmail_quote">On 6/12/07, <b class="gmail_sendername">Vlad Dumitrescu</b> <<a href="mailto:vladdu55@gmail.com">vladdu55@gmail.com</a>> wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Hi,<br><br>On 6/12/07, Kirill Zaborski <<a href="mailto:qrilka@gmail.com">qrilka@gmail.com</a>> wrote:<br>> Thanks, quite reasonable.<br>> But implementing an emulator for worker seems a bit ugly - I won't be able
<br>> use "normal" behavior so I will need gen_server with<br>> handle_call({work,Data}) (taken from your example).<br><br>Mmm, that's not an emulator or wrapper for the worker. The<br>gen_server:call has two arguments: a reference to the process running
<br>the code, and the message to be sent.<br><br>For your dispatcher, the reference is ?MODULE, presumably because the<br>process was registered with that name (dispatcher). Since the name is<br>known at compile time, the external API need not include it (
i.e<br>dispatcher:action needs only one argument)<br><br>For the workers, the reference will have to be the Pid of the<br>process. The API will have to reflect that, worker:action has two<br>arguments, the identity of the process and the message.
<br><br>Behind the scenes, the gen_server:call will take the {work, Data}<br>message, wrap it up in an internal strucure and send that. The<br>gen_server behaviour unpacks it and dispatches it to the appropriate<br>handler (handle_call, handle_cast, handle_info).
<br><br>I hope this is clearer.<br>Regards,<br>Vlad<br></blockquote></div><br>