public synchronized long removeBefore(final long newFirstIndex) {
    try (final ConcurrentIterableLinkedQueue<E>.DynamicIterator iterator =
        queue.iterateFromEarliest()) {
      while (iterator.getNextIndex() < newFirstIndex) {
        final E element = iterator.next(0);
        if (Objects.isNull(element)) {
          break;
        }
        releaseResource(element);
      }
    }
    return queue.tryRemoveBefore(newFirstIndex);
  }
{@link AbstractSerializableListeningQueue} is the encapsulation of the {@link
ConcurrentIterableLinkedQueue} to enable flushing all the element to disk and reading from it. To
implement this, each element much be configured with its own ser/de method. Besides, this class
also provides a means of opening and closing the queue, and a queue will stay empty while closed.
iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/pipe/datastructure/queue/listening/AbstractSerializableListeningQueue.java