public void maybeFinish(ClientContext context) { boolean success; boolean wasFatal; synchronized(this) { if(completedBlocks != inserters.length) return; success = completedBlocks == succeededBlocks; wasFatal = fatal; } if(success) { parent.onSuccess(this, context); } else if(wasFatal) parent.onFailure(new InsertException(InsertExceptionMode.FATAL_ERRORS_IN_BLOCKS, errors, null), this, context); else parent.onFailure(new InsertException(InsertExceptionMode.TOO_MANY_RETRIES_IN_BLOCKS, errors, null), this, context); }