peersim.edsim
Class CDScheduler

java.lang.Object
  extended by peersim.edsim.CDScheduler
All Implemented Interfaces:
Control, NodeInitializer

public class CDScheduler
extends java.lang.Object
implements Control, NodeInitializer

Schedules the first execution of the cycle based protocol instances in the event driven engine. It implements Control but it will most often be invoked only once for each protocol as an initializer, since the scheduled events schedule themselves for the consecutive executions (see NextCycleEvent).

All CDProtocol specifications in the configuration need to contain a Scheduler specification at least for the step size (see config parameter "step" of Scheduler). This value is used as the cycle length for the corresponding protocol.

See Also:
NextCycleEvent

Parameter Summary
nextcycle
          Parameter that is used to define the class that is used to schedule the next cycle.
protocol
          The protocols that this scheduler schedules for the first execution.
randstart
          If set, it means that the initial execution of the given protocol is scheduled for a different random time for all nodes.
 
Field Summary
static Scheduler[] sch
          Contains the scheduler objects for all CDProtocols defined in the configuration.
 
Constructor Summary
CDScheduler(java.lang.String n)
          Initialization based on configuration parameters.
 
Method Summary
 boolean execute()
          Schedules the protocol at all nodes for the first execution adding it to the priority queue of the event driven simulation.
protected  long firstDelay(long cyclelength)
          Returns the time (through giving the delay from the current time) when this even is first executed.
 void initialize(Node n)
          Schedules the protocol at given node for the first execution adding it to the priority queue of the event driven simulation.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Parameter Detail

nextcycle

Parameter that is used to define the class that is used to schedule the next cycle. Its type is (or extends) NextCycleEvent. Defaults to NextCycleEvent.


protocol

The protocols that this scheduler schedules for the first execution. It might contain several protocol names, separated by whitespace. All protocols will be scheduled based on the common parameter set for this scheduler and the parameters of the protocol (cycle length). Protocols are scheduled independently of each other.


randstart

If set, it means that the initial execution of the given protocol is scheduled for a different random time for all nodes. The random time is a sample between the current time (inclusive) and the cycle length (exclusive), the latter being specified by the step parameter (see Scheduler) of the assigned protocol.

See Also:
execute()
Field Detail

sch

public static final Scheduler[] sch
Contains the scheduler objects for all CDProtocols defined in the configuration. The length of the array is the number of protocols defined, but those entries that belong to protocols that are not CDProtocols are null.

Constructor Detail

CDScheduler

public CDScheduler(java.lang.String n)
Initialization based on configuration parameters.

Method Detail

execute

public boolean execute()
Schedules the protocol at all nodes for the first execution adding it to the priority queue of the event driven simulation. The time of the first execution is determined by firstDelay(long). The implementation calls initialize(peersim.core.Node) for all nodes.

Specified by:
execute in interface Control
Returns:
true if the simulation has to be stopped, false otherwise.
See Also:
initialize(peersim.core.Node)

initialize

public void initialize(Node n)
Schedules the protocol at given node for the first execution adding it to the priority queue of the event driven simulation. The time of the first execution is determined by a reference point in time and firstDelay(long), which defines the delay from the reference point. The reference point is the maximum of the current time, and the value of parameter "from" of the protocol being scheduled. If the calculated time of the first execution is not valid according to the schedule of the protocol then no execution is scheduled for that protocol.

A final note: for performance reasons, the recommended practice is not to use parameter "from" in protocols, but to schedule CDScheduler itself for the desired time, whenever possible (e.g., it is not possible if CDScheduler is used as a NodeInitializer).

Specified by:
initialize in interface NodeInitializer

firstDelay

protected long firstDelay(long cyclelength)
Returns the time (through giving the delay from the current time) when this even is first executed. If "randstart" is not set, it returns zero, otherwise a random value between 0, inclusive, and cyclelength, exclusive.

Parameters:
cyclelength - The cycle length of the cycle based protocol for which this method is called