Task #1119
closedImplement simple event scheduler
100%
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);
};
Updated by Junxiao Shi almost 11 years ago
- 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.
Updated by Alex Afanasyev almost 11 years ago
- Priority changed from High to Immediate
- Target version set to Mock
Updated by Alex Afanasyev almost 11 years ago
- Status changed from New to Feedback
- % Done changed from 0 to 100
Updated by Junxiao Shi almost 11 years ago
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.
Updated by Alex Afanasyev almost 11 years ago
- Status changed from Feedback to Closed
Updated by Junxiao Shi almost 11 years ago
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?
Updated by Alex Afanasyev almost 11 years ago
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.
Updated by Junxiao Shi almost 11 years ago
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.
Updated by Junxiao Shi almost 11 years ago
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.