Module ScheduleDispatcher

Core -- SCHEDULEDISPATCHER dispatches the different schedules.


Takes care of the creation and dispatching of scheduled functions for SCHEDULER objects.

This class is tricky and needs some thorought explanation. SCHEDULE classes are used to schedule functions for objects, or as persistent objects. The SCHEDULEDISPATCHER class ensures that:

  • Scheduled functions are planned according the SCHEDULER object parameters.
  • Scheduled functions are repeated when requested, according the SCHEDULER object parameters.
  • Scheduled functions are automatically removed when the schedule is finished, according the SCHEDULER object parameters.

The SCHEDULEDISPATCHER class will manage SCHEDULER object in memory during garbage collection: - When a SCHEDULER object is not attached to another object (that is, it's first :Schedule() parameter is nil), then the SCHEDULER

object is _persistent_ within memory.

- When a SCHEDULER object is attached to another object, then the SCHEDULER object is not persistent within memory after a garbage collection! The none persistency of SCHEDULERS attached to objects is required to allow SCHEDULER objects to be garbage collectged, when the parent object is also desroyed or nillified and garbage collected. Even when there are pending timer scheduled functions to be executed for the SCHEDULER object,
these will not be executed anymore when the SCHEDULER object has been destroyed.

The SCHEDULEDISPATCHER allows multiple scheduled functions to be planned and executed for one SCHEDULER object. The SCHEDULER object therefore keeps a table of "CallID's", which are returned after each planning of a new scheduled function by the SCHEDULEDISPATCHER. The SCHEDULER object plans new scheduled functions through the Scheduler#SCHEDULER.Schedule() method. The Schedule() method returns the CallID that is the reference ID for each planned schedule.


Contributions: -

Authors: FlightControl : Design & Programming

Global(s)

SCHEDULEDISPATCHER

Type SCHEDULEDISPATCHER

SCHEDULEDISPATCHER:AddSchedule(Scheduler, ScheduleFunction, ScheduleArguments, Start, Repeat, Randomize, Stop)

Add a Schedule to the ScheduleDispatcher.

SCHEDULEDISPATCHER.CallID
SCHEDULEDISPATCHER.ClassName
SCHEDULEDISPATCHER:Clear(Scheduler)
SCHEDULEDISPATCHER:New()
SCHEDULEDISPATCHER.ObjectSchedulers
SCHEDULEDISPATCHER.PersistentSchedulers
SCHEDULEDISPATCHER:RemoveSchedule(Scheduler, CallID)
SCHEDULEDISPATCHER.Schedule
SCHEDULEDISPATCHER:Start(Scheduler, CallID)
SCHEDULEDISPATCHER:Stop(Scheduler, CallID)

Global(s)

#SCHEDULEDISPATCHER SCHEDULEDISPATCHER

Type ScheduleDispatcher

Type SCHEDULEDISPATCHER

The SCHEDULEDISPATCHER structure

Field(s)

SCHEDULEDISPATCHER:AddSchedule(Scheduler, ScheduleFunction, ScheduleArguments, Start, Repeat, Randomize, Stop)

Add a Schedule to the ScheduleDispatcher.

The development of this method was really tidy. It is constructed as such that a garbage collection is executed on the weak tables, when the Scheduler is nillified. Nothing of this code should be modified without testing it thoroughly.

Parameters

SCHEDULEDISPATCHER.CallID
#string SCHEDULEDISPATCHER.ClassName
SCHEDULEDISPATCHER:Clear(Scheduler)

Parameter

  • Scheduler :

SCHEDULEDISPATCHER:New()
SCHEDULEDISPATCHER.ObjectSchedulers

Initialize the ObjectSchedulers array, which is a weakly coupled table. If the object used as the key is nil, then the garbage collector will remove the item from the Functions array.

SCHEDULEDISPATCHER.PersistentSchedulers

Initialize the ObjectSchedulers array, which is a weakly coupled table. If the object used as the key is nil, then the garbage collector will remove the item from the Functions array.

SCHEDULEDISPATCHER:RemoveSchedule(Scheduler, CallID)

Parameters

  • Scheduler :

  • CallID :

SCHEDULEDISPATCHER.Schedule
SCHEDULEDISPATCHER:Start(Scheduler, CallID)

Parameters

  • Scheduler :

  • CallID :

SCHEDULEDISPATCHER:Stop(Scheduler, CallID)

Parameters

  • Scheduler :

  • CallID :