[ejabberd] Communicate with other modules

Stefan Strigler steve at zeank.in-berlin.de
Mon Jan 30 13:11:11 MSK 2012

I'm not sure whether gen_server is the right choice here. Typically your scenario is what's called keeping guard of a shared resource (the link to the DB). You'd naively implement this by spawning a process which waits for messages of the other modules to fulfill queries on their behalf and synchronously or asynchronously send back replies to those other "modules" (which are running processes itself in fact). This whole thing can be formalized by using the gen_fsm pattern which is the general approach ejabberd uses for all of its architecture. By using a supervisor for this FSM you can make sure to keep such a process up and running in case of failures (which would otherwise be fatal to the overall system).

Greets, Steve

Am 30.01.2012 um 09:49 schrieb Michael Weibel <michael.weibel+xmpp at gmail.com>:

> Hi all,
> I'm implementing multiple modules which should use the same connection to a mongodb (I'm using the official mongodb-erlang driver). 
> To achieve this, I'd like to create a module which just opens the connection to the db and other modules could call this generic module.
> How can I do this? 
> In the generic module I create a gen_server which opens the db connection and now I tried from the other modules to call it with gen_server:cast(generic_module, {data})
> But this doesn't work.
> Do I need to create an application for that?
> - Michael
> _______________________________________________
> ejabberd mailing list
> ejabberd at jabber.ru
> http://lists.jabber.ru/mailman/listinfo/ejabberd

More information about the ejabberd mailing list