private RollingDestination lockAndRoll(final Object key, final RollingDestination destination) throws IOException {
        RollingDestination dest = destination;

        // Lock the destination so only the current thread can use it.
        dest.lock();

        boolean rolled = true;
        try {
            // Try and roll the destination.
            rolled = dest.tryFlushAndRoll(false, Instant.now());

        } finally {
            // If we rolled the destination then remove it and unlock it.
            if (rolled) {
                removeDestination(key, dest);
                dest.unlock();
                dest = null;
            }
        }

        return dest;
    }
Try and lock this destination so that the current thread has exclusive access. Once locked we will attempt to
roll this destination if it needs rolling.
<p>
If it is rolled then this method will return null as this destination can no longer be used, if the destination
does not need rolling yet then it will be returned for use.

@param key         The key that this destination is associated with.
@param destination The destination to lock and attempt to roll.
@return The destination if it didn't need rolling and can be used, null otherwise. The returned
destination is locked for exclusive use by the current thread.
@throws IOException Could be thrown while attempting to flush or close the destination on roll.
stroom-pipeline/src/main/java/stroom/pipeline/destination/RollingDestinations.java