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
Nested ClassesModifier and TypeClassDescriptionclassprotected static interfaceNested classes/interfaces inherited from interface io.deephaven.engine.util.ScriptSession
ScriptSession.Changes, ScriptSession.Listener -
Field Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAbstractScriptSession(UpdateGraph updateGraph, OperationInitializer operationInitializer, ObjectTypeLookup objectTypeLookup, @Nullable ScriptSession.Listener changeListener) protectedAbstractScriptSession(UpdateGraph updateGraph, OperationInitializer operationInitializer, ObjectTypeLookup objectTypeLookup, @Nullable ScriptSession.Listener changeListener, @NotNull File classCacheDirectory, @NotNull ClassLoader parentClassLoader) -
Method Summary
Modifier and TypeMethodDescriptionprotected voidapplyVariableChangeToDiff(ScriptSession.Changes diff, String name, @Nullable Object fromValue, @Nullable Object toValue) voidcleanup()Releases all resources and persistent external state associated with this script session.protected abstract ScriptSession.ChangescreateDiff(S from, S to, RuntimeException e) static voidprotected voiddestroy()Attempt to release (destructively when necessary) resources held by this object.protected abstract Sprotected abstract voidEvaluates command in the context of the current ScriptSession.final ScriptSession.ChangesevaluateScript(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 anExecutionContextinstance for the current script session.Provides access to the query scope defined by the state in this script session.protected abstract <T> TgetVariable(String name) Retrieve a variable from the script session's bindings.Retrieves all variable names present in the session's scope.protected abstract booleanhasVariable(String name) Check if the scope has the given variable name.protected static PathvoidObserve (and report viaonScopeChanges) any changes to this ScriptSession'sQueryScopethat may have been made externally, rather than duringscript evaluation.protected voidprotected abstract ObjectsetVariable(String name, @Nullable Object value) Inserts a value into the script's scope.protected abstract SMethods inherited from class io.deephaven.engine.liveness.LivenessArtifact
manageWithCurrentScopeMethods inherited from class io.deephaven.engine.liveness.ReferenceCountedLivenessNode
getWeakReference, initializeTransientFieldsForLiveness, onReferenceCountAtZero, tryManage, tryUnmanage, tryUnmanageMethods inherited from class io.deephaven.engine.liveness.ReferenceCountedLivenessReferent
dropReference, tryRetainReferenceMethods inherited from class io.deephaven.util.referencecounting.ReferenceCounted
append, decrementReferenceCount, forceReferenceCountToZero, getReferenceCountDebug, incrementReferenceCount, resetReferenceCount, toString, tryDecrementReferenceCount, tryIncrementReferenceCountMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface io.deephaven.engine.liveness.LivenessManager
manage, tryManage, tryUnmanage, tryUnmanage, unmanage, unmanageMethods inherited from interface io.deephaven.engine.liveness.LivenessReferent
dropReference, getReferentDescription, getWeakReference, retainReference, tryRetainReferenceMethods 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() -
cleanup
public void cleanup()Description copied from interface:ScriptSessionReleases all resources and persistent external state associated with this script session.Implementations of
ScriptSessionmay create state outside of the JVM (e.g. on-disk caches or temporary directories) that is not automatically cleaned up. If left unmanaged, this state may persist even after the session is no longer in use.This method should be called when the session is no longer needed to ensure that any external resources are properly released.
- Specified by:
cleanupin interfaceScriptSession
-
getExecutionContext
Description copied from interface:ScriptSessionObtain anExecutionContextinstance for the current script session. This is the execution context that is used when executing scripts.- Specified by:
getExecutionContextin interfaceScriptSession
-
publishInitial
protected void publishInitial() -
observeScopeChanges
public void observeScopeChanges()Description copied from interface:ScriptSessionObserve (and report viaonScopeChanges) any changes to this ScriptSession'sQueryScopethat may have been made externally, rather than duringscript evaluation.- Specified by:
observeScopeChangesin interfaceScriptSession
-
emptySnapshot
-
takeSnapshot
-
createDiff
-
evaluateScript
public final ScriptSession.Changes evaluateScript(String script, @Nullable @Nullable String scriptName) Description copied from interface:ScriptSessionEvaluates 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:
evaluateScriptin 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:ScriptSessionEvaluates 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:
evaluateScriptin interfaceScriptSession- Parameters:
scriptPath- the path to the script to execute- Returns:
- the changes made to the exportable objects
-
destroy
@OverridingMethodsMustInvokeSuper protected void destroy()Description copied from class:ReferenceCountedLivenessReferentAttempt 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:
destroyin 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:ScriptSessionProvides access to the query scope defined by the state in this script session.- Specified by:
getQueryScopein 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.
-