View Javadoc
1   /**
2    * Logback: the reliable, generic, fast and flexible logging framework.
3    * Copyright (C) 1999-2015, QOS.ch. All rights reserved.
4    *
5    * This program and the accompanying materials are dual-licensed under
6    * either the terms of the Eclipse Public License v1.0 as published by
7    * the Eclipse Foundation
8    *
9    *   or (per the licensee's choosing)
10   *
11   * under the terms of the GNU Lesser General Public License version 2.1
12   * as published by the Free Software Foundation.
13   */
14  package ch.qos.logback.core.spi;
15  
16  import ch.qos.logback.core.helpers.CyclicBuffer;
17  
18  import java.util.*;
19  
20  /**
21   * CyclicBufferTracker tracks {@link CyclicBuffer} instances.
22   *
23   * @author Ceki Gülcü
24   */
25  public class CyclicBufferTracker<E> extends AbstractComponentTracker<CyclicBuffer<E>> {
26  
27      static final int DEFAULT_NUMBER_OF_BUFFERS = 64;
28  
29      static final int DEFAULT_BUFFER_SIZE = 256;
30      int bufferSize = DEFAULT_BUFFER_SIZE;
31  
32      public CyclicBufferTracker() {
33          super();
34          setMaxComponents(DEFAULT_NUMBER_OF_BUFFERS);
35      }
36  
37      public int getBufferSize() {
38          return bufferSize;
39      }
40  
41      public void setBufferSize(int bufferSize) {
42          this.bufferSize = bufferSize;
43      }
44  
45      @Override
46      protected void processPriorToRemoval(CyclicBuffer<E> component) {
47          component.clear();
48      }
49  
50      @Override
51      protected CyclicBuffer<E> buildComponent(String key) {
52          return new CyclicBuffer<E>(bufferSize);
53      }
54  
55      @Override
56      protected boolean isComponentStale(CyclicBuffer<E> eCyclicBuffer) {
57          return false;
58      }
59  
60      // for testing purposes
61      List<String> liveKeysAsOrderedList() {
62          return new ArrayList<String>(liveMap.keySet());
63      }
64  
65      List<String> lingererKeysAsOrderedList() {
66          return new ArrayList<String>(lingerersMap.keySet());
67  
68      }
69  
70  }