Package gda.jython

Interface ICommandRunner

All Known Implementing Classes:
JythonServerFacade, MockJythonServerFacade

public interface ICommandRunner
Interface used by some classes to run a simple Jython command Provided to ensure loose coupling between callers and command runner implementation

 Runner           Blocking  Interruptible  Script lock Throws exception
 evaluateCommand    Yes           No            No                      No
 runCommand          No          Yes            No            No
 runScript           No          Yes           Yes            No
 runsource          Yes          Yes            No            No
 executeCommand   Yes          Yes            No            Yes
Blocking: This will not return until the command or script has finished running. If it takes a long time to run, it will hang the thread which calls this method, so this it must be called in a separate thread from the main GUI thread, else the GUI will seize up until the command has returned. Interruptible: Thread can be interrupted. If the command takes a long time to run, stopping a scan, script or doing a 'stop all' will interrupt the thread. Script lock: Acquire the script lock and run the script, or return BUSY without running the script, if the lock already has already been acquired. This allows script locked scripts to ensure only one will ever be running at once.
  • Method Details

    • runCommand

      void runCommand(String command)
      Executes the Jython command in a new thread.

      Non-blocking, Interruptible, Not script locked.
      See ICommandRunner for the other options.
      Parameters:
      command - to run
    • executeCommand

      void executeCommand(String command) throws ScriptExecutionException
      Executes the Jython command in a new thread.

      Blocking, Interruptible, Not script locked and throws ScriptExecutionException
      Parameters:
      command -
      Throws:
      ScriptExecutionException
    • evaluateCommand

      String evaluateCommand(String command)
      Runs a single line Jython command through the interpreter and returns the result in the form of a string. Note: this method waits until the command has finished so it can return the result. If the command takes a long time it will hang the thread which calls this method. So this method must be called in a separate thread from the main GUI thread, else the GUI will seize up until the command given to this method has returned. For an example of the, see the gda.jython.JythonTerminal class.

      Blocking, Not interruptible, Not script locked.
      See ICommandRunner for the other options.
      Parameters:
      command - to run
      Returns:
      the string representation of the result
    • runScript

      CommandThreadEvent runScript(String scriptContents)
      Runs the jython command string, and changes the ScriptStatus as is goes.

      Non-blocking, Interruptible, Script locked.
      See ICommandRunner for the other options.
      Parameters:
      scriptContents - to run
      Returns:
      status
    • runScript

      CommandThreadEvent runScript(File script)
      Runs the Jython script, and changes the ScriptStatus as is goes.

      Non-blocking, Interruptible, Script locked.
      See ICommandRunner for the other options.
      Parameters:
      script - to run
      Returns:
      status
    • runsource

      boolean runsource(String command)
      Similar to runCommand(java.lang.String), except that a boolean is returned if the command was complete or if additional lines of a multi-line command are required. Used only by the JythonTerminal to determine which prompt to display. Note: this method waits until the command has finished so it can return the result. If the command takes a long time it will hang the thread which calls this method. So this method must be called in a separate thread from the main GUI thread, else the GUI will seize up until the command given to this method has returned.

      Blocking, Interruptible, Not script locked.
      See ICommandRunner for the other options.
      Parameters:
      command - to run
      Returns:
      true if command was incomplete and more is required (eg "if True:"), false otherwise (including on error)
      See Also:
    • locateScript

      String locateScript(String scriptToRun)
      Find a script with given name in the GDA's script project folders.
      Parameters:
      scriptToRun - The name of a Jython script file.
      Returns:
      A path to the script in one of the project folders. The first file with matching name will be returned, or null if no file could be located.