/** * Returns value at the tail of the queue * * @return Value at the tail of the queue */ public T peek() { if (depth() == 0) { return null; } return circularArray[getIndex(getCurrentIndex())].get(); }
/** * {@inheritDoc} */ public TimeStampedCounterValue getMostRecentSample() { return this.history.peek(); }
/** * Returns an array of the current elements in the queue. The order of * elements is in reverse order of the order items were added. * * @param type * @return An array containing the current elements in the queue. The first * element of the array is the tail of the queue and the last * element is the head of the queue */ public T[] toArray(T[] type) { System.getProperties(); if (type.length > maxSize) { throw new IllegalArgumentException("Size of array passed in cannot be greater than " + maxSize); } int curIndex = getCurrentIndex(); for (int k = 0; k < type.length; k++) { int index = getIndex(curIndex - k); type[k] = circularArray[index].get(); } return type; }
/** * Returns true if the queue is empty, otherwise false * * @return true if the queue is empty, false otherwise */ public boolean isEmtpy() { return depth() == 0; }
/** * {@inheritDoc} */ void recordSample() { final long sample; if (resetOnSample) { sample = getAndReset(); } else { sample = getValue(); } final long now = System.currentTimeMillis(); TimeStampedCounterValue timedSample = new TimeStampedCounterValue(now, sample); history.push(timedSample); }
/** * Constructor accepting a {@link SampledCounterConfig} * * @param config */ public SampledCounterImpl(SampledCounterConfig config) { super(config.getInitialValue()); this.intervalMillis = config.getIntervalSecs() * MILLIS_PER_SEC; this.history = new CircularLossyQueue<TimeStampedCounterValue>(config.getHistorySize()); this.resetOnSample = config.isResetOnSample(); this.samplerTask = new TimerTask() { @Override public void run() { recordSample(); } }; recordSample(); }
/** * Returns an array of the current elements in the queue. The order of * elements is in reverse order of the order items were added. * * @param type * @return An array containing the current elements in the queue. The first * element of the array is the tail of the queue and the last * element is the head of the queue */ public T[] toArray(T[] type) { System.getProperties(); if (type.length > maxSize) { throw new IllegalArgumentException("Size of array passed in cannot be greater than " + maxSize); } int curIndex = getCurrentIndex(); for (int k = 0; k < type.length; k++) { int index = getIndex(curIndex - k); type[k] = circularArray[index].get(); } return type; }
/** * Returns true if the queue is empty, otherwise false * * @return true if the queue is empty, false otherwise */ public boolean isEmtpy() { return depth() == 0; }
/** * {@inheritDoc} */ void recordSample() { final long sample; if (resetOnSample) { sample = getAndReset(); } else { sample = getValue(); } final long now = System.currentTimeMillis(); TimeStampedCounterValue timedSample = new TimeStampedCounterValue(now, sample); history.push(timedSample); }
/** * Constructor accepting a {@link SampledCounterConfig} * * @param config */ public SampledCounterImpl(SampledCounterConfig config) { super(config.getInitialValue()); this.intervalMillis = config.getIntervalSecs() * MILLIS_PER_SEC; this.history = new CircularLossyQueue<TimeStampedCounterValue>(config.getHistorySize()); this.resetOnSample = config.isResetOnSample(); this.samplerTask = new TimerTask() { @Override public void run() { recordSample(); } }; recordSample(); }
/** * Returns value at the tail of the queue * * @return Value at the tail of the queue */ public T peek() { if (depth() == 0) { return null; } return circularArray[getIndex(getCurrentIndex())].get(); }
/** * {@inheritDoc} */ public TimeStampedCounterValue getMostRecentSample() { return this.history.peek(); }