[rabbitmq-discuss] Calls to management functions

Matthias Radestock matthias at lshift.net
Mon Jul 9 16:11:38 BST 2007


"Ben Hood" <0x6e6562 at gmail.com> writes:

> I looked into this by trying to parameterize the server with a
> callback module. However, I was starting the server in a supervision
> tree and the child specification calls apply/3 on the server under the
> hood which doesn't allow to parameterize the server. I couldn't see
> how to do by passing a function to the init() method, because I would
> need to register this in the handle_call() callback. I suppose you
> could save it to a database in the init method and then query it in
> the handle_call() method, but this seems a bit complicated to me.

This is really an Erlang question, so perhaps we should move over to
erlang-questions. ...

Anyway, say you want to delegate all handle_call() invocations of a
particular gen_server instance to a particular function. You'd make that
function part of the gen_server's state, initialised as part of init(),
and call it in handle_call(). If the process is part of a supervision
tree then the function needs to be passed in as part of the child_spec.

>> 2) create a custom behaviour
>
> Looked into that as well. However, extending the gen_server behaviour
> only adds extra callbacks that you would have implement in each
> implementation in addition to the standard callback, hence not saving
> you any code.

Right. The difficulty here is that we don't just want to implement some
custom behaviour, but want our implementation to be compatible with
the gen_server behaviour. IIRC this issue has been brought up before on
erlang-questions, so it's probably worth checking the archives.


Matthias.




More information about the rabbitmq-discuss mailing list