io.deephaven.engine.table.impl.replay.FixedStepReplayer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of deephaven-engine-table Show documentation
Show all versions of deephaven-engine-table Show documentation
Engine Table: Implementation and closely-coupled utilities
/**
* Copyright (c) 2016-2022 Deephaven Data Labs and Patent Pending
*/
package io.deephaven.engine.table.impl.replay;
import io.deephaven.base.clock.Clock;
import io.deephaven.base.clock.ClockNanoBase;
import io.deephaven.time.DateTimeUtils;
import java.time.Instant;
public class FixedStepReplayer extends Replayer {
private long incrementNanos;
private Instant currentTime;
public FixedStepReplayer(Instant startTime, Instant endTime, long incrementNanos) {
super(startTime, endTime);
this.incrementNanos = incrementNanos;
currentTime = startTime;
}
@Override
public void run() {
currentTime = DateTimeUtils.plus(currentTime, incrementNanos);
if (DateTimeUtils.epochNanos(currentTime) > DateTimeUtils.epochNanos(endTime)) {
currentTime = endTime;
}
super.run();
}
@Override
public void setTime(long updatedTime) {
currentTime = DateTimeUtils.epochMillisToInstant(Math.max(updatedTime, currentTime.toEpochMilli()));
}
@Override
public Clock clock() {
return new ClockImpl();
}
private class ClockImpl extends ClockNanoBase {
@Override
public long currentTimeNanos() {
return DateTimeUtils.epochNanos(currentTime);
}
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy