@Test public void testInitialState() { long startTime = getCurrentTimeNanos(); BucketId bucketId = new MinuteBucketIdProvider(ticker).get(); assertEquals(bucketId.getId(), 0); assertGreaterThanOrEqual(bucketId.getTimestamp(), startTime); assertLessThanOrEqual(bucketId.getTimestamp(), getCurrentTimeNanos()); ticker.elapseTime(27, TimeUnit.HOURS); ticker.elapseTime(977_777, TimeUnit.NANOSECONDS); startTime = getCurrentTimeNanos(); bucketId = new MinuteBucketIdProvider(ticker).get(); assertEquals(bucketId.getId(), 0); assertGreaterThanOrEqual(bucketId.getTimestamp(), startTime); assertLessThanOrEqual(bucketId.getTimestamp(), getCurrentTimeNanos()); }
@Override public BucketId get() { long nanosSinceInitial = ticker.read() - initialValue; int id = (int) (nanosSinceInitial / ONE_MINUTE_IN_NANOS); long nanosSinceBoundary = nanosSinceInitial % ONE_MINUTE_IN_NANOS; long timeAtBoundary = TimeUnit.MILLISECONDS.toNanos(currentTimeMillis()) - nanosSinceBoundary; return bucketId(id, timeAtBoundary); }
MinuteBucketIdProvider implements BucketIdProvider { @Override public BucketId get() { long nanosSinceInitial = ticker.read() - initialValue; int id = (int) (nanosSinceInitial / ONE_MINUTE_IN_NANOS); long nanosSinceBoundary = nanosSinceInitial % ONE_MINUTE_IN_NANOS; long timeAtBoundary = TimeUnit.MILLISECONDS.toNanos(currentTimeMillis()) - nanosSinceBoundary; return bucketId(id, timeAtBoundary); } }
MinuteBucketIdProvider implements BucketIdProvider { @Override public BucketId get() { long nanosSinceInitial = ticker.read() - initialValue; int id = (int) (nanosSinceInitial / ONE_MINUTE_IN_NANOS); long nanosSinceBoundary = nanosSinceInitial % ONE_MINUTE_IN_NANOS; long timeAtBoundary = TimeUnit.MILLISECONDS.toNanos(currentTimeMillis()) - nanosSinceBoundary; return bucketId(id, timeAtBoundary); } @Inject  MinuteBucketIdProvider();  MinuteBucketIdProvider(Ticker ticker); }
MinuteBucketIdProvider implements BucketIdProvider { @Override public BucketId get() { long nanosSinceInitial = ticker.read() - initialValue; int id = (int) (nanosSinceInitial / ONE_MINUTE_IN_NANOS); long nanosSinceBoundary = nanosSinceInitial % ONE_MINUTE_IN_NANOS; long timeAtBoundary = TimeUnit.MILLISECONDS.toNanos(currentTimeMillis()) - nanosSinceBoundary; return bucketId(id, timeAtBoundary); } @Inject  MinuteBucketIdProvider();  MinuteBucketIdProvider(Ticker ticker); @Override BucketId get(); long getLastSystemTimeMillis(); }
MinuteBucketIdProvider implements BucketIdProvider { @Override public BucketId get() { long nanosSinceInitial = ticker.read() - initialValue; int id = (int) (nanosSinceInitial / ONE_MINUTE_IN_NANOS); long nanosSinceBoundary = nanosSinceInitial % ONE_MINUTE_IN_NANOS; long timeAtBoundary = TimeUnit.MILLISECONDS.toNanos(currentTimeMillis()) - nanosSinceBoundary; return bucketId(id, timeAtBoundary); } @Inject  MinuteBucketIdProvider();  MinuteBucketIdProvider(Ticker ticker); @Override BucketId get(); long getLastSystemTimeMillis();  }