avrora.sim.clock
Class IntervalSynchronizer

java.lang.Object
  extended byavrora.sim.clock.Synchronizer
      extended byavrora.sim.clock.IntervalSynchronizer

public class IntervalSynchronizer
extends Synchronizer

The IntervalSynchronizer class implements a global timer among multiple simulators by inserting periodic events into the queue of each simulator.


Nested Class Summary
protected  class IntervalSynchronizer.SynchEvent
          The SynchEvent class represents an event that is inserted into the event queue of each simulator at the same global time.
 
Field Summary
protected  Simulator.Event action
           
protected  java.lang.Object condition
           
protected  int goal
           
protected  int meet_count
           
protected  long period
          period is the number of cycles on a member local clock per cycle on the global clock.
protected  java.util.HashMap threadMap
           
protected  int wait_count
           
protected  avrora.sim.clock.IntervalSynchronizer.WaitSlot waitSlotList
           
 
Constructor Summary
IntervalSynchronizer(long p, Simulator.Event a)
          The constructor for the IntervalSynchronizer class creates a new synchronizer with the specified period, that will fire the specified event each time all threads meet at a synchronization point.
 
Method Summary
 void addNode(Simulation.Node t)
          The addNode() method adds a node to this synchronization group.
 void adjustPeriod(long nperiod)
          The adjustPeriod() method can be used to adjust the period of synchronization while the simulation is executing.
protected  avrora.sim.clock.IntervalSynchronizer.WaitSlot checkWaiters()
           
protected  avrora.sim.clock.IntervalSynchronizer.WaitSlot insertWaiter(IntervalSynchronizer.SynchEvent event, long time)
           
 void join()
          The join() method will block the caller until all of the threads in this synchronization interval have terminated, either through stop() being called, or terminating normally such as through a timeout.
 void pause()
          The pause() method temporarily pauses the simulation.
 void removeNode(Simulation.Node t)
          The removeNode() method removes a node from this synchronization group, and wakes any nodes that might be waiting on it.
protected  boolean signalOthers()
          The signalOthers() method is used to check whether the thread that has just arrived should signal other threads to continue.
 void start()
          The start() method starts the threads executing, and the synchronizer will add whatever synchronization to their execution that is necessary to preserve the global timing properties of simulation.
protected  boolean stillWaiting(avrora.sim.clock.IntervalSynchronizer.WaitSlot w)
           
 void stop()
          The stop() method will terminate all the simulation threads.
 void synch(long globalTime)
          The synch() method will pause all of the nodes at the same global time.
 void waitForNeighbors(long time)
          The waitForNeighbors() method is called from within the execution of a node when that node needs to wait for its neighbors to catch up to it in execution time.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

period

protected long period
period is the number of cycles on a member local clock per cycle on the global clock. Some re-coding must be done if microcontrollers running at difference speeds are to be accurately simulated.


threadMap

protected final java.util.HashMap threadMap

action

protected final Simulator.Event action

condition

protected final java.lang.Object condition

goal

protected int goal

meet_count

protected int meet_count

wait_count

protected int wait_count

waitSlotList

protected avrora.sim.clock.IntervalSynchronizer.WaitSlot waitSlotList
Constructor Detail

IntervalSynchronizer

public IntervalSynchronizer(long p,
                            Simulator.Event a)
The constructor for the IntervalSynchronizer class creates a new synchronizer with the specified period, that will fire the specified event each time all threads meet at a synchronization point.

Parameters:
p - the period in clock cycles which to synchronize the threads
a - the event to fire each time all threads meet at a synchronization point
Method Detail

signalOthers

protected boolean signalOthers()
The signalOthers() method is used to check whether the thread that has just arrived should signal other threads to continue.

Returns:
true if this thread signalled the others to continue; false if this thread should stop and wait for the other threads before continuing

start

public void start()
The start() method starts the threads executing, and the synchronizer will add whatever synchronization to their execution that is necessary to preserve the global timing properties of simulation.

Specified by:
start in class Synchronizer

join

public void join()
          throws java.lang.InterruptedException
The join() method will block the caller until all of the threads in this synchronization interval have terminated, either through stop() being called, or terminating normally such as through a timeout.

Specified by:
join in class Synchronizer
Throws:
java.lang.InterruptedException

stop

public void stop()
The stop() method will terminate all the simulation threads. It is not guaranteed to stop all the simulation threads at the same global time.

Specified by:
stop in class Synchronizer

pause

public void pause()
The pause() method temporarily pauses the simulation. The nodes are not guaranteed to stop at the same global time. This method will return when all threads in the simulation have been paused and will no longer make progress until the start() method is called again.

Specified by:
pause in class Synchronizer

synch

public void synch(long globalTime)
The synch() method will pause all of the nodes at the same global time. This method can only be called when the simulation is paused. It will run all threads forward until the global time specified and pause them.

Specified by:
synch in class Synchronizer
Parameters:
globalTime - the global time in clock cycles to run all threads ahead to

addNode

public void addNode(Simulation.Node t)
The addNode() method adds a node to this synchronization group. This method should only be called before the start() method is called.

Specified by:
addNode in class Synchronizer
Parameters:
t - the simulator representing the node to add to this group

removeNode

public void removeNode(Simulation.Node t)
The removeNode() method removes a node from this synchronization group, and wakes any nodes that might be waiting on it.

Specified by:
removeNode in class Synchronizer
Parameters:
t - the simulator thread to remove from this synchronization group

waitForNeighbors

public void waitForNeighbors(long time)
The waitForNeighbors() method is called from within the execution of a node when that node needs to wait for its neighbors to catch up to it in execution time. The node will be blocked until the other nodes in other threads catch up in global time.

Specified by:
waitForNeighbors in class Synchronizer

insertWaiter

protected avrora.sim.clock.IntervalSynchronizer.WaitSlot insertWaiter(IntervalSynchronizer.SynchEvent event,
                                                                      long time)

checkWaiters

protected avrora.sim.clock.IntervalSynchronizer.WaitSlot checkWaiters()

stillWaiting

protected boolean stillWaiting(avrora.sim.clock.IntervalSynchronizer.WaitSlot w)

adjustPeriod

public void adjustPeriod(long nperiod)
The adjustPeriod() method can be used to adjust the period of synchronization while the simulation is executing. This is useful for adaptive types of synchronization, for example when the latency between beginning the first transmission and reception is larger than subsequent transmissions (e.g. implementing partial preamble loss). Care should be taken when calling this method! It should only be called at times when the simulation is guaranteed to be stopped at the same global time; i.e. either at a meet point or while it has been pause()'d and synch()'d.

Parameters:
nperiod - the new period in cycles