Package io.deephaven.engine.util
Class GroovyDeephavenSession
- All Implemented Interfaces:
LogOutputAppendable
,LivenessManager
,LivenessNode
,LivenessReferent
,ScriptSession
,Serializable
public class GroovyDeephavenSession
extends AbstractScriptSession<GroovyDeephavenSession.GroovySnapshot>
Groovy
ScriptSession
. Not safe for concurrent use.- See Also:
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
static class
static class
static interface
Represents an import that can be added to an ImportCustomizer, as a valid return fromcreateImport(String)
.protected static class
static interface
static class
Nested classes/interfaces inherited from class io.deephaven.engine.util.AbstractScriptSession
AbstractScriptSession.ScriptSessionQueryScope, AbstractScriptSession.Snapshot
Nested classes/interfaces inherited from interface io.deephaven.engine.util.ScriptSession
ScriptSession.Changes, ScriptSession.Listener
-
Field Summary
Fields inherited from class io.deephaven.engine.util.AbstractScriptSession
classCacheDirectory, executionContext
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addScriptImportClass
(Class<?> c) void
void
addScriptImportStatic
(Class<?> c) void
protected ScriptSession.Changes
createDiff
(GroovyDeephavenSession.GroovySnapshot from, GroovyDeephavenSession.GroovySnapshot to, RuntimeException e) createImport
(String importString) Ensure that the given importString is valid.protected GroovyDeephavenSession.GroovySnapshot
protected void
Evaluates command in the context of the current ScriptSession.static InputStream
findScript
(String relativePath) getAllValues
(@Nullable Function<Object, T> valueMapper, QueryScope.ParamFilter<T> filter) Returns a mutable map with all known variables and their values.groovy.lang.Binding
groovy.lang.GroovyShell
getShell()
protected <T> T
getVariable
(String name) Retrieve a variable from the script session's bindings.Retrieves all variable names present in the session's scope.boolean
hasExecutedScript
(String scriptName) protected boolean
hasVariable
(String name) Check if the scope has the given variable name.static GroovyDeephavenSession
of
(UpdateGraph updateGraph, OperationInitializer operationInitializer, ObjectTypeLookup objectTypeLookup, @Nullable ScriptSession.Listener changeListener, GroovyDeephavenSession.RunScripts runScripts) static GroovyDeephavenSession
of
(UpdateGraph updateGraph, OperationInitializer operationInitializer, ObjectTypeLookup objectTypeLookup, GroovyDeephavenSession.RunScripts runScripts) static String
Remove comments from an import statement.void
void
runScriptOnce
(String script) 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.protected Object
setVariable
(String name, @Nullable Object newValue) Inserts a value into the script's scope.protected GroovyDeephavenSession.GroovySnapshot
Methods inherited from class io.deephaven.engine.util.AbstractScriptSession
applyVariableChangeToDiff, createScriptCache, destroy, evaluateScript, evaluateScript, getExecutionContext, getQueryScope, newClassCacheLocation, observeScopeChanges, publishInitial
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, unwrapObject
-
Field Details
-
SCRIPT_TYPE
- See Also:
-
-
Method Details
-
of
public static GroovyDeephavenSession of(UpdateGraph updateGraph, OperationInitializer operationInitializer, ObjectTypeLookup objectTypeLookup, GroovyDeephavenSession.RunScripts runScripts) throws IOException - Throws:
IOException
-
of
public static GroovyDeephavenSession of(UpdateGraph updateGraph, OperationInitializer operationInitializer, ObjectTypeLookup objectTypeLookup, @Nullable @Nullable ScriptSession.Listener changeListener, GroovyDeephavenSession.RunScripts runScripts) throws IOException - Throws:
IOException
-
findScript
- Throws:
IOException
-
runScript
- Throws:
IOException
-
hasExecutedScript
-
runScriptOnce
- Throws:
IOException
-
getVariable
Description copied from class:AbstractScriptSession
Retrieve a variable from the script session's bindings. Values may need to be unwrapped.- Specified by:
getVariable
in classAbstractScriptSession<GroovyDeephavenSession.GroovySnapshot>
- Parameters:
name
- the name of the variable to retrieve- Returns:
- the variable value
-
evaluate
Description copied from class:AbstractScriptSession
Evaluates command in the context of the current ScriptSession.- Specified by:
evaluate
in classAbstractScriptSession<GroovyDeephavenSession.GroovySnapshot>
- 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
-
removeComments
Remove comments from an import statement. /* comments take precedence over eol (//) comments. This ignores escaping and quoting, as they are not valid in an import statement.- Parameters:
s
- import statement string from which to remove comments- Returns:
- the input string with comments removed, and whitespace trimmed
-
createImport
@VisibleForTesting public Optional<GroovyDeephavenSession.GroovyImport> createImport(String importString) Ensure that the given importString is valid. Return a canonical version of the import string if it is valid.- Parameters:
importString
- the string to check. importString is "[import] [static] package.class[.innerclass...][.field|.method][.*][;]".- Returns:
- null if importString is not valid, else a string of the form "import [static] package.class.part.part[.*];"
-
addScriptImportClass
-
addScriptImportClass
-
addScriptImportStatic
-
addScriptImportStatic
-
emptySnapshot
- Specified by:
emptySnapshot
in classAbstractScriptSession<GroovyDeephavenSession.GroovySnapshot>
-
takeSnapshot
- Specified by:
takeSnapshot
in classAbstractScriptSession<GroovyDeephavenSession.GroovySnapshot>
-
createDiff
protected ScriptSession.Changes createDiff(GroovyDeephavenSession.GroovySnapshot from, GroovyDeephavenSession.GroovySnapshot to, RuntimeException e) - Specified by:
createDiff
in classAbstractScriptSession<GroovyDeephavenSession.GroovySnapshot>
-
getVariableNames
Description copied from class:AbstractScriptSession
Retrieves all variable names present in the session's scope.- Specified by:
getVariableNames
in classAbstractScriptSession<GroovyDeephavenSession.GroovySnapshot>
- Returns:
- a caller-owned mutable set of variable names
-
hasVariable
Description copied from class:AbstractScriptSession
Check if the scope has the given variable name.- Specified by:
hasVariable
in classAbstractScriptSession<GroovyDeephavenSession.GroovySnapshot>
- Parameters:
name
- the variable name- Returns:
- True iff the scope has the given variable name
-
setVariable
Description copied from class:AbstractScriptSession
Inserts a value into the script's scope.- Specified by:
setVariable
in classAbstractScriptSession<GroovyDeephavenSession.GroovySnapshot>
- Parameters:
name
- the variable name to setnewValue
- the new value of the variable- Returns:
- the old value for this name, if any. As with
AbstractScriptSession.getVariable(String)
, may need to be unwrapped.
-
getAllValues
protected <T> Map<String,T> getAllValues(@Nullable @Nullable Function<Object, T> valueMapper, @NotNull QueryScope.ParamFilter<T> filter) Description copied from class:AbstractScriptSession
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.- Specified by:
getAllValues
in classAbstractScriptSession<GroovyDeephavenSession.GroovySnapshot>
- 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
AbstractScriptSession.getVariable(String)
, values may need to be unwrapped.
-
getBinding
public groovy.lang.Binding getBinding() -
getShell
public groovy.lang.GroovyShell getShell() -
scriptType
- Returns:
- a textual description of this script session's language for use in messages.
-
sanitizeThrowable
Description copied from interface:ScriptSession
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
-