Package io.deephaven.engine.util
Interface ScriptSession
- All Superinterfaces:
LivenessManager,LivenessNode,LivenessReferent,ReleasableLivenessManager
- All Known Implementing Classes:
AbstractScriptSession,DelegatingScriptSession,GroovyDeephavenSession,NoLanguageDeephavenSession,PythonDeephavenSession
Interface for interactive console script sessions.
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic classstatic interface -
Method Summary
Modifier and TypeMethodDescriptiondefault ScriptSession.ChangesevaluateScript(String script) Evaluates the script and manages liveness of objects that are exported to the user.evaluateScript(String script, @Nullable String scriptName) Evaluates the script and manages liveness of objects that are exported to the user.evaluateScript(Path scriptPath) Evaluates the script and manages liveness of objects that are exported to the user.Obtain anExecutionContextinstance for the current script session.@NotNull ObjectgetVariable(String name) Retrieve a variable from the script session's bindings.<T> TgetVariable(String name, T defaultValue) Retrieve a variable from the script session's bindings.Retrieves all of the variable names present in the session's scopeAVariableProviderinstance, for services like autocomplete which may want a limited "just the variables" view of our session state.Retrieves all of the variables present in the session's scope (e.g., Groovy binding, Python globals()).booleanhasVariableName(String name) Check if the scope has the given variable namevoidObserve (and report viaonScopeChanges) any changes to this ScriptSession'sQueryScopethat may have been made externally, rather than duringscript evaluation.default ThrowableIf this script session can throw unserializable exceptions, this method is responsible for turning those exceptions into something suitable for sending back to a client.voidsetVariable(String name, @Nullable Object value) Inserts a value into the script's scope.default ObjectunwrapObject(Object object) Asks the session to remove any wrapping that exists on scoped objects so that clients can fetch them.Methods inherited from interface io.deephaven.engine.liveness.LivenessManager
manage, tryManageMethods inherited from interface io.deephaven.engine.liveness.LivenessNode
tryUnmanage, tryUnmanage, unmanage, unmanageMethods inherited from interface io.deephaven.engine.liveness.LivenessReferent
dropReference, getReferentDescription, getWeakReference, retainReference, tryRetainReferenceMethods inherited from interface io.deephaven.engine.liveness.ReleasableLivenessManager
release
-
Method Details
-
getVariable
Retrieve a variable from the script session's bindings. Please usegetVariable(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
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 retrievedefaultValue- 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()AVariableProviderinstance, 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 anExecutionContextinstance for the current script session. This is the execution context that is used when executing scripts. -
observeScopeChanges
void observeScopeChanges()Observe (and report viaonScopeChanges) any changes to this ScriptSession'sQueryScopethat may have been made externally, rather than duringscript evaluation.- ApiNote:
- This method should be regarded as an unstable API
-
evaluateScript
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
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 executescriptName- 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
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
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
Retrieves all of the variable names present in the session's scope- Returns:
- an unmodifiable set of variable names
-
hasVariableName
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
Inserts a value into the script's scope.- Parameters:
name- the variable name to setvalue- the new value of the variable
-
scriptType
String scriptType()- Returns:
- a textual description of this script session's language for use in messages.
-
sanitizeThrowable
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
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
-