Class LivenessScopeStack
Support for a thread-local stack of LivenessScope
s to allow the preferred programming model for scoping of
LivenessArtifact
s.
Instances expect to be used on exactly one thread, and hence do not take any measures to ensure thread safety.
-
Method Summary
Modifier and TypeMethodDescriptionstatic <RESULT_TYPE extends LivenessReferent>
RESULT_TYPE[]computeArrayEnclosed
(@NotNull Supplier<RESULT_TYPE[]> computation, @NotNull BooleanSupplier shouldEnclose, @NotNull Predicate<RESULT_TYPE> shouldManageResult) Perform a computation guarded by a newLivenessScope
that is released before this method returns.static <RESULT_TYPE extends LivenessReferent>
RESULT_TYPEcomputeEnclosed
(@NotNull Supplier<RESULT_TYPE> computation, @NotNull BooleanSupplier shouldEnclose, @NotNull Predicate<RESULT_TYPE> shouldManageResult) Perform a computation guarded by a newLivenessScope
that is released before this method returns.static @NotNull SafeCloseable
open()
Push an anonymous scope onto the scope stack, and get anSafeCloseable
that pops it and thenLivenessScope.release()
s it.static @NotNull SafeCloseable
open
(@NotNull LivenessScope scope, boolean releaseOnClose) Push a scope onto the scope stack, and get anSafeCloseable
that pops it.static @NotNull LivenessManager
peek()
Get the scope at the top of the current thread's scope stack, or the base manager if no scopes have been pushed but not popped on this thread.static void
pop
(@NotNull LivenessScope scope) Pop a scope from the current thread's scope stack.static void
push
(@NotNull LivenessScope scope) Push a scope onto the current thread's scope stack.
-
Method Details
-
push
Push a scope onto the current thread's scope stack.
- Parameters:
scope
- The scope
-
pop
Pop a scope from the current thread's scope stack.
Must be the current top of the stack.
- Parameters:
scope
- The scope
-
peek
Get the scope at the top of the current thread's scope stack, or the base manager if no scopes have been pushed but not popped on this thread.
This method defines the manager that should be used for all new
LivenessArtifact
s.- Returns:
- The current manager
-
open
@NotNull public static @NotNull SafeCloseable open(@NotNull @NotNull LivenessScope scope, boolean releaseOnClose) Push a scope onto the scope stack, and get an
SafeCloseable
that pops it.This is useful for enclosing scope usage in a try-with-resources block.
- Parameters:
scope
- The scopereleaseOnClose
- Whether the scope should be released when the result is closed- Returns:
- A
SafeCloseable
whoseSafeCloseable.close()
method invokespop(LivenessScope)
for the scope (followed byLivenessScope.release()
if releaseOnClose is true)
-
open
Push an anonymous scope onto the scope stack, and get an
SafeCloseable
that pops it and thenLivenessScope.release()
s it.This is useful enclosing a series of query engine actions whose results must be explicitly retained externally in order to preserve liveness.
- Returns:
- A
SafeCloseable
whoseSafeCloseable.close()
method invokespop(LivenessScope)
for the scope, followed byLivenessScope.release()
-
computeEnclosed
public static <RESULT_TYPE extends LivenessReferent> RESULT_TYPE computeEnclosed(@NotNull @NotNull Supplier<RESULT_TYPE> computation, @NotNull @NotNull BooleanSupplier shouldEnclose, @NotNull @NotNull Predicate<RESULT_TYPE> shouldManageResult) Perform a computation guarded by a newLivenessScope
that is released before this method returns. The result of the computation is managed by the enclosingLivenessManager
, as determined bypeek()
.- Parameters:
computation
- The computation to perform. Will be invoked exactly once.shouldEnclose
- Whether its actually necessary to use a new LivenessScope for the computation. Will be invoked exactly once.shouldManageResult
- Whether its necessary to manage the result with the enclosing LivenessScope. Will be invoked exactly once.- Returns:
- The result of
computation.get()
-
computeArrayEnclosed
public static <RESULT_TYPE extends LivenessReferent> RESULT_TYPE[] computeArrayEnclosed(@NotNull @NotNull Supplier<RESULT_TYPE[]> computation, @NotNull @NotNull BooleanSupplier shouldEnclose, @NotNull @NotNull Predicate<RESULT_TYPE> shouldManageResult) Perform a computation guarded by a newLivenessScope
that is released before this method returns. The results of the computation are managed by the enclosingLivenessManager
, as determined bypeek()
.- Parameters:
computation
- The computation to perform. Will be invoked exactly once.shouldEnclose
- Whether its actually necessary to use a new LivenessScope for the computation. Will be invoked exactly once.shouldManageResult
- Whether its necessary to manage the result with the enclosing LivenessScope. Will be invoked exactly once per result.- Returns:
- The results of
computation.get()
-