Package jadex.platform.service.clock
Class AbstractClock
- java.lang.Object
-
- jadex.platform.service.clock.AbstractClock
-
- All Implemented Interfaces:
IClock
- Direct Known Subclasses:
ContinuousClock
,SimulationEventClock
,SimulationTickClock
public abstract class AbstractClock extends java.lang.Object implements IClock
Abstract base class for all clocks.
-
-
Field Summary
Fields Modifier and Type Field Description protected long
currenttime
The current time (last measurement).static long
DEFAULT_DELTA
The default delta (tick time).protected long
delta
The clock tick delta (relative to base time).protected java.util.List
listeners
The change listeners.protected java.lang.String
name
The clock name.protected long
starttime
The start time (model time).protected java.lang.String
state
The clock state.protected Timer
ticktimer
The tick timer.protected java.util.List
ticktimers
The tick timers.java.util.SortedSet
timers
The timers (entries ordered by timepoint).-
Fields inherited from interface jadex.bridge.service.types.clock.IClock
EVENT_TYPE_NEW_DELTA, EVENT_TYPE_NEW_DILATION, EVENT_TYPE_NEXT_TIMEPOINT, EVENT_TYPE_RESET, EVENT_TYPE_STARTED, EVENT_TYPE_STOPPED, EVENT_TYPE_TIMER_ADDED, EVENT_TYPE_TIMER_REMOVED, STATE_RUNNING, STATE_SUSPENDED, TYPE_CONTINUOUS, TYPE_EVENT_DRIVEN, TYPE_SYSTEM, TYPE_TIME_DRIVEN
-
-
Constructor Summary
Constructors Constructor Description AbstractClock(java.lang.String name, long starttime, long delta)
Create a new clock.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
activateTickTimer()
Activate the tick timer.void
addChangeListener(IChangeListener listener)
Add a change listener.void
addTickTimer(ITimer timer)
Add a tick timer.void
addTimer(ITimer timer)
Add a timer.void
copyFromClock(IClock oldclock)
Transfer state from another clock to this clock.ITimer
createTickTimer(ITimedObject to)
Create a new tick timer.ITimer
createTimer(long timespan, ITimedObject to)
Create a new timer.void
dispose()
Called, when the clock is no longer used.long
getDelta()
Get the clock delta.java.lang.String
getName()
Get the current time.ITimer
getNextTimer()
Get the next timer.long
getStarttime()
Get the clocks start time.java.lang.String
getState()
Get the clock state.double
getTick()
Get the current tick.ITimer[]
getTickTimers()
Get all active tick timers.long
getTime()
Get the clocks name.ITimer[]
getTimers()
Get all active timers.protected boolean
hasListeners()
Check if the clock has listeners.protected void
notifyListeners(ChangeEvent ce)
Notify the listeners.void
removeChangeListener(IChangeListener listener)
Remove a change listener.void
removeTickTimer(ITimer timer)
Remove a tick timer.void
removeTimer(ITimer timer)
Remove a timer.void
reset()
Reset the clock.void
setDelta(long delta)
Set the clock delta.void
setStarttime(long starttime)
Set the clocks start time.void
shutdown(IResultListener listener)
Shutdown the service.void
start()
Start the clock.void
stop()
Stop the clock.
-
-
-
Field Detail
-
DEFAULT_DELTA
public static final long DEFAULT_DELTA
The default delta (tick time).- See Also:
- Constant Field Values
-
name
protected java.lang.String name
The clock name.
-
starttime
protected long starttime
The start time (model time).
-
currenttime
protected long currenttime
The current time (last measurement).
-
delta
protected long delta
The clock tick delta (relative to base time).
-
state
protected java.lang.String state
The clock state.
-
ticktimers
protected java.util.List ticktimers
The tick timers.
-
timers
public java.util.SortedSet timers
The timers (entries ordered by timepoint).
-
ticktimer
protected Timer ticktimer
The tick timer.
-
listeners
protected java.util.List listeners
The change listeners.
-
-
Method Detail
-
copyFromClock
public void copyFromClock(IClock oldclock)
Transfer state from another clock to this clock.
-
dispose
public void dispose()
Called, when the clock is no longer used.
-
getName
public java.lang.String getName()
Get the current time.
-
getStarttime
public long getStarttime()
Get the clocks start time.- Specified by:
getStarttime
in interfaceIClock
- Returns:
- The start time.
-
setStarttime
public void setStarttime(long starttime)
Set the clocks start time.- Specified by:
setStarttime
in interfaceIClock
- Parameters:
starttime
- The start time.
-
getTime
public long getTime()
Get the clocks name.
-
getTick
public double getTick()
Get the current tick.
-
getDelta
public long getDelta()
Get the clock delta.
-
setDelta
public void setDelta(long delta)
Set the clock delta. param delta The new clock delta.
-
getNextTimer
public ITimer getNextTimer()
Get the next timer.- Specified by:
getNextTimer
in interfaceIClock
- Returns:
- The next timer.
-
getState
public java.lang.String getState()
Get the clock state.
-
createTimer
public ITimer createTimer(long timespan, ITimedObject to)
Create a new timer.- Specified by:
createTimer
in interfaceIClock
- Parameters:
timespan
- The timespan.to
- The timed object.
-
createTickTimer
public ITimer createTickTimer(ITimedObject to)
Create a new tick timer.- Specified by:
createTickTimer
in interfaceIClock
- Parameters:
to
- The timed object.info
- Optional info object.
-
getTimers
public ITimer[] getTimers()
Get all active timers.
-
getTickTimers
public ITimer[] getTickTimers()
Get all active tick timers.- Specified by:
getTickTimers
in interfaceIClock
- Returns:
- The active tick timers.
-
addTimer
public void addTimer(ITimer timer)
Add a timer.
-
removeTimer
public void removeTimer(ITimer timer)
Remove a timer.- Specified by:
removeTimer
in interfaceIClock
- Parameters:
timer
- The timer.
-
addTickTimer
public void addTickTimer(ITimer timer)
Add a tick timer.- Specified by:
addTickTimer
in interfaceIClock
- Parameters:
timer
- The timer.
-
activateTickTimer
protected void activateTickTimer()
Activate the tick timer.
-
removeTickTimer
public void removeTickTimer(ITimer timer)
Remove a tick timer.- Specified by:
removeTickTimer
in interfaceIClock
- Parameters:
timer
- The timer.
-
addChangeListener
public void addChangeListener(IChangeListener listener)
Add a change listener.- Specified by:
addChangeListener
in interfaceIClock
- Parameters:
listener
- The change listener.
-
removeChangeListener
public void removeChangeListener(IChangeListener listener)
Remove a change listener.- Specified by:
removeChangeListener
in interfaceIClock
- Parameters:
listener
- The change listener.
-
notifyListeners
protected void notifyListeners(ChangeEvent ce)
Notify the listeners.
-
hasListeners
protected boolean hasListeners()
Check if the clock has listeners.
-
shutdown
public void shutdown(IResultListener listener)
Shutdown the service.- Parameters:
listener
- The listener.
-
-