Interface IScriptEngine

All Known Subinterfaces:
IDebugEngine, IPythonDebugEngine, IReplEngine
All Known Implementing Classes:
AbstractReplScriptEngine, AbstractScriptEngine, ArchiveEngine, JVMCompiledScriptEngine, JythonScriptEngine, NashornScriptEngine, Py4jDebuggerEngine, Py4jScriptEngine, RhinoScriptEngine, TestSuiteScriptEngine

public interface IScriptEngine
Interface for a script engine. A script engine is capable of interpreting script code at runtime. Script engines shall be derived from Thread and therefore run separately from other code. An engine shall be started by calling schedule().
  • Field Details

    • TRACE_SCRIPT_ENGINE

      static final boolean TRACE_SCRIPT_ENGINE
      Trace enablement for script engines.
  • Method Details

    • execute

      ScriptResult execute(Object content)
      Execute script code. The code provided will be scheduled and executed as soon as all previously scheduled code is executed. If content is a Reader object, or a File special treatment is done, otherwise the toString() method is used to extract script code. This is a non-blocking call.
      Parameters:
      content - content to be executed.
      Returns:
      execution result
    • inject

      Object inject(Object content, boolean uiThread) throws ExecutionException
      Inject script code and execute synchronously. Code passed to this method will be invoked immediately. It might interrupt a currently running execution requested asynchronously.
      Parameters:
      content - content to be executed.
      uiThread - execute code in UI thread
      Returns:
      execution result
      Throws:
      ExecutionException - when code execution failed
    • getExecutedFile

      Object getExecutedFile()
      Get the currently executed file instance.
      Returns:
      currently executed file
    • setOutputStream

      void setOutputStream(OutputStream outputStream)
      Set the default output stream for the interpreter.
      Parameters:
      outputStream - default output stream
    • setErrorStream

      void setErrorStream(OutputStream errorStream)
      Set the default error stream for the interpreter.
      Parameters:
      errorStream - default error stream
    • setInputStream

      void setInputStream(InputStream inputStream)
      Set the default input stream for the interpreter.
      Parameters:
      inputStream - default input stream
    • getOutputStream

      PrintStream getOutputStream()
    • getErrorStream

      PrintStream getErrorStream()
    • getInputStream

      InputStream getInputStream()
    • setCloseStreamsOnTerminate

      void setCloseStreamsOnTerminate(boolean closeStreams)
      Set marker to automatically close I/O streams when engine is terminated.
      Parameters:
      closeStreams - true to close streams
    • schedule

      void schedule()
      Schedule script execution. This will start the script engine that either waits for input or immediate starts execution of previously scheduled input.
    • terminate

      void terminate()
      Terminate this interpreter. Addresses a request to terminate current script execution. When the request will be handled is implementation specific.
    • terminateCurrent

      void terminateCurrent()
      Stops the currently executed piece of code. Will continue to execute the next scheduled piece of code.
    • addExecutionListener

      void addExecutionListener(IExecutionListener listener)
    • removeExecutionListener

      void removeExecutionListener(IExecutionListener listener)
    • getName

      String getName()
      Get the engine name.
      Returns:
      engine name
    • setVariable

      void setVariable(String name, Object content)
      Set a variable in the script engine. This variable will be stored in the global script scope
      Parameters:
      name - variable name
      content - variable content
    • getVariable

      Object getVariable(String name)
      Get a script variable. Retrieve a variable from the global script scope.
      Parameters:
      name - variable name
      Returns:
      variable content or null
    • hasVariable

      boolean hasVariable(String name)
      Check if a variable exists within the scope of the engine. As a variable content may be null, getVariable(String) might not be sufficient to query.
      Parameters:
      name - variable name
      Returns:
      true when variable exists
    • getDescription

      EngineDescription getDescription()
      Get engine description for current engine.
      Returns:
      engine description
    • getVariables

      Map<String,Object> getVariables()
      Get all variables from the scope.
      Returns:
      map of variables
    • registerJar

      void registerJar(URL url)
      Register a jar file and add it to the classpath. After registering, classes within the jar file shall be usable within the script.
      Parameters:
      url - url to load jar file from
    • joinEngine

      void joinEngine(long timeout) throws InterruptedException
      Join engine execution thread. Waits for engine execution up to timeout milliseconds.
      Parameters:
      timeout - command timeout in milliseconds
      Throws:
      InterruptedException - when join command got interrupted
    • joinEngine

      void joinEngine() throws InterruptedException
      Join engine execution thread. Waits for engine termination.
      Throws:
      InterruptedException - when join command got interrupted
    • isFinished

      boolean isFinished()
      Verify that engine was started and terminated.
      Returns:
      true when engine ran and terminated
    • addSecurityCheck

      void addSecurityCheck(ISecurityCheck.ActionType type, ISecurityCheck check)
      Add a dedicated security check for a certain script action. If the check was already registered for this action, no further check will be added.
      Parameters:
      type - action type to add check for
      check - check to register
    • getLaunch

      org.eclipse.debug.core.ILaunch getLaunch()
      Get the launch that was used to create this engine.
      Returns:
      launch or null in case this engine was created without launch configuration