1 /**
2 * Logback: the reliable, generic, fast and flexible logging framework.
3 * Copyright (C) 1999-2011, 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.CoreConstants;
17 import ch.qos.logback.core.helpers.CyclicBuffer;
18
19 /**
20 * An interface for tracking cyclic buffers by key.
21 *
22 * @author Ceki Gücü
23 */
24 public interface CyclicBufferTracker<E> {
25
26 public static int DEFAULT_BUFFER_SIZE = 256;
27 public static int DEFAULT_NUMBER_OF_BUFFERS = 64;
28
29 static int THRESHOLD = 30 * 60 * CoreConstants.MILLIS_IN_ONE_SECOND; // 30 minutes
30
31 public int getBufferSize();
32
33 public void setBufferSize(int size);
34 public int getMaxNumberOfBuffers();
35
36 /**
37 * Set the maximum number of tracked buffers. After reaching the maximum number of
38 * buffers, the creation of a new buffer implies the removal of the least recently
39 * used buffer.
40 *
41 * @param maxNumBuffers
42 */
43 public void setMaxNumberOfBuffers(int maxNumBuffers);
44
45
46 /**
47 * Get the cyclic buffer identified by 'key', updating its timestamp in the process.
48 * If there is no such buffer, create it. If the current number of buffers is
49 * above or equal to 'maxNumBuffers' then the least recently accessed buffer is removed.
50 *
51 * @param key
52 * @param timestamp
53 * @return
54 */
55 CyclicBuffer<E> getOrCreate(String key, long timestamp);
56
57 /**
58 * Remove a cyclic buffer identified by its key.
59 */
60 void removeBuffer(String key);
61
62 /**
63 * Clear (and detach) buffers which are stale.
64 *
65 * @param now
66 */
67 void clearStaleBuffers(long now);
68
69 /**
70 * The size of the internal map/list/collection holding the cyclic buffers.
71 * @return size of internal collection
72 */
73 int size();
74 }