%
%  $Id: reactor.tex,v 1.7 2005/02/15 09:47:44 gokhale Exp $
%
% goal of this file is to discuss the challenges in developing DRE
% systems. We need to make a case that these systems are going to be
% assembled from middleware components. 
\subsection{Reactor Pattern in Middleware Implementations}
\label{sec:reactor}

Figure~\ref{fig:mw-demux} depicts a typical event demultiplexing and
dispatching mechanism documented in the Reactor pattern. The
application registers an event handler with the event demultiplexer
and delegates to it the responsibility of listening for incoming
events. On the occurrence of an event, the demultiplexer dispatches the
event by making a callback to the correct application-supplied event
handler. This is the idea behind the Reactor pattern, which provides
synchronous event demultiplexing and dispatching capabilities.

\begin{figure}[htb]
\begin{center}
\includegraphics[width=2.3in]{../Sigmetrics-2005/eps/demux.eps}
\bfcaption{Event Demultiplexers in Middleware}
\label{fig:mw-demux}
\end{center}
\end{figure}

The Reactor pattern could be implemented in many different ways
depending on the event demultiplexing capabilities provided by the
operating systems and the concurrency requirements of the
applications. For example, the demultiplexing capabilities of a
Reactor could be based on the {\em select} or {\em poll} system calls
provided by POSIX-compliant operating systems or {\em
WaitForMultipleObject} as found in the different flavors of Win32 operating
systems. Moreover, the handling of the event in the event handler
could be managed by the same thread of control that was listening for
events giving rise to a single-threaded Reactor
implementation. Alternately, the event could be delegated to a pool of
threads to handle the events to give rise to a thread-pool
Reactor. 
\iffalse
Delegation of events to one of the threads of the thread pool
can be implemented using either the {\em Leader-Follower} or the {\em
Active Object} patterns. These different choices are
dictated by the requirements of the application.
\fi
