public class ClockManager extends Object
The ClockManager
is used by the Topology
object to implement its clock mechanism.
Modifier and Type | Method and Description |
---|---|
void |
addClockListener(ClockListener listener)
Registers the specified listener to every pulse of the clock.
|
void |
addClockListener(ClockListener listener,
int period)
Registers the specified listener to the events of the clock.
|
int |
currentTime()
Returns the current round number.
|
Clock |
getClock()
Returns a reference to the
Clock . |
Class<? extends Clock> |
getClockModel()
Returns the clock model currently in use.
|
int |
getTimeUnit()
Returns the time unit of the clock, in milliseconds.
|
boolean |
isRunning()
Indicates whether the clock is currently running or paused.
|
void |
onClock() |
void |
pause()
Pauses the clock (or increments the pause counter).
|
void |
removeClockListener(ClockListener listener)
Unregisters the specified listener.
|
void |
reset()
Sets the clock time back to 0.
|
void |
resume()
Resumes the clock (or decrements the pause counter).
|
void |
setClockModel(Class<? extends Clock> clockModel)
Sets the clock model (to be instantiated automatically).
|
void |
setTimeUnit(int timeUnit)
Sets the time unit of the clock to the specified value in millisecond.
|
void |
start()
Starts the clock (if no model is set, DefaultClock is used).
|
public void onClock()
public Clock getClock()
Clock
.Clock
.public Class<? extends Clock> getClockModel()
public void setClockModel(Class<? extends Clock> clockModel)
clockModel
- A class that extends JBotSim's abstract Clockpublic void addClockListener(ClockListener listener, int period)
listener
- The listener to register.period
- The desired period between consecutive onClock() events,
in time units.public void addClockListener(ClockListener listener)
listener
- The listener to register.public void removeClockListener(ClockListener listener)
onClock()
method of this
listener will not longer be called.)listener
- The listener to unregister.public int getTimeUnit()
Returns the time unit of the clock, in milliseconds. The time unit is the duration of a round.
public void setTimeUnit(int timeUnit)
timeUnit
- The desired time unitpublic int currentTime()
public void start()
public boolean isRunning()
true
if running, false
if paused or not started.public void pause()
public void resume()
public void reset()