001/* 002 * (C) Copyright 2006-2009 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 * 016 * Contributors: 017 * Nuxeo - initial API and implementation 018 * 019 * $Id$ 020 */ 021package org.nuxeo.runtime.management.counters; 022 023import java.util.Iterator; 024import java.util.LinkedList; 025 026/** 027 * Fixed length Stack that is used to store values of a counter over time 028 * 029 * @author Tiry (tdelprat@nuxeo.com) 030 * @deprecated since 11.4: use dropwizard metrics instead 031 */ 032@Deprecated(since = "11.4") 033public class CounterHistoryStack implements Iterable<long[]> { 034 035 protected final LinkedList<long[]> list = new LinkedList<>(); 036 037 protected final int maxSize; 038 039 public CounterHistoryStack(int size) { 040 maxSize = size; 041 } 042 043 public synchronized void push(long[] item) { 044 list.push(item); 045 if (list.size() > maxSize) { 046 list.remove(list.size() - 1); 047 } 048 } 049 050 @Override 051 public Iterator<long[]> iterator() { 052 return list.iterator(); 053 } 054 055 @Override 056 public String toString() { 057 StringBuilder sb = new StringBuilder(); 058 059 for (long[] entry : this) { 060 sb.append(entry[0]); 061 sb.append(" => "); 062 sb.append(entry[1]); 063 sb.append("\n"); 064 } 065 return sb.toString(); 066 } 067 068 public long[] get(int idx) { 069 return list.get(idx); 070 } 071 072 public LinkedList<long[]> getAsList() { 073 return list; 074 } 075}