public Dir next() {
        Dir dir = null;
        try {
            lock.lockInterruptibly();
            try {
                while (dir == null) {
                    while (readId > writeId) {
                        condition.await();
                    }
                    // TODO It is possible to have big gaps, e.g. if there was an exception when
                    //  transferring 001 (so it was left on the queue) but 002 -> 901 worked. On next
                    //  reboot, it will have to check each of 002 -> 901 to find them not there.
                    //  May be better to call DirUtil.getMinDirId if we encounter a gap
                    final long id = readId++;
                    final Path path = DirUtil.createPath(rootDir, id);
                    if (Files.isDirectory(path)) {
                        queueMonitor.setReadPos(id);
                        dir = createDir(path);
                    }
                }
            } finally {
                lock.unlock();
            }
        } catch (final InterruptedException e) {
            throw UncheckedInterruptedException.create(e);
        }
        LOGGER.trace("{} ({}) - next() dir: {}", name, rootDir, dir);
        return dir;
    }
Get the next dir that is available in the queue as soon as one is available, block until then.

@return A dir that is managed by this queue. The dir should be closed once used to ensure parent dirs are
deleted if empty.
stroom-proxy/stroom-proxy-app/src/main/java/stroom/proxy/app/handler/DirQueue.java