I think I get it. I should add ` self.register_observer(EventTest, self.name)
` in TestEvent.__init__(). Thanks very much!
And I also see register_handler() in class RyuApp, when should I use it?
2013/3/1 can. <c...@canx.me>
> But I still cannot see the 'recv: xxx' as expected, here are the outputs:
> -----
> loading app ryu.controller.ofp_handler
> loading app event.py
> instantiating app ryu.controller.ofp_handler
> instantiating app event.py
> -----
> and nothing more.
>
>
> 2013/3/1 OHMURA Kei <ohmura....@lab.ntt.co.jp>
>
>> 2013/3/1 can. <c...@canx.me>:
>> > What I want is a minimal example of handling event, including:
>> > 1) define an event
>> > 2) send an event
>> > 3) receive an event
>>
>> The following code would help your understanding?
>>
>> --
>> import gevent
>>
>> from ryu.base import app_manager
>> from ryu.controller import event
>> from ryu.controller.handler import set_ev_cls
>>
>>
>> TEST_EVENT_EV_DISPATCHER = "test_event"
>>
>>
>> class EventTest(event.EventBase):
>> def __init__(self, msg):
>> super(EventTest, self).__init__()
>> self.msg = msg
>>
>>
>> class TestEvent(app_manager.RyuApp):
>> def __init__(self):
>> super(TestEvent, self).__init__()
>> self.name = 'test_event'
>> gevent.spawn_later(0, self._send_event_loop)
>>
>> def _send_event_loop(self):
>> i = 0
>> while True:
>> self.send_event_to_observers(EventTest(i))
>> i += 1
>> gevent.sleep(1)
>>
>> @set_ev_cls(EventTest, TEST_EVENT_EV_DISPATCHER)
>> def _recv_handler(self, ev):
>> print 'recv:', ev.msg
>>
>
>
>
> --
> Best regards,
> Can Zhang
>
--
Best regards,
Can Zhang
------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_d2d_feb
_______________________________________________
Ryu-devel mailing list
Ryu-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ryu-devel