/**
   * Commit. Remove and notify the completion of the completed messages from the list of messages.
   */
  public void commit() {
    while (!this.messages.isEmpty()) {
      final CoherenceMessage message = this.messages.get(0);
      if (!message.isDestinationArrived()) {
        break;
      }

      this.messages.remove(message);

      to.getCycleAccurateEventQueue()
          .schedule(
              this,
              () -> {
                message.onCompleted();
                if (message.getId() < lastCompletedMessageId) {
                  throw new IllegalArgumentException(
                      String.format(
                          "p2pReorderBuffer[%s->%s] messageId: %d, lastCompletedMessageId: %d",
                          from.getName(), to.getName(), message.getId(), lastCompletedMessageId));
                }
                lastCompletedMessageId = message.getId();
                to.receive(message);
              },
              to.getHitLatency());
    }
  }
 /**
  * Act on when a message arrives at the destination.
  *
  * @param message the message
  */
 public void onDestinationArrived(CoherenceMessage message) {
   message.onDestinationArrived();
   this.commit();
 }