Task #1290
closedGlobal io_service and Scheduler
100%
Description
Create a global instance of io_service
and Scheduler
.
namespace nfd {
boost::asio::io_service& getGlobalIoService();
namespace scheduler {
struct EventId;
typedef function<void()> Event;
EventId schedule(time::Duration after, Event event);
void cancel(const EventId& eventId);
} // namespace scheduler
using scheduler::EventId; // import to nfd namespace
} // namespace nfd
The global instances can be replaced/cleared/reset during unit testing.
This task is divided to two stages:
Stage 1¶
- Create global
io_service
andScheduler
. nfd::Scheduler
class still exists. Its global instance is accessed atnfd::scheduler::getGlobalScheduler()
.- Use the global
io_service
inmain()
. Forwarder
uses the globalScheduler
.- Unit tests can have their own
io_service
andScheduler
, if they don't interact withForwarder
.
Stage 2¶
- Delete references to
io_service
andScheduler
in all classes and constructors. - Change all scheduler calls to use
nfd::scheduler::schedule
andnfd::scheduler::cancel
. - Delete or move away
nfd::Scheduler
class. Deletenfd::getGlobalScheduler()
function. - Unit tests also use the global instances, and are provided a way to reset / replace the global
io_service
andScheduler
.
Updated by Junxiao Shi over 10 years ago
- Description updated (diff)
- Status changed from New to In Progress
- Start date set to 02/25/2014
Updated by Junxiao Shi over 10 years ago
- Description updated (diff)
- Status changed from In Progress to Code review
- % Done changed from 0 to 40
Updated by Junxiao Shi over 10 years ago
- Estimated time changed from 1.50 h to 2.50 h
Updated by Davide Pesavento over 10 years ago
I think this is a step backwards. Singletons and global variables are usually bad. We should aim at reducing their number, not adding more. The dependency injection pattern should be used instead, because it greatly simplifies unit testability.
Updated by Junxiao Shi over 10 years ago
I'm facing difficulty in cancelling a scheduled event at StrategyInfo
subclass's destructor.
The alternate to having a global Scheduler
is to have a reference to the Scheduler
instance in every StrategyInfo
subclass instance that contains a scheduled event. This has a memory cost.
Updated by Junxiao Shi over 10 years ago
- Status changed from Code review to In Progress
- Priority changed from High to Low
- % Done changed from 40 to 50
Stage 1 is merged. Stage 2 will start later.
Updated by Junxiao Shi over 10 years ago
- Status changed from In Progress to Code review
- % Done changed from 50 to 60
All test cases can have a fresh global io_service now.
Updated by Junxiao Shi over 10 years ago
- Status changed from Code review to In Progress
- Assignee changed from Junxiao Shi to Alex Afanasyev
Updated by Junxiao Shi over 10 years ago
- Status changed from In Progress to Closed
- % Done changed from 60 to 100
Already merged.
Updated by Junxiao Shi over 10 years ago
- Status changed from Closed to Code review
If994e3bd303f0788d8e945351c182bbd4ab5e0b2 deletes deprecated getGlobalScheduler()
public API.
Updated by Junxiao Shi over 10 years ago
- Status changed from Code review to Closed