[erlang-questions] initializing process

paweł kamiński kamiseq@REDACTED
Fri Sep 18 18:16:58 CEST 2009


2009/9/18 Jayson Vantuyl <kagato@REDACTED>

> What exactly are you trying to do?


exactly this is a application server that is getting requests from its
clients via http and then it is doing some computation. but the key feature
of the server is talking to other peer in local network and gathering
information about other devices in the area, process that information and
send it to clients.

the problem is that the other computer is a third-party hardware and
software black-box that I connect via tcp or rss and can switches off
itself. my server must be 100% sure that the other side is alive before
starting everything up. if my server is not responding clients will notify
local stuff that something is going on and someone will go check. the server
may loose connection with black-box and again will disconnect client. it is
maybe weird but help troubleshooting and I know that my server is ok but it
is THEIR :) fault.


> It's really easy to create complex race conditions and strange startup
> ordering issues doing something like this.
>
> that what I was worried about


> If you can have the node signal you (much less work).  Just start out in an
> "uninitialized" state set a short timeout and just go idle.  ..
>
If you must ping the node from the waiting side, you can simulate a delaying
> loop with a gen_server (and a gen_fsm) by using the timeout feature.  Just
> send the ping and set a timeout.  Have the timeout function send the ping
> again and set a timeout again.  Eventually, you'll get the response and can
> go about your merry way.
>

yep that is the case I need to force the communication.
ok lets say my device controller is gen_fsm I initialize it and set
running_disconnected fsm state, so now my fsm is waiting for some event. who
will ping the other side? I can't do it in init/1 as it may lead to race
conditions as you said earlier.

If I loose connection device controller should switch back to
running_disconnected fsm state and fold all processes that relay on
connection and start pinging again.

gleb's advice was to do everything in init using PeerPid!{ping} and receive,
it is some way. other is to skip behaviours and implement device controller
as a simple process that will do its job but both are less elegant.


> I think the "correct" way (i.e. overkill in the style of Ericsson) is to do
> this at an application level.  You can set up a distributed Erlang
> application to start in "phases".  Depending on your deployment, that might
> be the ultimate answer, since it also provides hooks for takeover /
> failover, which may be necessary depending on your application.
>
>
what do you mean by application level and "You can set up a distributed
Erlang application to start in "phases"" how you imagine the architecture
for that?
thanks for replay

pozdrawiam
Paweł Kamiński

kamiseq@REDACTED
pkaminski.prv@REDACTED
______________________


More information about the erlang-questions mailing list