use of io.pravega.common.util.ArrayView in project pravega by pravega.
the class SegmentStoreAdapter method append.
@Override
public CompletableFuture<Void> append(String streamName, Event event, Duration timeout) {
ensureRunning();
ArrayView s = event.getSerialization();
byte[] payload = s.arrayOffset() == 0 ? s.array() : Arrays.copyOfRange(s.array(), s.arrayOffset(), s.getLength());
return this.streamSegmentStore.append(streamName, payload, null, timeout).exceptionally(ex -> attemptReconcile(ex, streamName, timeout));
}
use of io.pravega.common.util.ArrayView in project pravega by pravega.
the class InMemoryDurableDataLog method append.
@Override
public CompletableFuture<LogAddress> append(ArrayView data, Duration timeout) {
ensurePreconditions();
CompletableFuture<LogAddress> result;
try {
Entry entry = new Entry(data);
synchronized (this.entries) {
entry.sequenceNumber = this.offset;
this.entries.add(entry, clientId);
// Only update internals after a successful add.
this.offset += entry.data.length;
}
result = CompletableFuture.completedFuture(new InMemoryLogAddress(entry.sequenceNumber));
} catch (Throwable ex) {
return Futures.failedFuture(ex);
}
Duration delay = this.appendDelayProvider.get();
if (delay.compareTo(Duration.ZERO) <= 0) {
// No delay, execute right away.
return result;
} else {
// Schedule the append after the given delay.
return result.thenComposeAsync(logAddress -> Futures.delayedFuture(delay, this.executorService).thenApply(ignored -> logAddress), this.executorService);
}
}
Aggregations