public List<MessageReference> getScheduledReferences() {
    List<MessageReference> refs = new LinkedList<MessageReference>();

    synchronized (scheduledReferences) {
      for (RefScheduled ref : scheduledReferences) {
        refs.add(ref.getRef());
      }
    }
    return refs;
  }
    public int compare(RefScheduled ref1, RefScheduled ref2) {
      long diff =
          ref1.getRef().getScheduledDeliveryTime() - ref2.getRef().getScheduledDeliveryTime();

      if (diff < 0L) {
        return -1;
      }
      if (diff > 0L) {
        return 1;
      }

      // Even if ref1 and ref2 have the same delivery time, we only want to return 0 if they are
      // identical
      if (ref1 == ref2) {
        return 0;
      } else {

        if (ref1.isTail() && !ref2.isTail()) {
          return 1;
        } else if (!ref1.isTail() && ref2.isTail()) {
          return -1;
        }
        if (!ref1.isTail() && !ref2.isTail()) {
          return -1;
        } else {
          return 1;
        }
      }
    }