public void close ( Duration duration ) throws InterruptedException , TimeoutException { closed = true ; long deadlineMs = System . currentTimeMillis ( ) + duration . toMillis ( ) ; synchronized ( lock ) { while ( numOutstanding . get ( ) > 0 ) { long waitMs = deadlineMs - System . currentTimeMillis ( ) ; if ( waitMs <= 0 ) { throw new TimeoutException ( "Timed out waiting outstanding mutations to finish" ) ; } lock . wait ( waitMs ) ; } // numFailures can only be checked after numOutstanding is zero. if ( numFailures > 0 ) { throw new BulkMutationFailure ( numFailures ) ; } } }
Prevents further mutations and waits for all outstanding mutations to complete .