List of usage examples for org.joda.time Duration Duration
public Duration(ReadableInstant start, ReadableInstant end)
From source file:com.facebook.stats.AbstractCompositeCounter.java
License:Apache License
/** * Updates the current composite counter so that it is up to date with the * current timestamp./*from w w w.j a v a 2 s. c o m*/ * <p/> * This should be called by any method that needs to have the most updated * view of the current set of counters. */ protected synchronized void trimIfNeeded() { Duration delta = new Duration(start, new DateTime()).minus(maxLength); if (delta.isLongerThan(Duration.ZERO)) { start = start.toDateTime().plus(delta); if (start.isAfter(end)) { end = start; } Iterator<C> iter = eventCounters.iterator(); while (iter.hasNext()) { EventCounterIf<C> counter = iter.next(); // trim any counter with an end up to and including start since our composite counter is // [start, ... and each counter is [..., end) if (!start.isBefore(counter.getEnd())) { iter.remove(); } else { break; } } } }
From source file:com.facebook.stats.AssociativeAggregationCounter.java
License:Apache License
@Override public Duration getLength() { return new Duration(start, end); }
From source file:com.facebook.stats.DecayCounter.java
License:Apache License
/** * @return counter value after computing exponential decay of the counter * value//w w w . j av a 2 s . c o m */ @Override public long getValue() { DateTime now = getNow(); // don't start decay unless it's at least 1s after the decayStart if (now.isAfter(decayStart.toDateTime().plusSeconds(1))) { Duration elapsed = new Duration(decayStart, now); long millis = elapsed.getMillis(); // compute total decay for millis / 1000 seconds double thisDecay = Math.pow(1.0 - decayRatePerSecond, (double) (millis / (double) 1000)); return (long) (count.get() * thisDecay); } else { return count.get(); } }
From source file:com.facebook.stats.EventCounterImpl.java
License:Apache License
@Override public Duration getLength() { return new Duration(start, end); }
From source file:com.facebook.stats.EventRateImpl.java
License:Apache License
private Duration getPeriodSize() { // normalize by the time since server start ReadableDateTime now = new DateTime(); Duration periodSize = new Duration(start, now); if (periodSize.isLongerThan(windowSize)) { return windowSize; } else {/*from w ww . j ava2s . c om*/ return periodSize; } }
From source file:com.facebook.stats.MultiWindowGauge.java
License:Apache License
private long calcRate(EventCounterIf<GaugeCounter> counter) { long value = counter.getValue(); ReadableDateTime end = counter.getEnd(); ReadableDateTime start = counter.getStart(); ReadableDateTime now = new DateTime(); Duration duration = now.isBefore(end) ? new Duration(start, now) : // so far new Duration(start, end); long secs = duration.getStandardSeconds(); return secs > 0 ? value / secs : value; }
From source file:com.facebook.stats.MultiWindowGauge.java
License:Apache License
@Override public long getAllTimeRate() { Duration sinceStart = new Duration(start, new DateTime()); if (sinceStart.getStandardSeconds() == 0) { return 0; }/*from ww w . j a v a 2 s . c o m*/ return allTimeCounter.getValue() / sinceStart.getStandardSeconds(); }
From source file:com.facebook.stats.MultiWindowRate.java
License:Apache License
@Override public long getAllTimeRate() { Duration sinceStart = new Duration(start, getNow()); if (sinceStart.getStandardSeconds() == 0) { return 0; }/*from w w w. j av a 2 s.c o m*/ return allTimeCounter.getValue() / sinceStart.getStandardSeconds(); }
From source file:com.facebook.stats.mx.StatsUtil.java
License:Apache License
public static Duration extentOf(EventCounterIf counter1, EventCounterIf counter2) { ReadableDateTime start = counter1.getStart(); ReadableDateTime end = counter1.getEnd(); if (counter2.getStart().isBefore(start)) { start = counter2.getStart();/*ww w .j a v a 2s. co m*/ } if (counter2.getEnd().isAfter(end)) { end = counter2.getEnd(); } return new Duration(start, end); }
From source file:com.facebook.stats.mx.StatsUtil.java
License:Apache License
public static void main(String[] args) { DateTime start = new DateTime("2012-01-01T01:01:00.000Z"); DateTime end = new DateTime("2012-01-01T01:02:00.000Z"); Duration x = new Duration(start, end); System.err.println(x.getMillis()); }