org.simulare
Class Clock

java.lang.Object
  extended byorg.simulare.Clock

public class Clock
extends java.lang.Object

Define a clock manager responsible for simulating a time schedule for executing some operations. This clock fires events in a periodic rate defined by the attribute period. To allow a better simulation of parallelism the fireEvent method notifys listeners using a random order.


Constructor Summary
Clock()
          Creates a clock with a period of 1 second, and maxCounter to positive infinite.
Clock(long period, long maxCounter)
          Creates a clock with a period.
 
Method Summary
 void addClockListener(ClockListener l)
          Remove a clock listener added.
protected  void fireClockChanged(ClockEvent e)
           
protected  void fireClockPaused(ClockEvent e)
           
protected  void fireClockResumed(ClockEvent e)
           
protected  void fireClockStarted(ClockEvent e)
           
protected  void fireClockStoped(ClockEvent e)
           
 long getMaxCounter()
          Return the max number of clock ticks.
 long getPeriod()
          The clock period in miliseconds.
 boolean isPaused()
          Indicate if the clock is in pause.
 void pause()
          Interrupts the clock counting.
 void removeClockListener(ClockListener l)
          Add a new clock listener.
 void resume()
          Resume the clock execution.
 void setMaxCounter(long maxCounter)
          Set the max counter for the clock.
 void setPeriod(long period)
          Set the clock period.
 void start()
          Start the clock.
 void stop()
          Stop the clock.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Clock

public Clock()
Creates a clock with a period of 1 second, and maxCounter to positive infinite.


Clock

public Clock(long period,
             long maxCounter)
Creates a clock with a period.

Parameters:
period - The periodic Thread interval execution.
maxCounter - The max number of clock ticks.
Method Detail

getPeriod

public long getPeriod()
The clock period in miliseconds.

Returns:
The clock period.

setPeriod

public void setPeriod(long period)
Set the clock period. The period only has efect if the clock has not started yet, or the clock is in pause, is this case the clock can resume its execution with a new period.

Parameters:
period - The clock period.

isPaused

public boolean isPaused()
Indicate if the clock is in pause.

Returns:
true, the clock is paused, false, otherwise.

getMaxCounter

public long getMaxCounter()
Return the max number of clock ticks.

Returns:
The max number of clock ticks.

setMaxCounter

public void setMaxCounter(long maxCounter)
Set the max counter for the clock.

Parameters:
maxCounter - The max cicle counter. After this limit has been reached the clock stops.

start

public void start()
Start the clock. After started the clock start to fire events.


pause

public void pause()
Interrupts the clock counting.


resume

public void resume()
Resume the clock execution.


stop

public void stop()
Stop the clock.


removeClockListener

public void removeClockListener(ClockListener l)
Add a new clock listener.

Parameters:
l - The clock listener.

addClockListener

public void addClockListener(ClockListener l)
Remove a clock listener added. If the listener was not added before, this method has no efect.

Parameters:
l - The clock listener.

fireClockStarted

protected void fireClockStarted(ClockEvent e)

fireClockPaused

protected void fireClockPaused(ClockEvent e)

fireClockResumed

protected void fireClockResumed(ClockEvent e)

fireClockStoped

protected void fireClockStoped(ClockEvent e)

fireClockChanged

protected void fireClockChanged(ClockEvent e)