com.backblaze.b2.util.B2ClockImpl Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of b2-sdk-core Show documentation
Show all versions of b2-sdk-core Show documentation
The core logic for B2 SDK for Java. Does not include any implementations of B2WebApiClient.
/*
* Copyright 2017, Backblaze Inc. All Rights Reserved.
* License https://www.backblaze.com/using_b2_code.html
*/
package com.backblaze.b2.util;
import static com.backblaze.b2.util.B2DateTimeUtil.ONE_MILLI_IN_NANOS;
/**
* B2ClockImpl uses values from the System class to provide a "real"
* implementation of B2Clock whose clocks are determined by the system.
*/
public class B2ClockImpl extends B2Clock {
/**
* 'monoNanoBase is the first nanoTime we get from the system.
* We use it as a baseline to avoid wrapping the monoNanoTime
* we return.
*/
private final long monoNanoBase;
public B2ClockImpl() {
monoNanoBase = System.nanoTime();
}
@Override
public long monotonicMillis() {
// subtraction gets the right value even if nanoTime() has wrapped past Long.MAX_VALUE.
return (System.nanoTime() - monoNanoBase) / ONE_MILLI_IN_NANOS;
}
@Override
public long wallClockMillis() {
return System.currentTimeMillis();
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy