/** * Indicates that this write completed successfully. This will set the final result on the externalCompletion future. */ Timer complete() { Preconditions.checkState(this.entryId.get() >= 0, "entryId not set; cannot complete Write."); this.failureCause.set(null); this.result.complete(new LedgerAddress(this.writeLedger.get().metadata, this.entryId.get())); return endAttempt(); }
/** * Indicates that this write failed. * * @param cause The failure cause. If null, the previous failure cause is preserved. * @param complete If true, the externalCompletion will be immediately be completed with the current failure cause. * If false, no completion will be done. */ void fail(Throwable cause, boolean complete) { if (cause != null) { Throwable e = this.failureCause.get(); if (e != null && e != cause) { cause.addSuppressed(e); } this.failureCause.set(cause); } endAttempt(); WriteLedger ledger = this.writeLedger.get(); if (ledger != null && ledger.isRolledOver()) { // Rollovers aren't really failures (they're caused by us). In that case, do not count this failure as an attempt. this.attemptCount.updateAndGet(v -> Math.max(0, v - 1)); } if (complete) { this.result.completeExceptionally(this.failureCause.get()); } }