[erlang-questions] question: gen_event problems with add_sup_handler() and swap_sup_handler()

Serge Aleynikov saleyn@REDACTED
Thu Jan 17 03:40:50 CET 2008


Note that gen_event:swap_sup_handler/0 is called from 
my_alarm_handler:start/1 function *in the context of the calling 
process* (implemented in the handler_guard module).  The handler_guard 
is attached to the supervisor, and every time my_alarm_handler would 
crash, handler_guard would receive the {gen_event_EXIT,Handler,Reason} 
message sent by the event manager and exit, causing the supervisor to 
restart the handler_guard that would consequently reinstall 
my_alarm_handler.

Serge

Ahmed Ali wrote:
> Hi Ulf,
> 
> I had this understanding when read the article, but that was not clear
> at all. If you look at the code in the article, you'll see that
> gen_event:swap_sup_handler() was called in the my_alarm_handler module
> not from the guard process. That was confusing for me at least.
> 
> I'll test it now.
> 
> Best regards,
> Ahmed
> 
> On Jan 16, 2008 1:33 AM, Ulf Wiger <ulf@REDACTED> wrote:
>> That tutorial pretty much explains it, I think, but perhaps
>> it's a bit terse on some points.
>>
>> The whole point is that when the handler crashes,
>> the gen_event process sends a message to the
>> process that called add_sup_handler() in the first
>> place. The supervising process /could/ simply
>> reinstall the handler, but it would then have to
>> be aware of recurring crashes. Since there is already
>> a library that does so, it's better to simply let the
>> supervising process die - it is supervised in its turn,
>> and its supervisor will restart it. When this happens,
>> the handler will be reinstalled.
>>
>> BR,
>> Ulf W
>>
>> 2008/1/15, Ahmed Ali <ahmed.nawras@REDACTED>:
>>
>>> Hi,
>>>
>>> I've been trying for sometime to find a way to supervise
>>> event_handlers in gen_event behaviour with no luck. I found the
>>> following article and tried the code in it but it does not appear to
>>> be right http://www.trapexit.org/Gen_event_behavior_demystified.
>>>
>>> Can anyone please explain how add_sup_handler and swap_sup_handler
>>> work and how I could get my event_handler to get restarted in case of
>>> a crash?
>>>
>>> Best regards,
>>> Ahmed
>>> _______________________________________________
>>> erlang-questions mailing list
>>> erlang-questions@REDACTED
>>> http://www.erlang.org/mailman/listinfo/erlang-questions
>>>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://www.erlang.org/mailman/listinfo/erlang-questions
> 




More information about the erlang-questions mailing list