Task #1119
closed
Implement simple event scheduler
Added by Alex Afanasyev almost 11 years ago.
Updated almost 11 years ago.
Description
Scheduler interface specification:
class Scheduler
{
public:
typedef function<void()> Event;
Scheduler(boost::asio::io_service& ioService);
/**
* \brief Schedule one time event after the specified delay
* \returns EventId that can be used to cancel the scheduled event
*/
EventId
scheduleEvent(const time::Duration& after, const Event& event);
/**
* \brief Schedule periodic event that should be fired every specified period.
* First event will be fired after the specified delay.
* \returns EventId that can be used to cancel the scheduled event
*/
EventId
schedulePeriodicEvent(const time::Duration& after,
const time::Duration& period,
const Event& event);
/**
* \brief Cancel scheduled event
*/
void
cancelEvent(const EventId& eventId);
};
- Due date set to 01/24/2014
- Assignee set to Alex Afanasyev
- Start date changed from 01/21/2014 to 01/24/2014
- Estimated time set to 3.00 h
Scheduler::scheduleEvent
and Scheduler::cancelEvent
are required for mock PIT.
- Priority changed from Normal to High
- Priority changed from High to Immediate
- Target version set to Mock
- Status changed from New to Feedback
- % Done changed from 0 to 100
Scheduler requires time::Point
and time::Duration
to have be structs, not typedefs.
Unit testing is missing on new time::Point
and time::Duration
structs, and should be added with #1152.
- Description updated (diff)
- Status changed from Feedback to Closed
Question: What's the intended way to instantiate the Scheduler?
If several components need Scheduler, should they each create a Scheduler instance upon the same ioService, or should they use the same Scheduler instance?
Technically it doesn't matter. In other case, all events are executed from the same thread. The only difference is additional overhead (additional deadline_timer service in io_service). If components are completely independent, then I would say separate schedulers make more sense, otherwise we should just use one.
It's cleaner to have a private Scheduler instance per module, as long as the total number instances is O(1) (eg. you can't have a Scheduler per pit::Entry).
One consequence is that a ScheduledEvent must be cancelled through the same Scheduler at which it was scheduled. This is easy to achieve.
I hope there is an EventId::cancel
method like ns3::EventId::Cancel
, so that EventId won't be cancelled on the wrong Scheduler.
The way to achieve this is to store a pointer to Scheduler inside EventId structure.
Also available in: Atom
PDF