• 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/stats/ConcurrentStatsCounter.java
1
/*
2
 * Copyright 2014 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.stats;
17

18
import static java.util.Objects.requireNonNull;
19

20
import java.util.concurrent.atomic.LongAdder;
21

22
import org.jspecify.annotations.NullMarked;
23

24
import com.github.benmanes.caffeine.cache.Cache;
25
import com.github.benmanes.caffeine.cache.RemovalCause;
26

27
/**
28
 * A thread-safe {@link StatsCounter} implementation for use by {@link Cache} implementors.
29
 *
30
 * @author ben.manes@gmail.com (Ben Manes)
31
 */
32
@NullMarked
33
public final class ConcurrentStatsCounter implements StatsCounter {
34
  private final LongAdder hitCount;
35
  private final LongAdder missCount;
36
  private final LongAdder loadSuccessCount;
37
  private final LongAdder loadFailureCount;
38
  private final LongAdder totalLoadTime;
39
  private final LongAdder evictionCount;
40
  private final LongAdder evictionWeight;
41

42
  /**
43
   * Constructs an instance with all counts initialized to zero.
44
   */
45
  public ConcurrentStatsCounter() {
×
46
    hitCount = new LongAdder();
×
47
    missCount = new LongAdder();
×
48
    loadSuccessCount = new LongAdder();
×
49
    loadFailureCount = new LongAdder();
×
50
    totalLoadTime = new LongAdder();
×
51
    evictionCount = new LongAdder();
×
52
    evictionWeight = new LongAdder();
×
53
  }
×
54

55
  @Override
56
  public void recordHits(int count) {
57
    hitCount.add(count);
×
58
  }
×
59

60
  @Override
61
  public void recordMisses(int count) {
62
    missCount.add(count);
×
63
  }
×
64

65
  @Override
66
  public void recordLoadSuccess(long loadTime) {
67
    loadSuccessCount.increment();
×
68
    totalLoadTime.add(loadTime);
×
69
  }
×
70

71
  @Override
72
  public void recordLoadFailure(long loadTime) {
73
    loadFailureCount.increment();
×
74
    totalLoadTime.add(loadTime);
×
75
  }
×
76

77
  @Override
78
  public void recordEviction(int weight, RemovalCause cause) {
79
    requireNonNull(cause);
×
80
    evictionCount.increment();
×
81
    evictionWeight.add(weight);
×
82
  }
×
83

84
  @Override
85
  public CacheStats snapshot() {
86
    return CacheStats.of(
×
87
        negativeToMaxValue(hitCount.sum()),
×
88
        negativeToMaxValue(missCount.sum()),
×
89
        negativeToMaxValue(loadSuccessCount.sum()),
×
90
        negativeToMaxValue(loadFailureCount.sum()),
×
91
        negativeToMaxValue(totalLoadTime.sum()),
×
92
        negativeToMaxValue(evictionCount.sum()),
×
93
        negativeToMaxValue(evictionWeight.sum()));
×
94
  }
95

96
  /** Returns {@code value}, if non-negative. Otherwise, returns {@link Long#MAX_VALUE}. */
97
  private static long negativeToMaxValue(long value) {
98
    return (value >= 0) ? value : Long.MAX_VALUE;
×
99
  }
100

101
  /**
102
   * Increments all counters by the values in {@code other}.
103
   *
104
   * @param other the counter to increment from
105
   */
106
  public void incrementBy(StatsCounter other) {
107
    CacheStats otherStats = other.snapshot();
×
108
    hitCount.add(otherStats.hitCount());
×
109
    missCount.add(otherStats.missCount());
×
110
    loadSuccessCount.add(otherStats.loadSuccessCount());
×
111
    loadFailureCount.add(otherStats.loadFailureCount());
×
112
    totalLoadTime.add(otherStats.totalLoadTime());
×
113
    evictionCount.add(otherStats.evictionCount());
×
114
    evictionWeight.add(otherStats.evictionWeight());
×
115
  }
×
116

117
  @Override
118
  public String toString() {
119
    return snapshot().toString();
×
120
  }
121
}
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