Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
Event andSignal DrivenProgrammingThe wheel already exists…
Feedback is precioushttps://joind.in/7027
Computer Science 201Event based programming …. ??? …. PROFIT!
Structured programming simple,hierarchical program flow structures     sequence     selection     repetition procedur...
Event Driven Programming                  Wait for                  Events      Handlers               Accept     are Call...
Transitioning to events code  flow is controlled by the user, not  the program software can sit “idle” until an event  o...
Asyncronous vs. Synchronous event-driven  !== asynchronous structured !== synchronous concurrency    through    Async ...
Interrupts asynchronous    signal/event indicating  need for change in execution or need for  attention “The ship is goi...
Design PatternsThe Evolution of Event based programming
Publish/Subscribe type   of event programming this is NOT observer publisher and subscriber are decoupled subscribers ...
SubscriberPublisher   Broker   Subscriber                     Subscriber
(Main) (event/message) loop poll blocks until something arrives dispatches main is added if it is the highest level of...
Subject/Observer this is a subset of publish/subscribe NOT  the other way around in this case, the subject maintains the...
Observer1Subject          Observer2          Observer3
Event/Handler events are spawned by the system events are dispatched to handlers which  are attached to them handler ca...
Object                         Handler1                               (Event1)          Send         Event2               ...
Dispatcher getsevent determines which handlers get called     either attached     determined by type     stored in so...
Signal/Slot signal – something you know is going to  happen that is attached to a class slot – method in a class that ca...
Reactor Resources Synchronous   Event Demultiplexer Dispatcher Request   Handler
Reactor  Service       Service     Service  Request       Request     Request            Demultiplexer             Dispatc...
Copy the Giants   Use examples of existing event driven codehttps://github.com/auroraeosrose/event-and-signal-exercises
Windows APIMessage Pump of Doom
On to the Code Concepts    Main “Loop” for processing    Message Queue holding messages    Windows (objects) post to q...
GobjectEvent Handler madness
On to the Code Concepts    Dispatcher    Register event by name    Attach a handler    Emit event
QTFor those who like a little ++with their C
On to the Code event–   virtual function in a class you  reimplement to handle the event signal – wired to a callback (s...
Best PracticesWhat to do in your own code
Name It properly   Publish / Subscribe    Dispatcher       Decoupled                           (Main) Event Loop   Su...
Standard interfaces Observer?  Use SplSubject and  SplObserver Pub/Sub? Event/Handler? Signal/Slot?
Borrow from other languages Any  C based language translates REALLY  well to PHP If you can’t depend on an extension, bu...
The future? Best  new hope for clean, easy eventing  implementations? Traits Some good wrappers around existing C  libra...
The Wild Wild WestExperiments are coming
Eventing Libraries https://github.com/christopherobin/Event  Emitter https://github.com/Wordi/LooPHP/tree/m  aster/LooPH...
Framework’s New Thing ZF2 – Event Manager Symfony 2 – Event Manager Kohana Events Aura (Aura.signal) CodeIgnitor even...
Extensions galore Php-gtk    (gobject)     http://gtk.php.net libevent        http://pecl.php.net/package/libevent eio...
node.php https://github.com/JosephMoniz/node.ph  p PHP extension using libuv (joyent based  platform abstraction eventin...
react-php http://nodephp.org/ Originally called nodephp (to great  screams), now is called react-php Is actually passin...
Bring it on Good   Libraries Blog posts Articles Extensions
Contact Me http://emsmith.net http://joind.in/7027 auroraeosrose@gmail.com IRC– freenode – auroraeosrose #coapp #phpm...
Event and Signal Driven Programming Zendcon 2012
Event and Signal Driven Programming Zendcon 2012
Event and Signal Driven Programming Zendcon 2012
Upcoming SlideShare
Loading in …5
×

Event and Signal Driven Programming Zendcon 2012

1,809 views

Published on

  • Be the first to comment

Event and Signal Driven Programming Zendcon 2012

  1. 1. Event andSignal DrivenProgrammingThe wheel already exists…
  2. 2. Feedback is precioushttps://joind.in/7027
  3. 3. Computer Science 201Event based programming …. ??? …. PROFIT!
  4. 4. Structured programming simple,hierarchical program flow structures  sequence  selection  repetition procedural  adds sub-routines or functions object oriented  modularizes components of code
  5. 5. Event Driven Programming Wait for Events Handlers Accept are Called Event Dispatch Event
  6. 6. Transitioning to events code flow is controlled by the user, not the program software can sit “idle” until an event occurs allows software to react why?
  7. 7. Asyncronous vs. Synchronous event-driven !== asynchronous structured !== synchronous concurrency through  Async I/O (epoll, IOCP, kqueue, et al)  threads  forking (multi-process)
  8. 8. Interrupts asynchronous signal/event indicating need for change in execution or need for attention “The ship is going to explode” A signal is a software interrupt delivered to a process
  9. 9. Design PatternsThe Evolution of Event based programming
  10. 10. Publish/Subscribe type of event programming this is NOT observer publisher and subscriber are decoupled subscribers express interest in a state change/event/message/signal each subscriber receives a copy
  11. 11. SubscriberPublisher Broker Subscriber Subscriber
  12. 12. (Main) (event/message) loop poll blocks until something arrives dispatches main is added if it is the highest level of control in a program
  13. 13. Subject/Observer this is a subset of publish/subscribe NOT the other way around in this case, the subject maintains the observers and notifies them of state change/event/message/signal more tightly coupled then publish/subscribe
  14. 14. Observer1Subject Observer2 Observer3
  15. 15. Event/Handler events are spawned by the system events are dispatched to handlers which are attached to them handler can go by many names – callback, closure, function events might have priority, might interrupt depending on the dispatch method used
  16. 16. Object Handler1 (Event1) Send Event2 Handler2 (Event1) Dispatcher Handler3 (Event1) Handler4Send Event (Event 2)
  17. 17. Dispatcher getsevent determines which handlers get called  either attached  determined by type  stored in some manner calls the handlers
  18. 18. Signal/Slot signal – something you know is going to happen that is attached to a class slot – method in a class that can be connected to a signal connect a signal to a slot (wire it up) emit the signal requires oo
  19. 19. Reactor Resources Synchronous Event Demultiplexer Dispatcher Request Handler
  20. 20. Reactor Service Service Service Request Request Request Demultiplexer Dispatcher Various Handlers
  21. 21. Copy the Giants Use examples of existing event driven codehttps://github.com/auroraeosrose/event-and-signal-exercises
  22. 22. Windows APIMessage Pump of Doom
  23. 23. On to the Code Concepts  Main “Loop” for processing  Message Queue holding messages  Windows (objects) post to queue  Queue passes messages around  Each window has a winproc to handle messages sent to it (switch of doom)
  24. 24. GobjectEvent Handler madness
  25. 25. On to the Code Concepts  Dispatcher  Register event by name  Attach a handler  Emit event
  26. 26. QTFor those who like a little ++with their C
  27. 27. On to the Code event– virtual function in a class you reimplement to handle the event signal – wired to a callback (slot) by a metaobject class, no loop necessarily required slot – the actual implemented function for an event or a callback attached to a signal
  28. 28. Best PracticesWhat to do in your own code
  29. 29. Name It properly Publish / Subscribe  Dispatcher  Decoupled  (Main) Event Loop Subject / Observer  stateless  State Machine Event / Handler  Message Pump  event loop  Reactor Signal / Slot  Tightly coupled objects  Traits
  30. 30. Standard interfaces Observer? Use SplSubject and SplObserver Pub/Sub? Event/Handler? Signal/Slot?
  31. 31. Borrow from other languages Any C based language translates REALLY well to PHP If you can’t depend on an extension, but want to “drop it in” – do the same API in a different namespace and class_alias as appropriate Upgrading from stone wheels to vulcanized rubber is great, but don’t reinvent
  32. 32. The future? Best new hope for clean, easy eventing implementations? Traits Some good wrappers around existing C libraries (libevent, dbus, glib/gobject, qt, winapi, . NET) Pulling in good ideas from other languages, PHP evolves
  33. 33. The Wild Wild WestExperiments are coming
  34. 34. Eventing Libraries https://github.com/christopherobin/Event Emitter https://github.com/Wordi/LooPHP/tree/m aster/LooPHP https://github.com/igorw/evenement https://github.com/kirbysayshi/SignalSlot
  35. 35. Framework’s New Thing ZF2 – Event Manager Symfony 2 – Event Manager Kohana Events Aura (Aura.signal) CodeIgnitor events I could go on….
  36. 36. Extensions galore Php-gtk (gobject)  http://gtk.php.net libevent http://pecl.php.net/package/libevent eio  http://pecl.php.net/package/eio libev  https://github.com/m4rw3r/php-libev
  37. 37. node.php https://github.com/JosephMoniz/node.ph p PHP extension using libuv (joyent based platform abstraction eventing layer ) and http parser used for node So essentially it IS node in a php extension
  38. 38. react-php http://nodephp.org/ Originally called nodephp (to great screams), now is called react-php Is actually passing off to another server Written in php
  39. 39. Bring it on Good Libraries Blog posts Articles Extensions
  40. 40. Contact Me http://emsmith.net http://joind.in/7027 auroraeosrose@gmail.com IRC– freenode – auroraeosrose #coapp #phpmentoring and others

×