@Nullable
    private EventCount onEvent(Event event) {
        final long tickerNanos = ticker.read();

        final Bucket currentBucket = current.get();
        assert currentBucket != null;

        if (tickerNanos < currentBucket.timestamp()) {
            // if current timestamp is older than bucket's timestamp (maybe race or GC pause?),
            // then creates an instant bucket and puts it to the reservoir not to lose event.
            final Bucket bucket = new Bucket(tickerNanos);
            event.increment(bucket);
            reservoir.offer(bucket);
            return null;
        }

        if (tickerNanos < currentBucket.timestamp() + updateIntervalNanos) {
            // increments the current bucket since it is exactly latest
            event.increment(currentBucket);
            return null;
        }

        // the current bucket is old
        // it's time to create new one
        final Bucket nextBucket = new Bucket(tickerNanos);
        event.increment(nextBucket);

        // replaces the bucket
        if (current.compareAndSet(currentBucket, nextBucket)) {
            // puts old one to the reservoir
            reservoir.offer(currentBucket);
            // and then updates count
            final EventCount eventCount = trimAndSum(tickerNanos);
            snapshot.set(eventCount);
            return eventCount;
        } else {
            // the bucket has been replaced already
            // puts new one as an instant bucket to the reservoir not to lose event
            reservoir.offer(nextBucket);
            return null;
        }
    }
The queue that stores {@link Bucket}s within the time window.
core/src/main/java/com/linecorp/armeria/common/util/SlidingWindowCounter.java