3.4 Rescheduling One-Shot Timers

In addition to being able to cancel running timers, it is also possible to reschedule them - effectively resetting the timer delay to a new value. This may be demonstrated by using timer rescheduling to delay the reactor shutdown in Listing 3.3. The changes required are shown in Listing 3.5. As may be seen from the example, rescheduling a timer is simply a case of calling the runTimerOneShot method with a reference to the associated timeable callback object and the new timer delay. The full code for this example is included in the timer examples package as OneShotTimerExample3.


\begin{listing}
% latex2html id marker 675\begin{small}\begin{verbatim}...
...
....\end{verbatim} \end{small}\caption{Rescheduling a One Shot Timer}
\end{listing}

Timer rescheduling may be used to implement the watchdog timer idiom. This provides a mechanism for monitoring a remote system which provides a regular `heartbeat' or `liveness' notification. Each time a heartbeat event is received the timer is rescheduled, preventing it from issuing the timer callback. However, if the remote system becomes inoperable it will stop sending heartbeat messages and the timer will expire. This causes the timer to issue a callback to the timeable callback object. The callback may then be interpreted as notification that the remote system is no longer available.