Package io.deephaven.engine.util
Class AbstractScriptSession<S extends AbstractScriptSession.Snapshot>
- All Implemented Interfaces:
LogOutputAppendable
,LivenessManager
,LivenessNode
,LivenessReferent
,ScriptSession
,Serializable
- Direct Known Subclasses:
GroovyDeephavenSession
,NoLanguageDeephavenSession
,PythonDeephavenSession
public abstract class AbstractScriptSession<S extends AbstractScriptSession.Snapshot>
extends LivenessArtifact
implements ScriptSession
This class exists to make all script sessions to be liveness artifacts, and provide a default implementation for
evaluateScript which handles liveness and diffs in a consistent way.
- See Also:
-
Nested Class Summary
Modifier and TypeClassDescriptionclass
protected static interface
Nested classes/interfaces inherited from interface io.deephaven.engine.util.ScriptSession
ScriptSession.Changes, ScriptSession.Listener
-
Field Summary
-
Constructor Summary
ModifierConstructorDescriptionprotected
AbstractScriptSession
(UpdateGraph updateGraph, OperationInitializer operationInitializer, ObjectTypeLookup objectTypeLookup, @Nullable ScriptSession.Listener changeListener) protected
AbstractScriptSession
(UpdateGraph updateGraph, OperationInitializer operationInitializer, ObjectTypeLookup objectTypeLookup, @Nullable ScriptSession.Listener changeListener, @NotNull File classCacheDirectory, @NotNull ClassLoader parentClassLoader) -
Method Summary
Modifier and TypeMethodDescriptionprotected void
applyVariableChangeToDiff
(ScriptSession.Changes diff, String name, @Nullable Object fromValue, @Nullable Object toValue) protected abstract ScriptSession.Changes
createDiff
(S from, S to, RuntimeException e) static void
protected void
destroy()
Attempt to release (destructively when necessary) resources held by this object.protected abstract S
protected abstract void
Evaluates command in the context of the current ScriptSession.final ScriptSession.Changes
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.getAllValues
(@Nullable Function<Object, T> valueMapper, QueryScope.ParamFilter<T> filter) Returns a mutable map with all known variables and their values.Obtain anExecutionContext
instance for the current script session.Provides access to the query scope defined by the state in this script session.protected abstract <T> T
getVariable
(String name) Retrieve a variable from the script session's bindings.Retrieves all variable names present in the session's scope.protected abstract boolean
hasVariable
(String name) Check if the scope has the given variable name.protected static Path
void
Observe (and report viaonScopeChanges
) any changes to this ScriptSession'sQueryScope
that may have been made externally, rather than duringscript evaluation
.protected void
protected abstract Object
setVariable
(String name, @Nullable Object value) Inserts a value into the script's scope.protected abstract S
Methods inherited from class io.deephaven.engine.liveness.LivenessArtifact
manageWithCurrentScope
Methods inherited from class io.deephaven.engine.liveness.ReferenceCountedLivenessNode
getWeakReference, initializeTransientFieldsForLiveness, onReferenceCountAtZero, tryManage, tryUnmanage, tryUnmanage
Methods inherited from class io.deephaven.engine.liveness.ReferenceCountedLivenessReferent
dropReference, tryRetainReference
Methods inherited from class io.deephaven.util.referencecounting.ReferenceCounted
append, decrementReferenceCount, forceReferenceCountToZero, getReferenceCountDebug, incrementReferenceCount, resetReferenceCount, toString, tryDecrementReferenceCount, tryIncrementReferenceCount
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface io.deephaven.engine.liveness.LivenessManager
manage, tryManage
Methods inherited from interface io.deephaven.engine.liveness.LivenessNode
tryUnmanage, tryUnmanage, unmanage, unmanage
Methods inherited from interface io.deephaven.engine.liveness.LivenessReferent
dropReference, getReferentDescription, getWeakReference, retainReference, tryRetainReference
Methods inherited from interface io.deephaven.engine.util.ScriptSession
evaluateScript, sanitizeThrowable, scriptType, unwrapObject
-
Field Details
-
classCacheDirectory
-
executionContext
-
-
Constructor Details
-
AbstractScriptSession
protected AbstractScriptSession(UpdateGraph updateGraph, OperationInitializer operationInitializer, ObjectTypeLookup objectTypeLookup, @Nullable @Nullable ScriptSession.Listener changeListener) -
AbstractScriptSession
protected AbstractScriptSession(UpdateGraph updateGraph, OperationInitializer operationInitializer, ObjectTypeLookup objectTypeLookup, @Nullable @Nullable ScriptSession.Listener changeListener, @NotNull @NotNull File classCacheDirectory, @NotNull @NotNull ClassLoader parentClassLoader)
-
-
Method Details
-
newClassCacheLocation
-
createScriptCache
public static void createScriptCache() -
getExecutionContext
Description copied from interface:ScriptSession
Obtain anExecutionContext
instance for the current script session. This is the execution context that is used when executing scripts.- Specified by:
getExecutionContext
in interfaceScriptSession
-
publishInitial
protected void publishInitial() -
observeScopeChanges
public void observeScopeChanges()Description copied from interface:ScriptSession
Observe (and report viaonScopeChanges
) any changes to this ScriptSession'sQueryScope
that may have been made externally, rather than duringscript evaluation
.- Specified by:
observeScopeChanges
in interfaceScriptSession
-
emptySnapshot
-
takeSnapshot
-
createDiff
-
evaluateScript
public final ScriptSession.Changes evaluateScript(String script, @Nullable @Nullable String scriptName) Description copied from interface:ScriptSession
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.- Specified by:
evaluateScript
in interfaceScriptSession
- 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
-
applyVariableChangeToDiff
protected void applyVariableChangeToDiff(ScriptSession.Changes diff, String name, @Nullable @Nullable Object fromValue, @Nullable @Nullable Object toValue) -
evaluateScript
Description copied from interface:ScriptSession
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.- Specified by:
evaluateScript
in interfaceScriptSession
- Parameters:
scriptPath
- the path to the script to execute- Returns:
- the changes made to the exportable objects
-
destroy
protected void destroy()Description copied from class:ReferenceCountedLivenessReferent
Attempt to release (destructively when necessary) resources held by this object. This may render the object unusable for subsequent operations. Implementations should be sure to call super.destroy().This is intended to only ever be used as a side effect of decreasing the reference count to 0.
- Overrides:
destroy
in classReferenceCountedLivenessReferent
-
evaluate
Evaluates command in the context of the current ScriptSession.- Parameters:
command
- the command to evaluatescriptName
- an optional script name, which may be ignored by the implementation, or used improve error messages or for other internal purposes
-
getQueryScope
Description copied from interface:ScriptSession
Provides access to the query scope defined by the state in this script session.- Specified by:
getQueryScope
in interfaceScriptSession
- Returns:
- an implementation defined QueryScope, allowing access to state in the script session
-
getVariable
Retrieve a variable from the script session's bindings. Values may need to be unwrapped.- Parameters:
name
- the name of the variable to retrieve- Returns:
- the variable value
- Throws:
QueryScope.MissingVariableException
- if the variable does not exist
-
getVariableNames
Retrieves all variable names present in the session's scope.- Returns:
- a caller-owned mutable set of variable names
-
hasVariable
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- Returns:
- the old value for this name, if any. As with
getVariable(String)
, may need to be unwrapped.
-
getAllValues
protected abstract <T> Map<String,T> getAllValues(@Nullable @Nullable Function<Object, T> valueMapper, @NotNull QueryScope.ParamFilter<T> filter) Returns a mutable map with all known variables and their values.Callers may want to pass in a valueMapper of
ScriptSession.unwrapObject(Object)
which would unwrap values before filtering. The returned map is owned by the caller.- Type Parameters:
T
- the type of the mapped values- Parameters:
valueMapper
- a function to map the valuesfilter
- a predicate to filter the map entries- Returns:
- a caller-owned mutable map with all known variables and their mapped values. As with
getVariable(String)
, values may need to be unwrapped.
-