public void close(final Runnable onInitialClose, final Runnable onSubsequentClose) {
        if (isClosed.compareAndSet(false, true)) {
            if (onInitialClose != null)
                onInitialClose.run();
        } else {
            if (onSubsequentClose != null)
                onSubsequentClose.run();
        }
    }
Closes the resource in a thread-safe manner.

<p/>

After the execution has completed, calls to {@link #isClosed()} will return {@code false} and calls to
{@link #assertOpen(String)} and {@link #assertOpen(Supplier)}
will throw an {@link IllegalStateException}.

@param onInitialClose    Optional {@link Runnable} to execute when the resource is closed. Note that the
                         object will still be considered closed even if an exception is thrown during the course
                         of its execution; can be {@code null}
@param onSubsequentClose Optional {@link Runnable} to execute if this resource was previously closed. Note that
                         no state will be affected if an exception is thrown during its execution; can be
                         {@code null}
clients/src/main/java/org/apache/kafka/common/internals/IdempotentCloser.java