[erlang-questions] initializing process
Ladislav Lenart
lenartlad@REDACTED
Fri Sep 18 18:42:38 CEST 2009
Hello.
paweł kamiński wrote:
> 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.
You could send yourself a proper event message (that will trigger
the first ping) directly in the init function. Since you do this
in init, your message will be the first in the process's mailbox
(noone else can know the new pid).
HTH,
Ladislav Lenart
More information about the erlang-questions
mailing list