private void sendEmptyRequests(boolean wakeFromPause) {
        assertUnlocked();

        while(true) {
            HTTPExchange sentExchange;
            lock.lock();

            try {
                if(!isWorking())
                    return;

                // If we're told we can wake from pause, but we're no longer paused,
                // switch back to a regular empty request.  This will happen if the
                // user sends a packet while we're paused.  It'll also happen the second
                // time through this loop, if hold is greater than one; the first packet
                // we send below will clear sessionPaused.
                if(!sessionPaused)
                    wakeFromPause = false;

                try {
                    sentExchange = sendInternal(ComposableBody.builder().build(), !wakeFromPause);
                } catch (BOSHException boshx) {
                    lock.unlock();
                    connectionLost(boshx);
                    lock.lock();
                    return;
                }

                if(sentExchange == null) {
                    // Once we're done, allow a new empty request task to be scheduled.
                    emptyRequestFuture = null;
                    break;
                }
            } finally {
                lock.unlock();
            }

            fireRequestSent(sentExchange.getRequest());
        }
    }