public class BasicClock extends java.lang.Object implements IClock, ISetableClock
Modifier and Type | Class and Description |
---|---|
static interface |
BasicClock.IClockWaiter
a closure interface that is used in #await(IClockWaiter, log) to specify
when the await should be retured from
|
class |
BasicClock.WaitFor
default impl of IClockWaiter that allows you to specify an exit time
|
Modifier and Type | Field and Description |
---|---|
protected java.util.concurrent.locks.Lock |
_lock |
protected java.util.concurrent.locks.Condition |
_timeChangeCondition |
Constructor and Description |
---|
BasicClock() |
Modifier and Type | Method and Description |
---|---|
double |
await(BasicClock.IClockWaiter waiter,
double targetTime,
long maxWait)
wait on the signal..
|
static double |
constrainPrecision(double time)
constrain our precision.
|
protected BasicClock.WaitFor |
createWaitForAny() |
protected BasicClock.WaitFor |
createWaitForTime() |
protected long |
getDefaultWaitTime() |
double |
getTime() |
double |
getTimeShift() |
static double |
getTimeSlipTolerance() |
protected BasicClock.WaitFor |
getWaitForAny() |
protected BasicClock.WaitFor |
getWaitForTime() |
boolean |
isIgnoringDiscrepencies()
are we temporarily ignoring time discrepencies - useful for the clock
owners when a simulation is reset
|
protected boolean |
requestTime(double requestedTime)
within the waitForTime() or waitForChange(), when the thread should block,
this is called before the actual block, allowing extenders to send out
requests for time updates, if necessary.
|
protected void |
setDefaultWaitTime(long waitTime) |
void |
setIgnoreDiscrepencies(boolean ignore) |
double |
setTime(double requestedTime)
set the time and signal (this is shifted time)
|
protected double |
setTimeInternal(double requestedTime)
actually set the time
|
void |
setTimeShift(double shift)
sets a constant for the clock to be adjusted by.
|
void |
setTimeSlipTolerance(double tolerance)
how much can the desired time differ from the target time before a warning
is issued.
|
double |
waitForChange()
wait for any change of time
|
double |
waitForTime(double time)
wait for this time to be reached, returning the current time
|
protected java.util.concurrent.locks.Lock _lock
protected java.util.concurrent.locks.Condition _timeChangeCondition
public static double getTimeSlipTolerance()
public void setTimeSlipTolerance(double tolerance)
tolerance
- protected long getDefaultWaitTime()
protected void setDefaultWaitTime(long waitTime)
protected BasicClock.WaitFor createWaitForTime()
protected BasicClock.WaitFor createWaitForAny()
protected BasicClock.WaitFor getWaitForAny()
protected BasicClock.WaitFor getWaitForTime()
public double getTime()
getTime
in interface IClock
IClock.getTime()
public boolean isIgnoringDiscrepencies()
public void setIgnoreDiscrepencies(boolean ignore)
public double waitForChange() throws java.lang.InterruptedException
IClock
waitForChange
in interface IClock
java.lang.InterruptedException
IClock.waitForChange()
public double waitForTime(double time) throws java.lang.InterruptedException
IClock
waitForTime
in interface IClock
java.lang.InterruptedException
IClock.waitForTime(double)
public double await(BasicClock.IClockWaiter waiter, double targetTime, long maxWait) throws java.lang.InterruptedException
maxWait
- ms to wait (0 to wait indef)java.lang.InterruptedException
public static double constrainPrecision(double time)
time
- public double setTime(double requestedTime)
setTime
in interface ISetableClock
time
- protected boolean requestTime(double requestedTime) throws java.lang.InterruptedException
requestedTime
- NaN if waitForChange was calledjava.lang.InterruptedException
protected double setTimeInternal(double requestedTime)
requestedTime
- public double getTimeShift()
getTimeShift
in interface IClock
public void setTimeShift(double shift)
IClock
setTimeShift
in interface IClock