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 longcurrenttimeThe current time (last measurement).static longDEFAULT_DELTAThe default delta (tick time).protected longdeltaThe clock tick delta (relative to base time).protected java.util.ListlistenersThe change listeners.protected java.lang.StringnameThe clock name.protected longstarttimeThe start time (model time).protected java.lang.StringstateThe clock state.protected TimerticktimerThe tick timer.protected java.util.ListticktimersThe tick timers.java.util.SortedSettimersThe 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 voidactivateTickTimer()Activate the tick timer.voidaddChangeListener(IChangeListener listener)Add a change listener.voidaddTickTimer(ITimer timer)Add a tick timer.voidaddTimer(ITimer timer)Add a timer.voidcopyFromClock(IClock oldclock)Transfer state from another clock to this clock.ITimercreateTickTimer(ITimedObject to)Create a new tick timer.ITimercreateTimer(long timespan, ITimedObject to)Create a new timer.voiddispose()Called, when the clock is no longer used.longgetDelta()Get the clock delta.java.lang.StringgetName()Get the current time.ITimergetNextTimer()Get the next timer.longgetStarttime()Get the clocks start time.java.lang.StringgetState()Get the clock state.doublegetTick()Get the current tick.ITimer[]getTickTimers()Get all active tick timers.longgetTime()Get the clocks name.ITimer[]getTimers()Get all active timers.protected booleanhasListeners()Check if the clock has listeners.protected voidnotifyListeners(ChangeEvent ce)Notify the listeners.voidremoveChangeListener(IChangeListener listener)Remove a change listener.voidremoveTickTimer(ITimer timer)Remove a tick timer.voidremoveTimer(ITimer timer)Remove a timer.voidreset()Reset the clock.voidsetDelta(long delta)Set the clock delta.voidsetStarttime(long starttime)Set the clocks start time.voidshutdown(IResultListener listener)Shutdown the service.voidstart()Start the clock.voidstop()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:
getStarttimein interfaceIClock- Returns:
- The start time.
-
setStarttime
public void setStarttime(long starttime)
Set the clocks start time.- Specified by:
setStarttimein 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:
getNextTimerin 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:
createTimerin interfaceIClock- Parameters:
timespan- The timespan.to- The timed object.
-
createTickTimer
public ITimer createTickTimer(ITimedObject to)
Create a new tick timer.- Specified by:
createTickTimerin 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:
getTickTimersin 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:
removeTimerin interfaceIClock- Parameters:
timer- The timer.
-
addTickTimer
public void addTickTimer(ITimer timer)
Add a tick timer.- Specified by:
addTickTimerin 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:
removeTickTimerin interfaceIClock- Parameters:
timer- The timer.
-
addChangeListener
public void addChangeListener(IChangeListener listener)
Add a change listener.- Specified by:
addChangeListenerin interfaceIClock- Parameters:
listener- The change listener.
-
removeChangeListener
public void removeChangeListener(IChangeListener listener)
Remove a change listener.- Specified by:
removeChangeListenerin 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.
-
-