use of com.apple.foundationdb.subspace.Subspace in project fdb-record-layer by FoundationDB.
the class SynchronizedSessionRunner method startSessionAsync.
/**
* Produces a new runner, wrapping a given runner, which performs all work in the context of a new
* {@link SynchronizedSession}.
* <p>
* The returned runner will have acquired and started the lease, so care must be taken to ensure that
* work begins before the lease expiration period.
* </p>
* @param lockSubspace the lock for which the session contends
* @param leaseLengthMill length between last access and lease's end time in milliseconds
* @param runner the underlying runner
* @return a future that will return a runner maintaining a new synchronized session
*/
public static CompletableFuture<SynchronizedSessionRunner> startSessionAsync(@Nonnull Subspace lockSubspace, long leaseLengthMill, @Nonnull FDBDatabaseRunnerImpl runner) {
final UUID newSessionId = UUID.randomUUID();
SynchronizedSession session = new SynchronizedSession(lockSubspace, newSessionId, leaseLengthMill);
return runner.runAsync(context -> session.initializeSessionAsync(context.ensureActive()), Arrays.asList(LogMessageKeys.TRANSACTION_NAME, "SynchronizedSessionRunner::startSession", LogMessageKeys.SESSION_ID, session.getSessionId(), LogMessageKeys.SUBSPACE, lockSubspace)).thenApply(vignore -> new SynchronizedSessionRunner(runner, session));
}
Aggregations