@Override
public CompletableFuture<LogAddress> append(ArrayView data, Duration timeout) {
ensurePreconditions();
long traceId = LoggerHelpers.traceEnterWithContext(log, this.traceObjectId, "append", data.getLength());
if (data.getLength() > getMaxAppendLength()) {
return Futures.failedFuture(new WriteTooLongException(data.getLength(), getMaxAppendLength()));
}
Timer timer = new Timer();
CompletableFuture<LogAddress> result = new CompletableFuture<>();
this.writes.add(new Write(data, getWriteLedger(), result));
this.writeProcessor.runAsync();
result.whenCompleteAsync((address, ex) -> {
if (ex != null) {
handleWriteException(ex);
} else {
this.metrics.writeCompleted(timer.getElapsed());
LoggerHelpers.traceLeave(log, this.traceObjectId, "append", traceId, data.getLength(), address);
}
}, this.executorService);
return result;
}