Interface ScriptSession

All Superinterfaces:
LivenessManager, LivenessNode, LivenessReferent, ReleasableLivenessManager
All Known Implementing Classes:
AbstractScriptSession, DelegatingScriptSession, GroovyDeephavenSession, NoLanguageDeephavenSession, PythonDeephavenSession

public interface ScriptSession extends ReleasableLivenessManager, LivenessNode
Interface for interactive console script sessions.
  • Method Details

    • getVariable

      @NotNull @NotNull Object getVariable(String name) throws QueryScope.MissingVariableException
      Retrieve a variable from the script session's bindings.

      Please use getVariable(String, Object) if you expect the variable may not exist.

      Parameters:
      name - the variable to retrieve
      Returns:
      the variable
      Throws:
      QueryScope.MissingVariableException - if the variable does not exist
    • getVariable

      <T> T getVariable(String name, T defaultValue)
      Retrieve a variable from the script session's bindings. If the variable is not present, return defaultValue. If the variable is present, but is not of type (T), a ClassCastException may result.
      Type Parameters:
      T - the type of the variable
      Parameters:
      name - the variable to retrieve
      defaultValue - the value to use when no value is present in the session's scope
      Returns:
      the value of the variable, or defaultValue if not present
    • getVariableProvider

      VariableProvider getVariableProvider()
      A VariableProvider instance, for services like autocomplete which may want a limited "just the variables" view of our session state.
      Returns:
      a VariableProvider instance backed by the global/binding context of this script session.
    • getExecutionContext

      ExecutionContext getExecutionContext()
      Obtain an ExecutionContext instance for the current script session. This is the execution context that is used when executing scripts.
    • observeScopeChanges

      void observeScopeChanges()
      Observe (and report via onScopeChanges) any changes to this ScriptSession's QueryScope that may have been made externally, rather than during script evaluation.
      ApiNote:
      This method should be regarded as an unstable API
    • evaluateScript

      default ScriptSession.Changes evaluateScript(String script)
      Evaluates the script and manages liveness of objects that are exported to the user. This method should be called from the serial executor as it manipulates static state.
      Parameters:
      script - the code to execute
      Returns:
      the changes made to the exportable objects
    • evaluateScript

      ScriptSession.Changes evaluateScript(String script, @Nullable @Nullable String scriptName)
      Evaluates the script and manages liveness of objects that are exported to the user. This method should be called from the serial executor as it manipulates static state.
      Parameters:
      script - the code to execute
      scriptName - an optional script name, which may be ignored by the implementation, or used improve error messages or for other internal purposes
      Returns:
      the changes made to the exportable objects
    • evaluateScript

      ScriptSession.Changes evaluateScript(Path scriptPath)
      Evaluates the script and manages liveness of objects that are exported to the user. This method should be called from the serial executor as it manipulates static state.
      Parameters:
      scriptPath - the path to the script to execute
      Returns:
      the changes made to the exportable objects
    • getVariables

      Map<String,Object> getVariables()
      Retrieves all of the variables present in the session's scope (e.g., Groovy binding, Python globals()).
      Returns:
      an unmodifiable map with variable names as the keys, and the Objects as the result
    • getVariableNames

      Set<String> getVariableNames()
      Retrieves all of the variable names present in the session's scope
      Returns:
      an unmodifiable set of variable names
    • hasVariableName

      boolean hasVariableName(String name)
      Check if the scope has the given variable name
      Parameters:
      name - the variable name
      Returns:
      True iff the scope has the given variable name
    • setVariable

      void setVariable(String name, @Nullable @Nullable Object value)
      Inserts a value into the script's scope.
      Parameters:
      name - the variable name to set
      value - the new value of the variable
    • scriptType

      String scriptType()
      Returns:
      a textual description of this script session's language for use in messages.
    • sanitizeThrowable

      default Throwable sanitizeThrowable(Throwable e)
      If this script session can throw unserializable exceptions, this method is responsible for turning those exceptions into something suitable for sending back to a client.
      Parameters:
      e - the exception to (possibly) sanitize
      Returns:
      the sanitized exception
    • unwrapObject

      default Object unwrapObject(Object object)
      Asks the session to remove any wrapping that exists on scoped objects so that clients can fetch them. Defaults to returning the object itself.
      Parameters:
      object - the scoped object
      Returns:
      an obj which can be consumed by a client