@Override public CompletableFuture<Void> pingTransaction(Stream stream, UUID txId, long lease) { return Futures.toVoidExpecting( controller.pingTransaction(stream.getScope(), stream.getStreamName(), ModelHelper.decode(txId), lease), PingTxnStatus.newBuilder().setStatus(PingTxnStatus.Status.OK).build(), PingFailedException::new); }
@Override public CompletableFuture<Void> abortTransaction(final Stream stream, final UUID txId) { Exceptions.checkNotClosed(closed.get(), this); Preconditions.checkNotNull(stream, "stream"); Preconditions.checkNotNull(txId, "txId"); long traceId = LoggerHelpers.traceEnter(log, "abortTransaction", stream, txId); final CompletableFuture<TxnStatus> result = this.retryConfig.runAsync(() -> { RPCAsyncCallback<TxnStatus> callback = new RPCAsyncCallback<>(traceId, "abortTransaction"); client.abortTransaction(TxnRequest.newBuilder() .setStreamInfo(ModelHelper.createStreamInfo(stream.getScope(), stream.getStreamName())) .setTxnId(ModelHelper.decode(txId)) .build(), callback); return callback.getFuture(); }, this.executor); return Futures.toVoidExpecting(result, TxnStatus.newBuilder().setStatus(TxnStatus.Status.SUCCESS).build(), TxnFailedException::new) .whenComplete((x, e) -> { if (e != null) { log.warn("abortTransaction failed: ", e); } LoggerHelpers.traceLeave(log, "abortTransaction", traceId); }); }
@Override public CompletableFuture<Void> commitTransaction(final Stream stream, final UUID txId) { Exceptions.checkNotClosed(closed.get(), this); Preconditions.checkNotNull(stream, "stream"); Preconditions.checkNotNull(txId, "txId"); long traceId = LoggerHelpers.traceEnter(log, "commitTransaction", stream, txId); final CompletableFuture<TxnStatus> result = this.retryConfig.runAsync(() -> { RPCAsyncCallback<TxnStatus> callback = new RPCAsyncCallback<>(traceId, "commitTransaction"); client.commitTransaction(TxnRequest.newBuilder() .setStreamInfo(ModelHelper.createStreamInfo(stream.getScope(), stream.getStreamName())) .setTxnId(ModelHelper.decode(txId)) .build(), callback); return callback.getFuture(); }, this.executor); return Futures.toVoidExpecting(result, TxnStatus.newBuilder().setStatus(TxnStatus.Status.SUCCESS).build(), TxnFailedException::new) .whenComplete((x, e) -> { if (e != null) { log.warn("commitTransaction failed: ", e); } LoggerHelpers.traceLeave(log, "commitTransaction", traceId); }); }
@Override public CompletableFuture<Void> pingTransaction(Stream stream, UUID txId, long lease) { Exceptions.checkNotClosed(closed.get(), this); long traceId = LoggerHelpers.traceEnter(log, "pingTransaction", stream, txId, lease); final CompletableFuture<PingTxnStatus> result = this.retryConfig.runAsync(() -> { RPCAsyncCallback<PingTxnStatus> callback = new RPCAsyncCallback<>(traceId, "pingTransaction"); client.pingTransaction(PingTxnRequest.newBuilder().setStreamInfo( ModelHelper.createStreamInfo(stream.getScope(), stream.getStreamName())) .setTxnId(ModelHelper.decode(txId)) .setLease(lease).build(), callback); return callback.getFuture(); }, this.executor); return Futures.toVoidExpecting(result, PingTxnStatus.newBuilder().setStatus(PingTxnStatus.Status.OK).build(), PingFailedException::new) .whenComplete((x, e) -> { if (e != null) { log.warn("pingTransaction failed: ", e); } LoggerHelpers.traceLeave(log, "pingTransaction", traceId); }); }