All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.xiaomi.infra.galaxy.rpc.util.clock.AdjustableClock Maven / Gradle / Ivy

There is a newer version: 1.3.2
Show newest version
package com.xiaomi.infra.galaxy.rpc.util.clock;

public class AdjustableClock implements Adjustable, Clock {
  private Clock localClock;
  private volatile long offset = 0;

  public AdjustableClock(Clock clock) {
    localClock = clock;
  }

  public AdjustableClock() {
    this(new LocalClock());
  }

  @Override
  public long getCurrentEpoch() {
    return localClock.getCurrentEpoch() + offset;
  }

  @Override
  public void adjust(long currentEpoch) {
    long localEpoch = localClock.getCurrentEpoch();
    offset = currentEpoch - localEpoch;
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy