Interface ScriptSession

All Known Implementing Classes:
IrisDbGroovySession, IrisDbNoLanguageSession, IrisDbPythonSession

public interface ScriptSession
Interface for interactive console script sessions.
  • Method Details

    • getVariable

      Object getVariable​(String name) throws QueryScope.MissingVariableException
      Retrieve a variable from the script session's bindings.
      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
    • evaluate

      void evaluate​(String command)
      Evaluates command in the context of the current ScriptSession.
      Parameters:
      command - the command to evaluate
    • evaluate

      void evaluate​(String command, @Nullable String scriptName)
      Evaluates command in the context of the current ScriptSession.
      Parameters:
      command - the command to evaluate
      scriptName - an optional script name, which may be ignored by the implementation, or used improve error messages or for other internal purposes
    • 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, 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
    • onPersistentQueryInitializationBegin

      void onPersistentQueryInitializationBegin​(Supplier<ScriptPathLoader> pathLoader, ScriptPathLoaderState scriptLoaderState)
      Called before PersistentQuery initialization, should setup sourcing from the controller (as required).
    • onPersistentQueryInitializationEnd

      void onPersistentQueryInitializationEnd()
      Called after PersistentQuery initialization.
    • setScriptPathLoader

      void setScriptPathLoader​(Supplier<ScriptPathLoader> scriptPathLoader, boolean caching)
      Sets the scriptPathLoader that is in use for this session.
      Parameters:
      scriptPathLoader - a supplier of a script path loader
      caching - whether the source operation should cache results
    • clearScriptPathLoader

      void clearScriptPathLoader()
      Removes the currently configured script path loader from this script.
    • setUseOriginalScriptLoaderState

      boolean setUseOriginalScriptLoaderState​(boolean useOriginal)
      Informs the session whether or not we should be using the original ScriptLoaderState for source commands.
      Parameters:
      useOriginal - whether to use the script loader state at persistent query initialization