@Scope(value="singleton") @Service public class TimeService extends Object
currentTime = base + (systemTime - start) * rate
Modifier and Type | Field and Description |
---|---|
static long |
DAY |
static long |
HOUR |
static long |
MINUTE |
static long |
SECOND |
static long |
WEEK |
Constructor and Description |
---|
TimeService()
Default constructor.
|
TimeService(long base,
long start,
long rate,
long modulo)
Handy constructor for testing
|
Modifier and Type | Method and Description |
---|---|
void |
addAction(org.joda.time.Instant time,
TimedAction act)
Adds an action to the simulation queue, to be triggered at the specified time.
|
long |
getBase() |
org.joda.time.Instant |
getBaseInstant() |
org.joda.time.DateTime |
getCurrentDateTime() |
org.joda.time.Instant |
getCurrentTime()
Returns the current time as an Instant
|
int |
getHourOfDay()
Returns the current hour-of-day
|
static TimeService |
getInstance()
Returns the most-recently created instance of TimeService.
|
long |
getModulo() |
long |
getOffset()
Computes and returns the offset in msec between the current system time
and the current clock time.
|
long |
getRate() |
long |
getStart() |
void |
init(org.joda.time.Instant start)
Sets current time to modulo before the desired start time.
|
void |
setBase(long value)
Deprecated.
use
setClockParameters(long, long, long) instead |
void |
setClockParameters(Competition comp)
Sets base, rate, and modulo from a Competition instance
|
void |
setClockParameters(long base,
long rate,
long modulo)
Sets base, rate, and modulo clock parameters with a single call.
|
void |
setClockParameters(Map<String,Long> params)
Sets base, rate, and modulo parameters from a map, which is wrapped
in a Configuration to allow for conversions and default values.
|
void |
setCurrentTime() |
protected void |
setCurrentTime(org.joda.time.base.AbstractDateTime time)
Sets current time to a specific value.
|
void |
setCurrentTime(org.joda.time.Instant time)
Sets current time to a specific value.
|
void |
setModulo(long value)
Deprecated.
use
setClockParameters(long, long, long) instead |
void |
setRate(long value)
Deprecated.
use
setClockParameters(long, long, long) instead |
void |
setStart(long start) |
org.joda.time.Instant |
truncateInstant(org.joda.time.Instant time,
long mod)
Returns the most recent Instant at which time % modulo was zero
|
void |
updateTime()
Updates simulation time when called as specified by clock
parameters, then runs any actions that may be due.
|
public static final long SECOND
public static final long MINUTE
public static final long HOUR
public static final long DAY
public static final long WEEK
public TimeService()
public TimeService(long base, long start, long rate, long modulo)
public static TimeService getInstance()
public void init(org.joda.time.Instant start)
public void updateTime()
public org.joda.time.Instant truncateInstant(org.joda.time.Instant time, long mod)
public void setClockParameters(long base, long rate, long modulo)
public void setClockParameters(Map<String,Long> params)
public void setClockParameters(Competition comp)
public long getBase()
public org.joda.time.Instant getBaseInstant()
@Deprecated public void setBase(long value)
setClockParameters(long, long, long)
insteadpublic long getStart()
public void setStart(long start)
public long getRate()
@Deprecated public void setRate(long value)
setClockParameters(long, long, long)
insteadpublic long getModulo()
@Deprecated public void setModulo(long value)
setClockParameters(long, long, long)
insteadpublic org.joda.time.Instant getCurrentTime()
public org.joda.time.DateTime getCurrentDateTime()
public int getHourOfDay()
@StateChange public void setCurrentTime(org.joda.time.Instant time)
public long getOffset()
@StateChange protected void setCurrentTime(org.joda.time.base.AbstractDateTime time)
public void setCurrentTime()
public void addAction(org.joda.time.Instant time, TimedAction act)
Copyright © 2019 Power TAC. All rights reserved.