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

ben-manes / caffeine / #5173

29 Dec 2025 05:27AM UTC coverage: 0.0% (-100.0%) from 100.0%
#5173

push

github

ben-manes
speed up development ci build

0 of 3838 branches covered (0.0%)

0 of 7869 relevant lines covered (0.0%)

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}
50
   */
51
  int offer(E e);
52

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

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

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

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

85
enum DisabledBuffer implements Buffer<Object> {
×
86
  INSTANCE;
×
87

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

© 2026 Coveralls, Inc