Class LivenessScopeStack

java.lang.Object
io.deephaven.engine.liveness.LivenessScopeStack

public class LivenessScopeStack extends Object

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 Details

    • push

      public static void push(@NotNull @NotNull LivenessScope scope)

      Push a scope onto the current thread's scope stack.

      Parameters:
      scope - The scope
    • pop

      public static void pop(@NotNull @NotNull LivenessScope scope)

      Pop a scope from the current thread's scope stack.

      Must be the current top of the stack.

      Parameters:
      scope - The scope
    • peek

      @NotNull public 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.

      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 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 scope
      releaseOnClose - Whether the scope should be released when the result is closed
      Returns:
      A SafeCloseable whose SafeCloseable.close() method invokes pop(LivenessScope) for the scope (followed by LivenessScope.release() if releaseOnClose is true)
    • open

      @NotNull public static @NotNull SafeCloseable open()

      Push an anonymous scope onto the scope stack, and get an SafeCloseable that pops it and then LivenessScope.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 whose SafeCloseable.close() method invokes pop(LivenessScope) for the scope, followed by LivenessScope.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 new LivenessScope that is released before this method returns. The result of the computation is managed by the enclosing LivenessManager, as determined by peek().
      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 new LivenessScope that is released before this method returns. The results of the computation are managed by the enclosing LivenessManager, as determined by peek().
      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()