code: public synchronized int discardBefore(final int firstPositionNotToDiscard) {
          final int firstMessagePosition = this.getFirstPosition();
          if (this.getNextPosition() == MessageStore.INITIAL_MESSAGE_POSITION) {
              MessageStore.LOGGER.info("Not discarding any messages, as there haven't been any messages yet.");
              return 0;
          } else if ((firstPositionNotToDiscard < MessageStore.INITIAL_MESSAGE_POSITION)
                  || (firstPositionNotToDiscard <= firstMessagePosition)) {
              MessageStore.LOGGER.info(
                      "Not discarding any messages, as there are no messages with position lower than {}.",
                      firstPositionNotToDiscard);
              return 0;
          } else if (firstPositionNotToDiscard > this.getLatestPosition()) {
              MessageStore.LOGGER.info("Discarding all messages, as all have lower positions than {}.",
                      firstPositionNotToDiscard);
              final int size = this.store.size();
              this.store.clear();
              return size;
          }
          // and now actually discard
          MessageStore.LOGGER.info("Discarding messages in positions <{},{}).", firstMessagePosition,
                  firstPositionNotToDiscard);
          final SortedMap<Integer, Message> toDiscard = this.store.headMap(firstPositionNotToDiscard);
          final int size = toDiscard.size();
          toDiscard.clear();
          return size;
      }
docs: Remove messages from the queue that come before the given position. If
  the ID is larger than {@link #getLatestPosition()}, all messages will be
  discarded while marking no future messages for discarding.
  
  @param firstPositionNotToDiscard
  Messages be kept from this position onward, inclusive.
  @return Number of messages actually discarded.