The Reactor pattern (shown in Figure 1) involves the following
objects:
Figure 1:
Structure of Reactor pattern
![\includegraphics[scale=0.4]{reactor}](img1.png) |
- Handles
- Handles are objects by which incoming communication channels or
similar entities (e.g. timers, files, synchronisation constructs) are
accessed and events received from them.
- Synchronous event demultiplexer (demux)
- A demux is given a set of
handles and has a method called select that waits until an event is
received. When select is called, the demux waits until at least one
handle has an unread event and then reports that a message can be read.
- Event handler
- An event handler has a single method handleEvent
that takes an event as a parameter and processes it in whatever manner the
application needs.
- Initiation dispatcher
- A dispatcher has a set of handle/event handler
pairs and methods to add and remove such pairs. It has a method
handleEvents that repeatedly uses a demux to wait for events on the
handles in the set and then sends each event to the corresponding event
handler.
A typical Reactor-based application uses only one dispatcher and therefore
only one demux and one thread (although the Reactor implementation may contain
additional threads).
Jan Lönnberg
2006-10-23