private void rollCount(long now) { final long stepTime = now / step; final long lastInit = lastInitPos.get(); if (lastInit < stepTime && lastInitPos.compareAndSet(lastInit, stepTime)) { final double v = current.getAndSet(init); // Need to check if there was any activity during the previous step interval. If there was // then the init position will move forward by 1, otherwise it will be older. No activity // means the previous interval should be set to the `init` value. previous = (lastInit == stepTime - 1) ? v : init; } }
private void rollCount(long now) { final long stepTime = now / step; final long lastInit = lastInitPos.get(); if (lastInit < stepTime && lastInitPos.compareAndSet(lastInit, stepTime)) { final double v = current.getAndSet(init); // Need to check if there was any activity during the previous step interval. If there was // then the init position will move forward by 1, otherwise it will be older. No activity // means the previous interval should be set to the `init` value. previous = (lastInit == stepTime - 1) ? v : init; } }
@Override public Iterable<Measurement> measure() { final double delta = count.getAndSet(0.0); if (delta > 0.0) { final Measurement m = new Measurement(stat, clock.wallTime(), delta); return Collections.singletonList(m); } else { return Collections.emptyList(); } }
@Override public Iterable<Measurement> measure() { final double delta = value.getAndSet(0.0); if (delta > 0.0) { final Measurement m = new Measurement(stat, clock.wallTime(), delta); return Collections.singletonList(m); } else { return Collections.emptyList(); } } }
@Override public Iterable<Measurement> measure() { final double delta = value.getAndSet(Double.NaN); if (Double.isNaN(delta)) { return Collections.emptyList(); } else { final Measurement m = new Measurement(stat, clock.wallTime(), delta); return Collections.singletonList(m); } } }
@Override public Iterable<Measurement> measure() { final double delta = value.getAndSet(Double.NaN); if (Double.isNaN(delta)) { return Collections.emptyList(); } else { final Measurement m = new Measurement(stat, clock.wallTime(), delta); return Collections.singletonList(m); } } }
@Override public Iterable<Measurement> measure() { final double delta = count.getAndSet(0.0); if (delta > 0.0) { final Measurement m = new Measurement(stat, clock.wallTime(), delta); return Collections.singletonList(m); } else { return Collections.emptyList(); } }
@Override public Iterable<Measurement> measure() { final double delta = value.getAndSet(0.0); if (delta > 0.0) { final Measurement m = new Measurement(stat, clock.wallTime(), delta); return Collections.singletonList(m); } else { return Collections.emptyList(); } } }
@Override public Iterable<Measurement> measure() { Measurement m = new Measurement(id, clock.wallTime(), value.getAndSet(0L)); return Collections.singletonList(m); }
@Test public void getAndSet() { AtomicDouble v = new AtomicDouble(13.0); Assertions.assertEquals(13.0, v.getAndSet(42.0), 1e-12); Assertions.assertEquals(42.0, v.get(), 1e-12); }