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 IClock
bisimclock
Shared clock for bisimulation, if any.protected ClockCreationInfo
cinfo
The clock type.protected IClock
clock
The clock.protected IInternalAccess
component
The component.protected java.util.List<IChangeListener>
listeners
The clock listeners.protected IThreadPoolService
threadpool
The threadpool.protected java.util.Timer
timer
The 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 void
addChangeListener(IChangeListener listener)
Add a change listener.boolean
advanceEvent()
Advance one event.protected static IClock
createClock(ClockCreationInfo cinfo, IThreadPool tp)
Create a clock based on creation info.java.util.TimerTask
createRealtimeTimer(long time, ITimedObject to)
Create a new realtime timer.ITimer
createTickTimer(ITimedObject to)
Create a new tick timer.ITimer
createTimer(long time, ITimedObject to)
Create a new timer.java.lang.String
getClockType()
Get the clock type.long
getDelta()
Get the clock delta.double
getDilation()
Get the clocks dilation.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.long
getTime()
Get the current time.ITimer[]
getTimers()
Get all active timers.void
removeChangeListener(IChangeListener listener)
Remove a change listener.void
setClock(ClockCreationInfo cinfo, IThreadPool tp)
Create and set a new clock.void
setClock(java.lang.String type, IThreadPool tp)
Change the clock.void
setDelta(long delta)
Set the clock delta.void
setDilation(double dilation)
Set the clocks dilation.void
setTime(long time)
Set the current time.IFuture<java.lang.Void>
shutdownService()
Shutdown the service.void
start()
Start the clock.IFuture<java.lang.Void>
startService()
Start the service.void
stop()
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:
getTime
in 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:
getTick
in interfaceIClockService
- Returns:
- The current tick.
-
getStarttime
public long getStarttime()
Get the clocks start time.- Specified by:
getStarttime
in interfaceIClockService
- Returns:
- The start time.
-
getDelta
public long getDelta()
Get the clock delta.- Specified by:
getDelta
in interfaceIClockService
- Returns:
- The clock delta.
-
setDelta
public void setDelta(long delta)
Set the clock delta. param delta The new clock delta.- Specified by:
setDelta
in interfaceIClockService
- Parameters:
delta
- The new clock delta.
-
getState
public java.lang.String getState()
Get the clock state.- Specified by:
getState
in interfaceIClockService
- Returns:
- The clock state.
-
getDilation
public double getDilation()
Get the clocks dilation.- Specified by:
getDilation
in interfaceIClockService
- Returns:
- The clocks dilation. // Hack!!! only for continuous clock.
-
setDilation
public void setDilation(double dilation)
Set the clocks dilation.- Specified by:
setDilation
in interfaceIClockService
- Parameters:
dilation
- The clocks dilation. // Hack. Remove? only for continuous
-
getClockType
public java.lang.String getClockType()
Get the clock type.- Specified by:
getClockType
in 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:
createTimer
in 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:
createTickTimer
in interfaceIClockService
- Parameters:
to
- The timed object.
-
createRealtimeTimer
public java.util.TimerTask createRealtimeTimer(long time, ITimedObject to)
Create a new realtime timer.- Specified by:
createRealtimeTimer
in 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:
getNextTimer
in interfaceIClockService
- Returns:
- The next timer.
-
getTimers
public ITimer[] getTimers()
Get all active timers.- Specified by:
getTimers
in interfaceIClockService
- Returns:
- The active timers.
-
addChangeListener
public void addChangeListener(IChangeListener listener)
Add a change listener.- Specified by:
addChangeListener
in interfaceIClockService
- Parameters:
listener
- The change listener.
-
removeChangeListener
public void removeChangeListener(IChangeListener listener)
Remove a change listener.- Specified by:
removeChangeListener
in interfaceIClockService
- Parameters:
listener
- The change listener.
-
advanceEvent
public boolean advanceEvent()
Advance one event.- Specified by:
advanceEvent
in interfaceIClockService
- Returns:
- True, if clock could be advanced.
-
start
public void start()
Start the clock.- Specified by:
start
in interfaceIClockService
-
stop
public void stop()
Stop the clock.- Specified by:
stop
in interfaceIClockService
-
startService
public IFuture<java.lang.Void> startService()
Start the service.- Specified by:
startService
in interfaceIInternalService
- Overrides:
startService
in 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:
shutdownService
in interfaceIInternalService
- Overrides:
shutdownService
in 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:
setClock
in 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.
-
-