Package jadex.platform.service.clock
Class ClockService
- java.lang.Object
-
- jadex.bridge.service.BasicService
-
- jadex.platform.service.clock.ClockService
-
- All Implemented Interfaces:
IInternalService,IService,IClockService
public class ClockService extends BasicService implements IClockService
A clock service abstracts away from clock implementations. The clock service is meant to be kept constant during runtime.
-
-
Field Summary
Fields Modifier and Type Field Description protected static IClockbisimclockShared clock for bisimulation, if any.protected ClockCreationInfocinfoThe clock type.protected IClockclockThe clock.protected IInternalAccesscomponentThe component.protected java.util.List<IChangeListener>listenersThe clock listeners.protected IThreadPoolServicethreadpoolThe threadpool.protected java.util.TimertimerThe realtime timer.-
Fields inherited from class jadex.bridge.service.BasicService
idcnt, impltype, internalaccess, providerid, shutdowned, sid, started, type
-
Fields inherited from interface jadex.bridge.service.types.clock.IClockService
BISIMULATION_CLOCK_FLAG, SIMULATION_CLOCK_FLAG, TYPE
-
Fields inherited from interface jadex.bridge.service.IService
EMPTY_SERVICES
-
-
Constructor Summary
Constructors Constructor Description ClockService(ClockCreationInfo cinfo, IInternalAccess component)Create a new clock service.ClockService(ClockCreationInfo cinfo, IInternalAccess component, java.util.Map properties)Create a new clock service.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddChangeListener(IChangeListener listener)Add a change listener.booleanadvanceEvent()Advance one event.protected static IClockcreateClock(ClockCreationInfo cinfo, IThreadPool tp)Create a clock based on creation info.java.util.TimerTaskcreateRealtimeTimer(long time, ITimedObject to)Create a new realtime timer.ITimercreateTickTimer(ITimedObject to)Create a new tick timer.ITimercreateTimer(long time, ITimedObject to)Create a new timer.java.lang.StringgetClockType()Get the clock type.longgetDelta()Get the clock delta.doublegetDilation()Get the clocks dilation.ITimergetNextTimer()Get the next timer.longgetStarttime()Get the clocks start time.java.lang.StringgetState()Get the clock state.doublegetTick()Get the current tick.longgetTime()Get the current time.ITimer[]getTimers()Get all active timers.voidremoveChangeListener(IChangeListener listener)Remove a change listener.voidsetClock(ClockCreationInfo cinfo, IThreadPool tp)Create and set a new clock.voidsetClock(java.lang.String type, IThreadPool tp)Change the clock.voidsetDelta(long delta)Set the clock delta.voidsetDilation(double dilation)Set the clocks dilation.voidsetTime(long time)Set the current time.IFuture<java.lang.Void>shutdownService()Shutdown the service.voidstart()Start the clock.IFuture<java.lang.Void>startService()Start the service.voidstop()Stop the clock.-
Methods inherited from class jadex.bridge.service.BasicService
createServiceIdentifier, createServiceIdentifier, equals, generateServiceName, getInterfaceType, getInternalAccess, getInvokeMethod, getMethodInfos, getMethodTimeout, getPropertyMap, getProviderId, getServiceId, hashCode, initNFProperties, invokeMethod, isValid, setComponentAccess, setPropertyMap, setServiceIdentifier, toString
-
-
-
-
Field Detail
-
bisimclock
protected static volatile IClock bisimclock
Shared clock for bisimulation, if any.
-
clock
protected IClock clock
The clock.
-
threadpool
protected IThreadPoolService threadpool
The threadpool.
-
listeners
protected java.util.List<IChangeListener> listeners
The clock listeners.
-
component
protected IInternalAccess component
The component.
-
cinfo
protected ClockCreationInfo cinfo
The clock type.
-
timer
protected java.util.Timer timer
The realtime timer.
-
-
Constructor Detail
-
ClockService
public ClockService(ClockCreationInfo cinfo, IInternalAccess component)
Create a new clock service.
-
ClockService
public ClockService(ClockCreationInfo cinfo, IInternalAccess component, java.util.Map properties)
Create a new clock service.
-
-
Method Detail
-
getTime
public long getTime()
Get the current time.- Specified by:
getTimein interfaceIClockService- Returns:
- The current time.
-
setTime
public void setTime(long time)
Set the current time.- Parameters:
time- The current time.
-
getTick
public double getTick()
Get the current tick.- Specified by:
getTickin interfaceIClockService- Returns:
- The current tick.
-
getStarttime
public long getStarttime()
Get the clocks start time.- Specified by:
getStarttimein interfaceIClockService- Returns:
- The start time.
-
getDelta
public long getDelta()
Get the clock delta.- Specified by:
getDeltain interfaceIClockService- Returns:
- The clock delta.
-
setDelta
public void setDelta(long delta)
Set the clock delta. param delta The new clock delta.- Specified by:
setDeltain interfaceIClockService- Parameters:
delta- The new clock delta.
-
getState
public java.lang.String getState()
Get the clock state.- Specified by:
getStatein interfaceIClockService- Returns:
- The clock state.
-
getDilation
public double getDilation()
Get the clocks dilation.- Specified by:
getDilationin interfaceIClockService- Returns:
- The clocks dilation. // Hack!!! only for continuous clock.
-
setDilation
public void setDilation(double dilation)
Set the clocks dilation.- Specified by:
setDilationin interfaceIClockService- Parameters:
dilation- The clocks dilation. // Hack. Remove? only for continuous
-
getClockType
public java.lang.String getClockType()
Get the clock type.- Specified by:
getClockTypein interfaceIClockService- Returns:
- The clock type.
-
createTimer
public ITimer createTimer(long time, ITimedObject to)
Create a new timer. The unit of the timespan value depends on the clock implementation. For system clocks, the time value should adhere to the time representation as used bySystem.currentTimeMillis().- Specified by:
createTimerin interfaceIClockService- Parameters:
timespan- The relative timespan after which the timed object should be notified.to- The timed object.
-
createTickTimer
public ITimer createTickTimer(ITimedObject to)
Create a new tick timer. todo: @param tickcount The number of ticks.- Specified by:
createTickTimerin interfaceIClockService- Parameters:
to- The timed object.
-
createRealtimeTimer
public java.util.TimerTask createRealtimeTimer(long time, ITimedObject to)Create a new realtime timer.- Specified by:
createRealtimeTimerin interfaceIClockService- Parameters:
timespan- The relative timespan after which the timed object should be notified.to- The timed object.
-
getNextTimer
public ITimer getNextTimer()
Get the next timer.- Specified by:
getNextTimerin interfaceIClockService- Returns:
- The next timer.
-
getTimers
public ITimer[] getTimers()
Get all active timers.- Specified by:
getTimersin interfaceIClockService- Returns:
- The active timers.
-
addChangeListener
public void addChangeListener(IChangeListener listener)
Add a change listener.- Specified by:
addChangeListenerin interfaceIClockService- Parameters:
listener- The change listener.
-
removeChangeListener
public void removeChangeListener(IChangeListener listener)
Remove a change listener.- Specified by:
removeChangeListenerin interfaceIClockService- Parameters:
listener- The change listener.
-
advanceEvent
public boolean advanceEvent()
Advance one event.- Specified by:
advanceEventin interfaceIClockService- Returns:
- True, if clock could be advanced.
-
start
public void start()
Start the clock.- Specified by:
startin interfaceIClockService
-
stop
public void stop()
Stop the clock.- Specified by:
stopin interfaceIClockService
-
startService
public IFuture<java.lang.Void> startService()
Start the service.- Specified by:
startServicein interfaceIInternalService- Overrides:
startServicein classBasicService- Returns:
- A future that is done when the service has completed starting.
-
shutdownService
public IFuture<java.lang.Void> shutdownService()
Shutdown the service.- Specified by:
shutdownServicein interfaceIInternalService- Overrides:
shutdownServicein classBasicService- Parameters:
listener- The listener.- Returns:
- A future that is done when the service has completed its shutdown.
-
setClock
public void setClock(java.lang.String type, IThreadPool tp)Change the clock.- Specified by:
setClockin interfaceIClockService- Parameters:
type- The new clock type
-
setClock
public void setClock(ClockCreationInfo cinfo, IThreadPool tp)
Create and set a new clock.
-
createClock
protected static IClock createClock(ClockCreationInfo cinfo, IThreadPool tp)
Create a clock based on creation info.
-
-