Class LivenessScopeStack
Support for a thread-local stack of LivenessScopes to allow the preferred programming model for scoping of
LivenessArtifacts.
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, boolean shouldEnclose, @NotNull Predicate<RESULT_TYPE> shouldManageResult) Perform a computation guarded by a newLivenessScopethat is released before this method returns.static <RESULT_TYPE extends LivenessReferent>
RESULT_TYPE[]computeArrayEnclosed(@NotNull Supplier<RESULT_TYPE[]> computation, @NotNull BooleanSupplier shouldEnclose, @NotNull Predicate<RESULT_TYPE> shouldManageResult) Deprecated.static <RESULT_TYPE extends LivenessReferent>
RESULT_TYPEcomputeEnclosed(@NotNull Supplier<RESULT_TYPE> computation, boolean shouldEnclose, @NotNull Predicate<RESULT_TYPE> shouldManageResult) Perform a computation guarded by a newLivenessScopethat 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) Deprecated.static @NotNull SafeCloseableopen()Push an anonymous scope onto the scope stack, and get anSafeCloseablethat pops it and thenLivenessScope.release()s it.static @NotNull SafeCloseableopen(@NotNull ReleasableLivenessManager scope, boolean releaseOnClose) Push a scope onto the scope stack, and get anSafeCloseablethat pops it.static @NotNull LivenessManagerpeek()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 voidpop(@NotNull LivenessManager scope) Pop a scope from the current thread's scope stack.static voidpush(@NotNull LivenessManager 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
LivenessArtifacts.- Returns:
- The current manager
-
open
@NotNull public static @NotNull SafeCloseable open(@NotNull @NotNull ReleasableLivenessManager scope, boolean releaseOnClose) Push a scope onto the scope stack, and get an
SafeCloseablethat 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
SafeCloseablewhoseSafeCloseable.close()method invokespop(LivenessManager)for the scope (followed byLivenessScope.release()if releaseOnClose is true)
-
open
Push an anonymous scope onto the scope stack, and get an
SafeCloseablethat 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
SafeCloseablewhoseSafeCloseable.close()method invokespop(LivenessManager)for the scope, followed byLivenessScope.release()
-
computeEnclosed
@Deprecated 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) Deprecated.Perform a computation guarded by a newLivenessScopethat is released before this method returns. The result of the computation is managed by the enclosingLivenessManager, as determined bypeek().Equivalent to
computeEnclosed(computation, shouldEnclose.getAsBoolean(), shouldManageResult).- 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()
-
computeEnclosed
public static <RESULT_TYPE extends LivenessReferent> RESULT_TYPE computeEnclosed(@NotNull @NotNull Supplier<RESULT_TYPE> computation, boolean shouldEnclose, @NotNull @NotNull Predicate<RESULT_TYPE> shouldManageResult) Perform a computation guarded by a newLivenessScopethat 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.shouldManageResult- Whether its necessary to manage the result with the enclosing LivenessScope. Will be invoked exactly once.- Returns:
- The result of
computation.get()
-
computeArrayEnclosed
@Deprecated 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) Deprecated.Perform a computation guarded by a newLivenessScopethat is released before this method returns. The results of the computation are managed by the enclosingLivenessManager, as determined bypeek().Equivalent to
computeArrayEnclosed(computation, shouldEnclose.getAsBoolean(), shouldManageResult).- 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()
-
computeArrayEnclosed
public static <RESULT_TYPE extends LivenessReferent> RESULT_TYPE[] computeArrayEnclosed(@NotNull @NotNull Supplier<RESULT_TYPE[]> computation, boolean shouldEnclose, @NotNull @NotNull Predicate<RESULT_TYPE> shouldManageResult) Perform a computation guarded by a newLivenessScopethat 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.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()
-
computeArrayEnclosed(Supplier, boolean, Predicate)