Package gda.jython

Interface Jython

All Superinterfaces:
Findable, gda.observable.IObservable
All Known Subinterfaces:
LocalJython
All Known Implementing Classes:
JythonServer

public interface Jython extends Findable, gda.observable.IObservable
The distributed interface for the JythonServer object. This interface should not be operated directly, but via the InterfaceProvider.
  • Field Details

    • SERVER_NAME

      static final String SERVER_NAME
      Name of this object. This should agree with the string used in Castor.
      See Also:
    • RAW_INPUT_REQUESTED

      static final String RAW_INPUT_REQUESTED
      String passed to IObservers of the CommandServer that it is waiting for input via the setRawInput method
      See Also:
    • RAW_INPUT_RECEIVED

      static final String RAW_INPUT_RECEIVED
      String passed to IObservers of the CommandServer that it has received input via the setRawInput method
      See Also:
  • Method Details

    • evaluateCommand

      String evaluateCommand(String command, String JSFIdentifier)
      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 - command to run
      JSFIdentifier - - the unique ID of the JythonServerFacade calling this method
      Returns:
      the string representation of the result
    • runCommand

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

      Non-blocking, Interruptible, Not script locked.
      See ICommandRunner for the other options.
      Parameters:
      command - to run
      JSFIdentifier - - the unique ID of the JythonServerFacade calling this method
    • executeCommand

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

      Blocking, Interruptible, Not script locked.
      See ICommandRunner for the other options.
      Parameters:
      command - to run
      JSFIdentifier -
      Throws:
      ScriptExecutionException - if there is an exception in the script
    • executeCommand

      void executeCommand(String command, String JSFIdentifier, InputStream stdin) throws ScriptExecutionException
      Executes the Jython command in a new thread with the provided stdin input stream.

      Blocking, Interruptible, Not script locked.
      See ICommandRunner for the other options.
      See executeCommand(String, String) for alternative using the RCP input stream
      Parameters:
      command - to run
      JSFIdentifier -
      stdin - an InputStream to use as the source of user input
      Throws:
      ScriptExecutionException - if there is an exception in the script
    • runScript

      CommandThreadEvent runScript(String command, String scriptName, String JSFIdentifier)
      Runs the Jython script, and changes the ScriptStatus as is goes.

      Non-blocking, Interruptible, Script locked.
      See ICommandRunner for the other options.
      Parameters:
      command - to run
      scriptName - used to acquire a lock
      JSFIdentifier - - the unique ID of the JythonServerFacade calling this method
      Returns:
      status
    • runsource

      boolean runsource(String command, String JSFIdentifier)
      Similar to runCommand(java.lang.String, 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
      JSFIdentifier - the unique ID of the JythonServerFacade calling this method
      Returns:
      true if command was incomplete and more is required (eg "if True:"), false otherwise (including on error)
      See Also:
    • runsource

      boolean runsource(String command, String JSFIdentifier, InputStream stdin)
      Similar to runsource(java.lang.String, java.lang.String) but allows a specific InputStream to be used.

      Blocking, Interruptible, Not script locked.
      See ICommandRunner for the other options.
      Parameters:
      command - to run
      JSFIdentifier - - the unique ID of the JythonServerFacade calling this method
      stdin - input stream to use as stdin for this command
      Returns:
      true if command was incomplete and more is required (eg "if True:"), false otherwise (including on error)
      See Also:
    • addFacade

      int addFacade(String JSFIdentifier, String hostName, String username, String fullName, String visitID) throws DeviceException
      For use by the JythonServerFacade class. Allows an instance of this class operating in a different process to remotely register itself with a JythonServer.
      Parameters:
      JSFIdentifier -
      hostName -
      username -
      fullName -
      visitID -
      Returns:
      the index number of the facade (i.e. its public key)
      Throws:
      DeviceException - - thrown if an error during authentication/authorisation
    • removeFacade

      void removeFacade(String uniqueFacadeName)
      Removes the registration of the facade with this server and returns the baton if applicable.
      Parameters:
      uniqueFacadeName -
    • switchUser

      void switchUser(String uniqueFacadeName, String username, String visitID) throws DeviceException
      For an already registered JythonServerFacade, changes information for that facade. This can change the permission level of this facade (and so this client) or the visit which data is savaed as when this client has the baton.
      Parameters:
      uniqueFacadeName -
      username -
      visitID -
      Throws:
      DeviceException
    • requestFinishEarly

      void requestFinishEarly(String JSFIdentifier)
      Cleanly stops the current scan.
      Parameters:
      JSFIdentifier - - the unique ID of the JythonServerFacade calling this method.
    • isFinishEarlyRequested

      boolean isFinishEarlyRequested()
      Returns:
      true if the current scan has had requestFinishEarly called on it.
    • beamlineHalt

      void beamlineHalt(String JSFIdentifier)
      Stops all scripts, scans, and commands immediately. Also calls the stop method on all motors.
      Parameters:
      JSFIdentifier - - the unique ID of the JythonServerFacade calling this method.
    • abortCommands

      void abortCommands(String JSFIdentifier)
      Stops all scripts, scans, and commands running from the Jython Server immediately.
      Parameters:
      JSFIdentifier - - the unique ID of the JythonServerFacade calling this method.
    • pauseCurrentScan

      void pauseCurrentScan(String JSFIdentifier)
      Pauses the current scan
      Parameters:
      JSFIdentifier - - the unique ID of the JythonServerFacade calling this method.
    • pauseCurrentScript

      void pauseCurrentScript(String JSFIdentifier)
      Pauses the current script the next time it calls the ScriptBase.checkForPuases method until resumeCurrentScript is called.
      Parameters:
      JSFIdentifier - - the unique ID of the JythonServerFacade calling this method.
    • resumeCurrentScan

      void resumeCurrentScan(String JSFIdentifier)
      Resumes the currently paused scan.
      Parameters:
      JSFIdentifier - - the unique ID of the JythonServerFacade calling this method.
    • restartCurrentScan

      void restartCurrentScan(String JSFIdentifier)
      Restarts the last scan which was run, if it ended due to an error or it was interrupted. If the last scan completed successfully, then this will do nothing.
      Parameters:
      JSFIdentifier - - the unique ID of the JythonServerFacade calling this method.
    • resumeCurrentScript

      void resumeCurrentScript(String JSFIdentifier)
      Resumes the currently paused script
      Parameters:
      JSFIdentifier - - the unique ID of the JythonServerFacade calling this method.
    • getScanStatus

      JythonStatus getScanStatus(String JSFIdentifier)
      Returns the scan of the queue (running, idle, paused).
      Parameters:
      JSFIdentifier - - the unique ID of the JythonServerFacade calling this method.
      Returns:
      int
    • getScriptStatus

      JythonStatus getScriptStatus(String JSFIdentifier)
      Returns the status of the script (running, idle, paused).
      Parameters:
      JSFIdentifier - - the unique ID of the JythonServerFacade calling this method.
      Returns:
      int
    • getJythonServerStatus

      JythonServerStatus getJythonServerStatus()
      Get the state of running scripts/scans
    • getCommandThreadInfo

      ICommandThreadInfo[] getCommandThreadInfo()
      Returns information about each active command thread
      Returns:
      Array of command thread information
    • setScriptStatus

      void setScriptStatus(JythonStatus status, String JSFIdentifier)
      Sets the script status.
      Parameters:
      status - JythonStatus of script
      JSFIdentifier - - the unique ID of the JythonServerFacade calling this method.
    • placeInJythonNamespace

      void placeInJythonNamespace(String objectName, Object obj, String JSFIdentifier)
      Pass a copy of an object to the Jython interpreter. This object must be relatively simple otherwise it will not be passed over CORBA successfully. So the object must be a native type (or only contain native types) and must not have any object references inside.
      Parameters:
      objectName -
      obj -
      JSFIdentifier - - the unique ID of the JythonServerFacade calling this method.
    • getFromJythonNamespace

      Object getFromJythonNamespace(String objectName, String JSFIdentifier)
      Get a copy of an object from the Jython interpreter. Note that the retreived object will have to be cast by the local code. As the object will be passed over CORBA, this method should only be used on native types or classes containing only native types.
      Parameters:
      objectName -
      JSFIdentifier - - the unique ID of the JythonServerFacade calling this method.
      Returns:
      Object
    • getRelease

      String getRelease(String JSFIdentifier)
      Returns the name of the GDA release being used by the CommandServer. This is the String returned by the JythonServer's local copy of gda.util.Version. This enables Client and Server processes to check if they are of the same GDA version.
      Parameters:
      JSFIdentifier - - the unique ID of the JythonServerFacade calling this method.
      Returns:
      the current GDA release used by the CommandServer.
    • getStartupOutput

      String getStartupOutput(String JSFIdentifier)
      This is used by clients when they start to immediately give any output messages from the startup script.
      Parameters:
      JSFIdentifier - - the unique ID of the JythonServerFacade calling this method.
      Returns:
      the output generated when the CommandServer ran its startup file as a string.
    • setRawInput

      void setRawInput(String theInput, String JSFIdentifier)
      After a requestRawInput has been called, the response should be returned via this method. The string is then the returned string to script which called requestRawInput. This method is distributed because the response could come from any object. The requestRawInput should only come from within a script, so that method is not distributed.
      Parameters:
      theInput -
      JSFIdentifier - - the unique ID of the JythonServerFacade calling this method.
    • requestBaton

      boolean requestBaton(String uniqueIdentifier)
      Ask for the baton for control of the beamline devices.
      Parameters:
      uniqueIdentifier -
      Returns:
      boolean
    • returnBaton

      void returnBaton(String uniqueIdentifier)
      Inform the JythonServer that the baton is no longer required by this connection.
      Parameters:
      uniqueIdentifier - String
    • assignBaton

      void assignBaton(String myJSFIdentifier, int indexOfReciever, int currentBatonHolderIndex)
      Inform the JythonServer which Client should now have the baton. This method will only be run for current holders of the baton.
      Parameters:
      myJSFIdentifier -
      indexOfReciever -
      currentBatonHolderIndex -
    • getClientInformation

      ClientDetails getClientInformation(String name)
      Returns details of this client
      Parameters:
      name -
      Returns:
      ClientDetails
    • getOtherClientInformation

      ClientDetails[] getOtherClientInformation(String myJSFIdentifier)
      Returns an array of objects describing the other clients on this beamline.

      This array may be slightly out of date if the client was not closed down properly, but after a few minutes the client should be automatically removed from the list.

      Parameters:
      myJSFIdentifier -
      Returns:
      ClientDetails[]
    • amIBatonHolder

      boolean amIBatonHolder(String myJSFIdentifier)
      Parameters:
      myJSFIdentifier -
      Returns:
      boolean if the given client holds the beamline baton
    • isBatonHeld

      boolean isBatonHeld()
      Returns true if any client holds the baton. If no client holds the baton then all clients may operate hardware subject to their authorisation level.
      Returns:
      true if any client holds the baton.
    • sendMessage

      void sendMessage(String myJSFIdentifier, String message)
      Broadcast a message to other users on this beamline. Such messages will be displayed in a special viewer.
      Parameters:
      myJSFIdentifier -
      message -
    • getMessageHistory

      List<UserMessage> getMessageHistory(String myJSFIdentifier)
      Returns previous messages sent during this visit.
    • addAliasedCommand

      void addAliasedCommand(String commandName, String JSFIdentifier)
      Add a new aliased command.
      Parameters:
      commandName -
      JSFIdentifier - - the unique ID of the JythonServerFacade calling this method.
    • addAliasedVarargCommand

      void addAliasedVarargCommand(String commandName, String JSFIdentifier)
      Add a new vararg aliased command
      Parameters:
      commandName -
      JSFIdentifier - - the unique ID of the JythonServerFacade calling this method.
    • getAliasedCommands

      Collection<String> getAliasedCommands(String JSFIdentifier)
      Get the list of aliased commands - GDA syntax extension in Jython environment
      Parameters:
      JSFIdentifier -
      Returns:
      the aliased commands
    • getAliasedVarargCommands

      Collection<String> getAliasedVarargCommands(String JSFIdentifier)
      Get the list of vararg aliased commands - GDA syntax extension in Jython environment
      Parameters:
      JSFIdentifier -
      Returns:
      the aliased vararg commands
    • hasAlias

      boolean hasAlias(String command, String jsfIdentifier)
      Check if given command is aliased
      Parameters:
      command -
      Returns:
      True if command is an alias
    • removeAlias

      void removeAlias(String command, String jsfIdentifier)
      Remove an alias
      Parameters:
      command - to remove
    • getAllNamesForType

      <F extends Findable> Set<String> getAllNamesForType(Class<F> clazz)
      Returns all names for all Objects of a type in the Jython namespace
      Parameters:
      clazz - a Class extending Findable
      Returns:
      a set of all names of all objects of a type in the Jython namespace.
    • getAllNamesForObject

      Set<String> getAllNamesForObject(Object obj) throws DeviceException
      Returns all names for an Object in the Jython namespace
      Parameters:
      obj -
      Returns:
      All names that refer to the Object in the Jython namespace
      Throws:
      DeviceException
    • locateScript

      String locateScript(String scriptToRun)
      Find a script with given name in the GDA's script project folders.
      Parameters:
      scriptToRun - The name of the script.
      Returns:
      The path to the script, or null if it can't be found.
    • getDefaultScriptProjectFolder

      String getDefaultScriptProjectFolder()
      The default location for Jython scripts in the server.
      Returns:
      A path to a folder where the server will search for Jython scripts.
    • getAllScriptProjectFolders

      List<String> getAllScriptProjectFolders()
    • getProjectNameForPath

      String getProjectNameForPath(String path)
    • projectIsUserType

      boolean projectIsUserType(String path)
    • projectIsConfigType

      boolean projectIsConfigType(String path)
    • projectIsCoreType

      boolean projectIsCoreType(String path)
    • eval

      org.python.core.PyObject eval(String s) throws org.python.core.PyException
      Evaluates a string as a Python expression and returns the result. Bypasses translator, batton control, and is not available across corba.

      This is of particular utility compared to other offerings as calls are synchronous, throw exceptions and can return an actual object.

      Parameters:
      s - The pure Jython string command to eval.
      Returns:
      PyObject The result of the eval
      Throws:
      org.python.core.PyException - If eval resulted in exception.
    • exec

      void exec(String s) throws org.python.core.PyException
      Executes a string of Python source in the local namespace. Bypasses translator, batton control, and is not available across corba.

      This is of particular utility compared to other offerings as calls are synchronous and throw exceptions.

      Parameters:
      s - The pure Jython string command to exec.
      Throws:
      org.python.core.PyException - If exec resulted in exception.
    • getCompletionsFor

      AutoCompletion getCompletionsFor(String line, int posn)
    • print

      void print(String text)