Kea 2.7.5
isc::dhcp::TimerMgr Class Reference

Manages a pool of asynchronous interval timers. More...

#include <timer_mgr.h>

+ Inheritance diagram for isc::dhcp::TimerMgr:

Public Member Functions

 ~TimerMgr ()
 Destructor.
 
void setIOService (const asiolink::IOServicePtr &io_service)
 Sets IO service to be used by the Timer Manager.
 

Static Public Member Functions

static const TimerMgrPtrinstance ()
 Returns pointer to the sole instance of the TimerMgr.
 

Registering, unregistering and scheduling the timers.

void registerTimer (const std::string &timer_name, const asiolink::IntervalTimer::Callback &callback, const long interval, const asiolink::IntervalTimer::Mode &scheduling_mode)
 Registers new timer in the TimerMgr.
 
void unregisterTimer (const std::string &timer_name)
 Unregisters specified timer.
 
void unregisterTimers ()
 Unregisters all timers.
 
bool isTimerRegistered (const std::string &timer_name)
 Checks if the timer with a specified name has been registered.
 
size_t timersCount () const
 Returns the number of registered timers.
 
void setup (const std::string &timer_name)
 Schedules the execution of the interval timer.
 
void cancel (const std::string &timer_name)
 Cancels the execution of the interval timer.
 

Detailed Description

Manages a pool of asynchronous interval timers.

This class holds a pool of asynchronous interval timers.

This class is useful for performing periodic actions at the specified intervals, e.g. act upon expired leases (leases reclamation) or return declined leases back to the address pool. Other applications may be added in the future.

The TimerMgr is a singleton, thus its instance is available from different places in the server code. This is convenient because timers can be installed by different configuration parsers or they can be re-scheduled from the callback functions.

The timer is registered using the TimerMgr::registerTimer method. Each registered timer has a unique name. It is not possible to register multiple timers with the same name. Each registered timer is associated with the callback function supplied by the caller. This callback function performs the tasks to be executed periodically according to the timer's interval.

The registered timer's interval does not begin to elapse until the TimerMgr::setup method is called for it.

Before the TimerMgr can be used the server process must call TimerMgr::setIOService to associate the manager with the IO service that the server is using to its run tasks.

Note
Only scheduling new timer (calling setup) and canceling existing timer (calling cancel) are thread safe. Registering new timers (calling registerTimer) and unregistering existing timers (calling unregisterTimer) must be handled before starting processing threads.

Definition at line 62 of file timer_mgr.h.

Constructor & Destructor Documentation

◆ ~TimerMgr()

isc::dhcp::TimerMgr::~TimerMgr ( )

Destructor.

Stops the worker thread if it is running and unregisters any registered timers.

Definition at line 455 of file timer_mgr.cc.

Member Function Documentation

◆ cancel()

void isc::dhcp::TimerMgr::cancel ( const std::string & timer_name)

Cancels the execution of the interval timer.

This method has no effect if the timer hasn't been scheduled with the TimerMgr::setup method.

Parameters
timer_nameUnique timer name.
Exceptions
BadValueif the timer hasn't been registered.

Definition at line 513 of file timer_mgr.cc.

References isc::dhcp::DHCPSRV_DBG_TRACE, isc::dhcp::dhcpsrv_logger, isc::dhcp::DHCPSRV_TIMERMGR_STOP_TIMER, and LOG_DEBUG.

◆ instance()

◆ isTimerRegistered()

bool isc::dhcp::TimerMgr::isTimerRegistered ( const std::string & timer_name)

Checks if the timer with a specified name has been registered.

Parameters
timer_nameName of the timer.
Returns
true if the timer with the specified name has been registered, false otherwise.

Definition at line 493 of file timer_mgr.cc.

◆ registerTimer()

void isc::dhcp::TimerMgr::registerTimer ( const std::string & timer_name,
const asiolink::IntervalTimer::Callback & callback,
const long interval,
const asiolink::IntervalTimer::Mode & scheduling_mode )

Registers new timer in the TimerMgr.

Parameters
timer_nameUnique name for the timer.
callbackPointer to the callback function to be invoked when the timer elapses, e.g. function processing expired leases in the DHCP server.
intervalTimer interval in milliseconds.
scheduling_modeScheduling mode of the timer as described in asiolink::IntervalTimer::Mode.
Exceptions
BadValueif the timer name is invalid or duplicate.

Definition at line 460 of file timer_mgr.cc.

References isc::dhcp::DHCPSRV_DBG_TRACE, isc::dhcp::dhcpsrv_logger, isc::dhcp::DHCPSRV_TIMERMGR_REGISTER_TIMER, and LOG_DEBUG.

◆ setIOService()

void isc::dhcp::TimerMgr::setIOService ( const asiolink::IOServicePtr & io_service)

Sets IO service to be used by the Timer Manager.

Parameters
io_servicePointer to the IO service.

Definition at line 523 of file timer_mgr.cc.

◆ setup()

void isc::dhcp::TimerMgr::setup ( const std::string & timer_name)

Schedules the execution of the interval timer.

This method schedules the timer, i.e. the callback will be executed after specified interval elapses. The interval has been specified during timer registration. Depending on the mode selected during the timer registration, the callback will be executed once after it has been scheduled or until it is cancelled. Though, in the former case the timer can be re-scheduled in the callback function.

Parameters
timer_nameUnique timer name.
Exceptions
BadValueif the timer hasn't been registered.

Definition at line 503 of file timer_mgr.cc.

References isc::dhcp::DHCPSRV_DBG_TRACE, isc::dhcp::dhcpsrv_logger, isc::dhcp::DHCPSRV_TIMERMGR_START_TIMER, and LOG_DEBUG.

◆ timersCount()

size_t isc::dhcp::TimerMgr::timersCount ( ) const

Returns the number of registered timers.

Definition at line 498 of file timer_mgr.cc.

◆ unregisterTimer()

void isc::dhcp::TimerMgr::unregisterTimer ( const std::string & timer_name)

Unregisters specified timer.

This method cancels the timer if it is setup and removes it from the internal collection of timers.

Parameters
timer_nameName of the timer to be unregistered.
Exceptions
BadValueif the specified timer hasn't been registered.

Definition at line 474 of file timer_mgr.cc.

References isc::dhcp::DHCPSRV_DBG_TRACE, isc::dhcp::dhcpsrv_logger, isc::dhcp::DHCPSRV_TIMERMGR_UNREGISTER_TIMER, and LOG_DEBUG.

◆ unregisterTimers()

void isc::dhcp::TimerMgr::unregisterTimers ( )

The documentation for this class was generated from the following files: