• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

ben-manes / caffeine / #5707

02 Aug 2026 12:45AM UTC coverage: 0.106% (-99.9%) from 100.0%
#5707

push

github

ben-manes
fix wikibench trace reader after overly strict audit fixes

0 of 4235 branches covered (0.0%)

9 of 8528 relevant lines covered (0.11%)

0.0 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/caffeine/src/main/java/com/github/benmanes/caffeine/cache/Buffer.java
1
/*
2
 * Copyright 2015 Ben Manes. All Rights Reserved.
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 *     http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16
package com.github.benmanes.caffeine.cache;
17

18
import java.util.function.Consumer;
19

20
/**
21
 * A multiple-producer / single-consumer buffer that rejects new elements if it is full or
22
 * fails spuriously due to contention. Unlike a queue and stack, a buffer does not guarantee an
23
 * ordering of elements in either FIFO or LIFO order.
24
 * <p>
25
 * Beware that it is the responsibility of the caller to ensure that a consumer has exclusive read
26
 * access to the buffer. This implementation does <em>not</em> include fail-fast behavior to guard
27
 * against incorrect consumer usage.
28
 *
29
 * @param <E> the type of elements maintained by this buffer
30
 * @author ben.manes@gmail.com (Ben Manes)
31
 */
32
interface Buffer<E> {
33
  int FULL = 1;     // if the buffer is full
34
  int FAILED = -1;  // if the CAS failed
35
  int SUCCESS = 0;  // if added
36

37
  /** Returns a no-op implementation. */
38
  @SuppressWarnings("unchecked")
39
  static <E> Buffer<E> disabled() {
40
    return (Buffer<E>) DisabledBuffer.INSTANCE;
×
41
  }
42

43
  /**
44
   * Inserts the specified element into this buffer if it is possible to do so immediately without
45
   * violating capacity restrictions. The addition is allowed to fail spuriously if multiple
46
   * threads insert concurrently.
47
   *
48
   * @param e the element to add
49
   * @return {@code Buffer.SUCCESS}, {@code Buffer.FAILED}, or {@code Buffer.FULL}; an insertion
50
   *         that fills the last free slot is recorded and reports {@code Buffer.FULL} so that the
51
   *         caller drains promptly
52
   */
53
  int offer(E e);
54

55
  /**
56
   * Drains the buffer, sending each element to the consumer for processing. The caller must ensure
57
   * that a consumer has exclusive read access to the buffer.
58
   *
59
   * @param consumer the action to perform on each element
60
   */
61
  void drainTo(Consumer<E> consumer);
62

63
  /**
64
   * Returns the number of elements residing in the buffer.
65
   *
66
   * @return the number of elements in this buffer
67
   */
68
  default long size() {
69
    return writes() - reads();
×
70
  }
71

72
  /**
73
   * Returns the number of elements that have been read from the buffer.
74
   *
75
   * @return the number of elements read from this buffer
76
   */
77
  long reads();
78

79
  /**
80
   * Returns the number of elements that have been written to the buffer.
81
   *
82
   * @return the number of elements written to this buffer
83
   */
84
  long writes();
85
}
86

87
enum DisabledBuffer implements Buffer<Object> {
×
88
  INSTANCE;
×
89

90
  @Override public int offer(Object e) { return Buffer.SUCCESS; }
×
91
  @Override public void drainTo(Consumer<Object> consumer) {}
×
92
  @Override public long size() { return 0; }
×
93
  @Override public long reads() { return 0; }
×
94
  @Override public long writes() { return 0; }
×
95
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc