コード例 #1
0
  /** {@inheritDoc} */
  @Override
  protected Collection<E> dequeue0(int cnt) {
    WindowHolder tup = ref.get();

    AtomicInteger size = tup.size();
    Collection<T> evts = tup.collection();

    Collection<E> resCol = new ArrayList<>(cnt);

    while (true) {
      int curSize = size.get();

      if (curSize > 0) {
        if (size.compareAndSet(curSize, curSize - 1)) {
          E res = pollInternal(evts, tup.set());

          if (res != null) {
            resCol.add(res);

            if (resCol.size() >= cnt) return resCol;
          } else {
            size.incrementAndGet();

            return resCol;
          }
        }
      } else return resCol;
    }
  }
コード例 #2
0
  /** {@inheritDoc} */
  @Override
  protected Collection<E> pollEvicted0(int cnt) {
    Collection<E> res = new ArrayList<>(cnt);

    for (int i = 0; i < cnt; i++) {
      E evicted = pollEvictedInternal();

      if (evicted == null) return res;

      res.add(evicted);
    }

    return res;
  }