001/** 002 * Logback: the reliable, generic, fast and flexible logging framework. 003 * Copyright (C) 1999-2015, QOS.ch. All rights reserved. 004 * 005 * This program and the accompanying materials are dual-licensed under 006 * either the terms of the Eclipse Public License v1.0 as published by 007 * the Eclipse Foundation 008 * 009 * or (per the licensee's choosing) 010 * 011 * under the terms of the GNU Lesser General Public License version 2.1 012 * as published by the Free Software Foundation. 013 */ 014package ch.qos.logback.core.spi; 015 016import ch.qos.logback.core.helpers.CyclicBuffer; 017 018import java.util.*; 019 020/** 021 * CyclicBufferTracker tracks {@link CyclicBuffer} instances. 022 * 023 * @author Ceki Gülcü 024 */ 025public class CyclicBufferTracker<E> extends AbstractComponentTracker<CyclicBuffer<E>> { 026 027 static final int DEFAULT_NUMBER_OF_BUFFERS = 64; 028 029 static final int DEFAULT_BUFFER_SIZE = 256; 030 int bufferSize = DEFAULT_BUFFER_SIZE; 031 032 public CyclicBufferTracker() { 033 super(); 034 setMaxComponents(DEFAULT_NUMBER_OF_BUFFERS); 035 } 036 037 public int getBufferSize() { 038 return bufferSize; 039 } 040 041 public void setBufferSize(int bufferSize) { 042 this.bufferSize = bufferSize; 043 } 044 045 @Override 046 protected void processPriorToRemoval(CyclicBuffer<E> component) { 047 component.clear(); 048 } 049 050 @Override 051 protected CyclicBuffer<E> buildComponent(String key) { 052 return new CyclicBuffer<E>(bufferSize); 053 } 054 055 @Override 056 protected boolean isComponentStale(CyclicBuffer<E> eCyclicBuffer) { 057 return false; 058 } 059 060 // for testing purposes 061 List<String> liveKeysAsOrderedList() { 062 return new ArrayList<String>(liveMap.keySet()); 063 } 064 065 List<String> lingererKeysAsOrderedList() { 066 return new ArrayList<String>(lingerersMap.keySet()); 067 068 } 069 070}