Project

General

Profile

Actions

Task #1119

closed

Implement simple event scheduler

Added by Alex Afanasyev almost 11 years ago. Updated almost 11 years ago.

Status:
Closed
Priority:
Immediate
Category:
Core
Target version:
Start date:
01/24/2014
Due date:
01/24/2014
% Done:

100%

Estimated time:
3.00 h

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);
};

Related issues 2 (0 open2 closed)

Related to ndn-cxx - Task #1152: time structsClosedAlex Afanasyev

Actions
Blocked by NFD - Task #1148: mock implementation of time structsClosedJunxiao Shi01/24/2014

Actions
Actions #1

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.

Actions #2

Updated by Junxiao Shi almost 11 years ago

  • Priority changed from Normal to High
Actions #3

Updated by Alex Afanasyev almost 11 years ago

  • Priority changed from High to Immediate
  • Target version set to Mock
Actions #4

Updated by Alex Afanasyev almost 11 years ago

  • Status changed from New to Feedback
  • % Done changed from 0 to 100
Actions #5

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.

Actions #6

Updated by Alex Afanasyev almost 11 years ago

  • Description updated (diff)
Actions #7

Updated by Alex Afanasyev almost 11 years ago

  • Status changed from Feedback to Closed
Actions #8

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?

Actions #9

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.

Actions #10

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.

Actions #11

Updated by Alex Afanasyev almost 11 years ago

Agreed.

Actions #12

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.

Actions #13

Updated by Junxiao Shi almost 11 years ago

  • Category set to Core
Actions

Also available in: Atom PDF