In gen_event, what functional diff does it makes for gen_event:notify & gen_event:call
Ulf Wiger
etxuwig@REDACTED
Fri Feb 21 10:55:13 CET 2003
On Fri, 21 Feb 2003, Suresh S wrote:
>Hi Ulf,
>
>> The {Module,Id} construct is for the case that you
>> have lots
>> of instances of similar handlers, and it's not
>> practical, or
>> even desired, to implement a module for each
>> instance. Id
>> can be anything that helps you tell the different
>> handlers
>> apart in your application.
>
>I have one question left,
>If i have 'N' events in a callback module to be
>handled, i no need to have 'N' handlers ,
>
>i can manage all the events with one handler,
>if it is the case,
Yes, just like you can handle several different calls with
a gen_server, you can handle several different events in one
callback module. You simply do pattern matching in the
handle_event/2 function. Again, to exemplify with the EVA
application's eva_snmp_adaptation.erl:
handle_event({send_event, Event}, S) ->
...;
handle_event({send_alarm, Alarm}, S) ->
...;
handle_event({unregister_event, Name}, S) ->
...;
handle_event({unregister_alarm, Name}, S) ->
...;
handle_event(_, S) ->
{ok, S}.
In this case, the same module handles 4 specific events, and
ignores all other events.
Multiple handlers would be used if you want to do several
unrelated things on the same event.
/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