Erlang/OTP Forums

Author Message

<  Open Telecom Platform (OTP)  ~  OTP gen_event article

PAWilson
Posted: Sat Jan 20, 2007 2:43 am Reply with quote
Joined: 20 Jan 2007 Posts: 1
Hi,

I am just trying to get to grips with this intriguing language / platform. I've worked through the "Gen event behaviour demystified" article in the trapexit cookbook and have a question.

The handler_guard module is supposed to "upon receiving a {gen_event_EXIT,Handler,Reason} message from the event manager reinstall[] the event handler.

If this is the case, why does the handler_guard return {stop, ...}, which according to the manual calls Module:terminate/2 and shuts the module down.

I was expecting to see the handle_info reregister the handler somehow. Perhaps by calling init?

Not really sure *how* the code reregisters the event handler in the event manager process. Any clarification would be welcome.

Thank you
PAWilson
View user's profile Send private message
anders_n
Posted: Mon Jan 22, 2007 6:58 pm Reply with quote
User Joined: 28 Feb 2005 Posts: 155 Location: Saltillo, Mexico
Hi
The problem with gen_event is that Your event_handler is not
running as a separate process, instead it is just one of possibly
many callback modules registered in one event manager. So when
an event_handler fails it is just removed by the event manager.

The "trick" with the handler_guard is that it creates a separate
process that has only one purpose, to receive the
{gen_event_EXIT,Handler,Reason} message and terminate.

The reason here is that normally in Erlang You have a supervisor
that is responsible for supervising processes and restart them
if they crash. So the supervisor that started the handler_guard
will restart it for You.

/Anders
View user's profile Send private message Yahoo Messenger

Display posts from previous:  

All times are GMT
Page 1 of 1
This forum is locked: you cannot post, reply to, or edit topics.

Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum