About the Handler in gen_event

Ulf Wiger etxuwig@REDACTED
Mon Feb 24 14:25:35 CET 2003


Suresh,

I will help you a little bit with the debugging, but I will
leave some things for you to sort out. ;-)

(Actually, Sean already pointed out the errors...)

First, I compiled your module, and ran the start_link()
function.

4> test_gen_event:start_link().

 add_handler success ok

(The printout above really only says that the init function
was called. The printout lacked a newline, so the 'ok' at
the end is the return value from the test() function. You
have no real confirmation that things went well.)

5> regs().

** Registered procs on node nonode@REDACTED **
Name                  Pid          Initial Call
Reds Msgs
alarm_handler         <0.33.0>  {gen_event,init_it,6} ...
application_controlle <0.5.0>   {application_controller,i...
code_server           <0.17.0>  {code_server,init,1} ...
erl_prim_loader       <0.2.0>   {erlang,apply,2} ...
error_logger          <0.4.0>   {gen_event,init_it,6} ...
event_mgr             <0.48.0>  {gen_event,init_it,6} ...
^^^^^^^^^  (that is, your process did indeed start)
file_server           <0.16.0>  {erlang,apply,2} ...
file_server_2         <0.15.0>  {file_server,init,1} ...
global_group          <0.14.0>  {global_group,init,1} ...
global_name_server    <0.11.0>  {global,init,1} ...
inet_db               <0.13.0>  {inet_db,init,1} ...
init                  <0.0.0>   {otp_ring0,start,2} ...
kernel_safe_sup       <0.24.0>  {supervisor,kernel,1} ...
kernel_sup            <0.9.0>   {supervisor,kernel,1} ...
overload              <0.34.0>  {overload,init,1} ...
release_handler       <0.35.0>  {release_handler,init,1} ...
rex                   <0.10.0>  {rpc,init,1} ...
sasl_safe_sup         <0.32.0>  {supervisor,sasl,1} ...
sasl_sup              <0.31.0>  {supervisor,sasl,1} ...
user                  <0.20.0>  {group,server,2} ...
ok
6> gen_event:which_handlers(event_mgr).
[]

(oops -- your handler was not installed.)

(Try the add_handler command to see what it actually
returns.)

7> gen_event:add_handler(event_mgr,test_gen_event,[]).

 add_handler success {ok}

(It returns {ok}, which is not the expected return. It's
supposed to return 'ok'. Your handler's init/1 function
should return {ok,State} instead of {ok}.

You could check this in your code by writing
ok = gen_event:add_handler(...). This will give you a
distinct error message if something goes wrong.)

8>
8> v(7).
{ok}



2> test_gen_event:start_link().

 add_handler success ok

 Teriminating the Handler 3>
=ERROR REPORT==== 24-Feb-2003::14:02:51 ===
** gen_event handler test_gen_event crashed.
** Was installed in event_mgr
** Last event was: {request,980000001}
** When handler state == []
** Reason == {'EXIT',{format,[{io,format,
                                  [<0.21.0>,"~n Handle
request  ~w",980000001]},

{test_gen_event,handle_event,2},
                              {gen_event,server_update,4},
                              {gen_event,server_notify,4},
                              {gen_event,handle_msg,5},
                              {proc_lib,init_p,5}]}}

Now, there's your SASL error report due to a crash in your
handler. (-:



On Mon, 24 Feb 2003, Suresh S wrote:

>Hi Ulf,
>
>> If you're not doing so already, you should run your
>> tests
>> with the SASL application active. You can do this
>> either by
>> starting erlang with 'erl -boot start_sasl', or by
>> calling
>> application:start(sasl) in the shell of an already
>> running
>> system.
>
>
>Hi have tested this module implementing gen_event,
>When an event is notified to the event_mgr, it  is not
>handled,
>Even i started sasl also,
>
>the gen_event:add_handler is success i.e callback
>function init(_) is called.
>but when an event is notified gen_event:notify is
>called the callback function handle_event is not
>called
>
>what may the problem?
>Just please have a look at this module attached,
>
>
>
>
>
>________________________________________________________________________
>Missed your favourite TV serial last night? Try the new, Yahoo! TV.
>       visit http://in.tv.yahoo.com

-- 
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