In gen_event, what functional diff does it makes for gen_event:notify & gen_event:call

Ulf Wiger etxuwig@REDACTED
Thu Feb 20 12:12:42 CET 2003


On Thu, 20 Feb 2003, Suresh S wrote:

>Hi,
>
>I have few doubts in gen_event, like
>
>What is the need for gen_event:call when we have
>gen_event:notify ?

gen_event:call() can be used pretty much like a
gen_server:call, when e.g. the owner of an event handler
wants to query or configure the handler. The call is
addressed to a specific handler in a specific gen_event
process. The other handlers are unaffected.

>what for gen_event:call when purpose is solved with
>gen_event:notify ?

Notify is different. It sends a message to the gen_event
process, and all installed handlers are called in order to
get a chance to handle it.

>how do we relate handlers and events ? i mean when a
>request is made or an event is notified how does the
>handler knows to handle particular event or call, both in
>case of gen_even:notify and gen_event:call.

See above for the difference between event and call.
If a handler is only interested in one or a few specific
events, it uses pattern matching:

handle_event({my_important_event, Event}, S) ->
   ...
   {ok, S'};
handle_event(_, S) ->
   {ok, S}.

The catch-all clause is important. Each handler must be
prepared for any message coming in to handle_event/2. This
is similar to handle_info/2 in a gen_server callback. It is
perfectly OK to ignore unknown messages.

/Uffe

-- 
Ulf Wiger, Senior Specialist,
   / / /   Architecture & Design of Carrier-Class Software
  / / /    Strategic Product & System Management
 / / /     Ericsson AB, Connectivity and Control Nodes




More information about the erlang-questions mailing list