public synchronized List<Packet> queueOrPush(@Nonnull final Packet packet)
    {
        queue.add(packet);

        final boolean mustPush =
               !DELAY_ENABLED.getValue() // The feature is disabled by configuration. Always send stanzas immediately.
            || active // The client is active! Do not delay.
            || queue.size() > DELAY_QUEUE_CAPACITY.getValue() // The delay queue has reached its capacity. Flush the entire thing.
            || Instant.now().isAfter(lastPush.plus(DELAY_MAX_DURATION.getValue())) // Ensure that periodically, delayed data is sent anyway.
            || !canDelay(packet);

        final List<Packet> result = new LinkedList<>();
        if (mustPush) {
            result.addAll(queue);
            queue.clear();
            lastPush = Instant.now();
            Log.trace("Cannot delay delivery of stanza. Push {} {}.", result.size(), result.size() == 1 ? "stanza" : "stanzas");
        } else {
            Log.trace("Delay delivery of stanza. Current queue size: {}", queue.size());
        }
        return result;
    }
Queues an unimportant stanza for later delivery, or returns the entire queue (including the argument) to be
sent to the client.

@param packet the stanza to process.
@return stanzas to be delivered to the client (possibly empty).
xmppserver/src/main/java/org/jivesoftware/openfire/csi/CsiManager.java