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

com.netflix.astyanax.clock.MicrosecondsAsyncClock Maven / Gradle / Ivy

There is a newer version: 3.10.2
Show newest version
package com.netflix.astyanax.clock;

import java.util.concurrent.atomic.AtomicInteger;

import com.netflix.astyanax.Clock;

public class MicrosecondsAsyncClock implements Clock {

    private static final long serialVersionUID = -4671061000963496156L;
    private static final long ONE_THOUSAND = 1000L;

    private static AtomicInteger counter = new AtomicInteger(0);

    public MicrosecondsAsyncClock() {

    }

    @Override
    public long getCurrentTime() {
        // The following simulates a microseconds resolution by advancing a
        // static counter
        // every time a client calls the createClock method, simulating a tick.
        long us = System.currentTimeMillis() * ONE_THOUSAND;
        return us + counter.getAndIncrement() % ONE_THOUSAND;
    }

    public String toString() {
        return "MicrosecondsAsyncClock";
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy