2.4 The Reactor Control Interface

The reactor control interface is used to control the reactor lifecycle and is a part of the core package. Direct access to this API is only required for application startup code and it should not be accessed by more general application code. The reactor control interface is defined as shown in Listing 2.6.

% latex2html id marker 423\begin{small}\begin{verbatim}packa...
...erbatim} \end{small}\caption{Reactor Control Interface Definition}

The reactor creates its own thread for running the event loop, so three reactor control functions are provided for controlling it from the main program thread. Note that the API calls are synchronised, so they may be called from other thread contexts if required. The first method is the start method which passes in references to the monotonic clock and log service components which are to be used by the reactor. Calling this method creates the reactor thread and starts the reactor running before returning to the main thread.

In order to stop the reactor, a call to the stop method will initiate reactor shutdown, requesting that the reactor thread be stopped and all outstanding events either cancelled or dispatched. The stop method returns immediately and the main application thread must then wait for the reactor shutdown to complete. This is done by calling the join method which will block until the reactor thread has exited.