+ public FluentFuture<? extends @NonNull CommitInfo> commit(long timeout, TimeUnit timeUnit) {
+ if (wasSubmittedOrCancelled.get()) {
+ String msg = "Transaction was already submitted or canceled!";
+ LOG.error(msg);
+ return FluentFutures.immediateFailedFluentFuture(new IllegalStateException(msg));
+ }
+
+ LOG.debug("Transaction committed. Lock: {}", deviceLock);
+ wasSubmittedOrCancelled.set(true);
+ FluentFuture<? extends @NonNull CommitInfo> future =
+ rwTx.commit().withTimeout(timeout, timeUnit, scheduledExecutorService);
+
+ future.addCallback(new FutureCallback<CommitInfo>() {
+ @Override
+ public void onSuccess(@Nullable CommitInfo result) {
+ LOG.debug("Transaction with lock {} successfully committed:", deviceLock, result);
+ afterClose();
+ }
+
+ @Override
+ public void onFailure(Throwable throwable) {
+ LOG.error("Device transaction commit failed or submit took longer than {} {}! Unlocking device.",
+ timeout, timeUnit, throwable);
+ afterClose();
+ }
+ }, scheduledExecutorService);
+ return future;
+ }
+