org.powertac.common
Class TimeService

java.lang.Object
  extended by org.powertac.common.TimeService

@Scope(value="singleton")
@Service
public class TimeService
extends Object

This is the simulation time-keeper and event queue. Here's how it works:

Note that all times are absolute times represented as UTC; timezone offset is 0, and there is no "daylight-saving" time. If we want to represent the effects of DST, we'll have to have our customers wake up earlier in the summertime.

Author:
John Collins

Field Summary
static long DAY
           
static long HOUR
           
static long MINUTE
           
static long SECOND
           
static long WEEK
           
 
Constructor Summary
TimeService()
          Default constructor.
TimeService(long base, long start, long rate, long modulo)
          Handy constructor for testing
 
Method Summary
 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
 long getModulo()
           
 long getRate()
           
 long getStart()
           
 void init()
          Sets current time to modulo before base time.
 void setBase(long value)
          Deprecated. use setClockParameters instead
 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.
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 instead
 void setRate(long value)
          Deprecated. use setClockParameters 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SECOND

public static final long SECOND
See Also:
Constant Field Values

MINUTE

public static final long MINUTE
See Also:
Constant Field Values

HOUR

public static final long HOUR
See Also:
Constant Field Values

DAY

public static final long DAY
See Also:
Constant Field Values

WEEK

public static final long WEEK
See Also:
Constant Field Values
Constructor Detail

TimeService

public TimeService()
Default constructor. You need to set base, rate, start, and modulo before using it.


TimeService

public TimeService(long base,
                   long start,
                   long rate,
                   long modulo)
Handy constructor for testing

Method Detail

init

public void init()
Sets current time to modulo before base time. This allows scheduling of actions to take place on the first tick, which should be at the base time. Call this after setting clock parameters.


updateTime

public void updateTime()
Updates simulation time when called as specified by clock parameters, then runs any actions that may be due.


truncateInstant

public org.joda.time.Instant truncateInstant(org.joda.time.Instant time,
                                             long mod)
Returns the most recent Instant at which time % modulo was zero


setClockParameters

public void setClockParameters(long base,
                               long rate,
                               long modulo)
Sets base, rate, and modulo clock parameters with a single call. We do not set start at this point, because it is changed whenever the clock is paused and therefore needs to be treated separately.


setClockParameters

public 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. The map must contain entries named "base", "rate", and "modulo". We also init the clock here, because we have all the parameters.


getBase

public long getBase()

getBaseInstant

public org.joda.time.Instant getBaseInstant()

setBase

@Deprecated
public void setBase(long value)
Deprecated. use setClockParameters instead


getStart

public long getStart()

setStart

public void setStart(long start)

getRate

public long getRate()

setRate

@Deprecated
public void setRate(long value)
Deprecated. use setClockParameters instead


getModulo

public long getModulo()

setModulo

@Deprecated
public void setModulo(long value)
Deprecated. use setClockParameters instead


getCurrentTime

public org.joda.time.Instant getCurrentTime()
Returns the current time as an Instant


getCurrentDateTime

public org.joda.time.DateTime getCurrentDateTime()

getHourOfDay

public int getHourOfDay()
Returns the current hour-of-day


setCurrentTime

public void setCurrentTime(org.joda.time.Instant time)
Sets current time to a specific value. Intended for testing purposes only.


setCurrentTime

protected void setCurrentTime(org.joda.time.base.AbstractDateTime time)
Sets current time to a specific value. Intended for testing purposes only.


addAction

public void addAction(org.joda.time.Instant time,
                      TimedAction act)
Adds an action to the simulation queue, to be triggered at the specified time.



Copyright © 2012. All Rights Reserved.