Kea 2.7.6
|
Manages a pool of asynchronous interval timers. More...
#include <timer_mgr.h>
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 TimerMgrPtr & | instance () |
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. | |
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.
Definition at line 62 of file timer_mgr.h.
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.
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.
timer_name | Unique timer name. |
BadValue | if 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.
|
static |
Returns pointer to the sole instance of the TimerMgr
.
Definition at line 446 of file timer_mgr.cc.
Referenced by isc::dhcp::ControlledDhcpv4Srv::ControlledDhcpv4Srv(), isc::dhcp::ControlledDhcpv6Srv::ControlledDhcpv6Srv(), isc::dhcp::configureDhcp4Server(), isc::dhcp::configureDhcp6Server(), isc::dhcp::NetworkState::isDelayedEnableService(), isc::dhcp::ControlledDhcpv4Srv::processConfig(), and isc::dhcp::ControlledDhcpv6Srv::processConfig().
bool isc::dhcp::TimerMgr::isTimerRegistered | ( | const std::string & | timer_name | ) |
Checks if the timer with a specified name has been registered.
timer_name | Name of the timer. |
Definition at line 493 of file timer_mgr.cc.
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
.
timer_name | Unique name for the timer. |
callback | Pointer to the callback function to be invoked when the timer elapses, e.g. function processing expired leases in the DHCP server. |
interval | Timer interval in milliseconds. |
scheduling_mode | Scheduling mode of the timer as described in asiolink::IntervalTimer::Mode . |
BadValue | if 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.
void isc::dhcp::TimerMgr::setIOService | ( | const asiolink::IOServicePtr & | io_service | ) |
Sets IO service to be used by the Timer Manager.
io_service | Pointer to the IO service. |
Definition at line 523 of file timer_mgr.cc.
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.
timer_name | Unique timer name. |
BadValue | if 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.
size_t isc::dhcp::TimerMgr::timersCount | ( | ) | const |
Returns the number of registered timers.
Definition at line 498 of file timer_mgr.cc.
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.
timer_name | Name of the timer to be unregistered. |
BadValue | if 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.
void isc::dhcp::TimerMgr::unregisterTimers | ( | ) |
Unregisters all timers.
Definition at line 484 of file timer_mgr.cc.
References isc::dhcp::DHCPSRV_DBG_TRACE, isc::dhcp::dhcpsrv_logger, isc::dhcp::DHCPSRV_TIMERMGR_UNREGISTER_ALL_TIMERS, and LOG_DEBUG.