peersim.edsim
Class NextCycleEvent

java.lang.Object
  extended by peersim.edsim.NextCycleEvent
All Implemented Interfaces:
java.lang.Cloneable
Direct Known Subclasses:
RandNextCycle, RegRandNextCycle

public class NextCycleEvent
extends java.lang.Object
implements java.lang.Cloneable

This class is used to wrap a CDProtocol instance into an event so that it can be used in the event based simulation engine. This class is responsible for calling CDProtocol.nextCycle(peersim.core.Node, int) and also to schedule the consecutive cycle. In the configuration of an event driven simulation CDProtocols can be configured using CDScheduler, which places appropriate instances of this events in the queue.

Note that reimplementing method nextDelay(long) of this class allows for arbitrary scheduling, including adaptively changing or irregular cycle lengths, etc.

See Also:
CDScheduler, CDProtocol

Constructor Summary
NextCycleEvent(java.lang.String n)
          Reads configuration to initialize the object.
 
Method Summary
 java.lang.Object clone()
          Returns a clone of the object.
 void execute()
          Executes the nextCycle method of the protocol, and schedules the next call using the delay returned by nextDelay(long).
protected  long nextDelay(long step)
          Calculates the delay until the next execution of the protocol.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

NextCycleEvent

public NextCycleEvent(java.lang.String n)
Reads configuration to initialize the object. Extending classes should have a constructor with the same signature, often as simple as super(n).

Method Detail

clone

public java.lang.Object clone()
                       throws java.lang.CloneNotSupportedException
Returns a clone of the object. Overriding this method is necessary and typically is as simple as return super.clone(). In general, always use super.clone() to obtain the object to be returned on which you can perform optional deep cloning operations (arrays, etc).

Overrides:
clone in class java.lang.Object
Throws:
java.lang.CloneNotSupportedException

execute

public final void execute()
Executes the nextCycle method of the protocol, and schedules the next call using the delay returned by nextDelay(long). If the next execution time as defined by the delay is outside of the valid times as defined by CDScheduler.sch, then the next event is not scheduled. Note that this means that this protocol will no longer be scheduled because the next event after the next event is scheduled by the next event.


nextDelay

protected long nextDelay(long step)
Calculates the delay until the next execution of the protocol. This default implementation returns a constant delay equal to the step parameter (cycle length in this case) of the schedule of this event (as set in the config file).