/** @param evts Events to add. */
  private void addAll(Collection<E> evts) {
    WindowHolder tup = ref.get();

    int cnt = addAllInternal(evts, tup.collection(), tup.set());

    tup.size().addAndGet(cnt);
  }
  /** {@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;
    }
  }
  /**
   * Poll evicted internal implementation.
   *
   * @return Evicted element.
   */
  @Nullable
  private E pollEvictedInternal() {
    WindowHolder tup = ref.get();

    AtomicInteger size = tup.size();

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

      if (curSize > maxSize) {
        if (size.compareAndSet(curSize, curSize - 1)) {
          E evt = pollInternal(tup.collection(), tup.set());

          if (evt != null) return evt;
          else {
            // No actual events in queue, it means that other thread is just adding event.
            // return null as it is a concurrent add call.
            size.incrementAndGet();

            return null;
          }
        }
      } else return null;
    }
  }
  /** Checks window consistency. Used for testing. */
  void consistencyCheck() {
    WindowHolder win = ref.get();

    consistencyCheck(win.collection(), win.set(), win.size());
  }
  /** @param evt Event to add. */
  private void add(E evt) {
    WindowHolder tup = ref.get();

    if (addInternal(evt, tup.collection(), tup.set())) tup.size().incrementAndGet();
  }
  /** {@inheritDoc} */
  @Override
  protected GridStreamerWindowIterator<E> iterator0() {
    WindowHolder win = ref.get();

    return iteratorInternal(win.collection(), win.set(), win.size());
  }