public final class SimulationClock extends WaitableClock
WaitableClock
als simulierte Uhr, die einen
beliebigen Startzeitpunkt hat und auch schneller oder langsamer gehen kann,
als die reale Systemzeit.Modifier and Type | Field and Description |
---|---|
private double |
_simulationSpeed |
private Instant |
_startRealTime |
private Instant |
_startSimulation |
private ZoneId |
_zone |
Modifier | Constructor and Description |
---|---|
|
SimulationClock(Instant startState,
double simulationSpeed)
Erstellt eine neue SimulationClock
|
private |
SimulationClock(Instant startSimulation,
double simulationSpeed,
ZoneId zone,
Instant startRealTime)
Interner Hilfskonstruktor für die
withZone(ZoneId) -Methode. |
Modifier and Type | Method and Description |
---|---|
ZoneId |
getZone() |
Instant |
instant() |
void |
setInstant(Instant start)
Verstellt den aktuellen Zeitpunkt.
|
void |
sleep(long millis)
Tut das gleiche wie
Thread.sleep(long) , verwendet aber diese Uhr um die Wartezeit zu bestimmen. |
Duration |
wait(Object obj,
long millis)
Tut das gleiche wie obj.
|
Clock |
withZone(ZoneId zone) |
durationUntil, simulationClock, sleep, sleepUntil, systemClock, wait, waitUntil
equals, fixed, hashCode, millis, offset, system, systemDefaultZone, systemUTC, tick, tickMinutes, tickSeconds
private final double _simulationSpeed
private final ZoneId _zone
private Instant _startSimulation
private Instant _startRealTime
public SimulationClock(Instant startState, double simulationSpeed)
startState
- Startzeitpunkt der UhrsimulationSpeed
- Simulationsgeschwindigkeit (1 = reale Geschwindigkeit, 10 =
die Uhr geht 10 mal schneller, als die reale Zeit, usw.)private SimulationClock(Instant startSimulation, double simulationSpeed, ZoneId zone, Instant startRealTime)
withZone(ZoneId)
-Methode.startSimulation
- der Startzeitpunkt der SimulationsimulationSpeed
- die Simulationsgeschwindigkeitzone
- die Id der ZeitzonestartRealTime
- der Startzeitpunkt in Realzeitpublic void setInstant(Instant start)
start
- Neue aktuelle Uhrzeit.public void sleep(long millis) throws InterruptedException
WaitableClock
Thread.sleep(long)
, verwendet aber diese Uhr um die Wartezeit zu bestimmen. Wenn diese Uhr beispielsweise
um Faktor 10 beschleunigt läuft, dann verringert sich die reale Wartezeit um Faktor 10.sleep
in class WaitableClock
millis
- Millisekunden, fall 0 oder negativ wird nicht gewartet.InterruptedException
public Duration wait(Object obj, long millis) throws InterruptedException
WaitableClock
Object.wait(long)
, verwendet aber diese Uhr um die Wartezeit zu bestimmen. Wenn diese Uhr beispielsweise
um Faktor 10 beschleunigt läuft, dann verringert sich die reale Wartezeit um Faktor 10. Im Gegensatz zu WaitableClock.sleep(Duration)
kann
das Warten mit Object.notifyAll()
unterbrochen werden und es muss auf das Objekt synchronisiert werden.wait
in class WaitableClock
obj
- Objekt, für das Object.wait(long)
aufgerufen werden sollmillis
- Millisekunden, fall 0 oder negativ wird nicht gewartet.InterruptedException
Copyright © 2017 BitCtrl Systems GmbH. All rights reserved.