Package gda.jython
Interface Jython
- All Superinterfaces:
Findable,gda.observable.IObservable
- All Known Subinterfaces:
LocalJython
- All Known Implementing Classes:
JythonServer
The distributed interface for the JythonServer object. This interface should not be operated directly, but via the
InterfaceProvider.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringString passed to IObservers of the CommandServer that it has received input via the setRawInput methodstatic final StringString passed to IObservers of the CommandServer that it is waiting for input via the setRawInput methodstatic final StringName of this object. -
Method Summary
Modifier and TypeMethodDescriptionvoidabortCommands(String JSFIdentifier) Stops all scripts, scans, and commands running from the Jython Server immediately.voidaddAliasedCommand(String commandName, String JSFIdentifier) Add a new aliased command.voidaddAliasedVarargCommand(String commandName, String JSFIdentifier) Add a new vararg aliased commandintFor use by the JythonServerFacade class.booleanamIBatonHolder(String myJSFIdentifier) voidassignBaton(String myJSFIdentifier, int indexOfReciever, int currentBatonHolderIndex) Inform the JythonServer which Client should now have the baton.voidbeamlineHalt(String JSFIdentifier) Stops all scripts, scans, and commands immediately.org.python.core.PyObjectEvaluates a string as a Python expression and returns the result.evaluateCommand(String command, String JSFIdentifier) Runs a single line Jython command through the interpreter and returns the result in the form of a string.voidExecutes a string of Python source in the local namespace.voidexecuteCommand(String command, String JSFIdentifier) Executes the Jython command in a new thread
Blocking, Interruptible, Not script locked.voidexecuteCommand(String command, String JSFIdentifier, InputStream stdin) Executes the Jython command in a new thread with the provided stdin input stream.getAliasedCommands(String JSFIdentifier) Get the list of aliased commands - GDA syntax extension in Jython environmentgetAliasedVarargCommands(String JSFIdentifier) Get the list of vararg aliased commands - GDA syntax extension in Jython environmentReturns all names for an Object in the Jython namespacegetAllNamesForType(Class<F> clazz) Returns all names for all Objects of a type in the Jython namespacegetClientInformation(String name) Returns details of this clientReturns information about each active command threadgetCompletionsFor(String line, int posn) The default location for Jython scripts in the server.getFromJythonNamespace(String objectName, String JSFIdentifier) Get a copy of an object from the Jython interpreter.Get the state of running scripts/scansgetMessageHistory(String myJSFIdentifier) Returns previous messages sent during this visit.getOtherClientInformation(String myJSFIdentifier) Returns an array of objects describing the other clients on this beamline.getProjectNameForPath(String path) getRelease(String JSFIdentifier) Returns the name of the GDA release being used by the CommandServer.getScanStatus(String JSFIdentifier) Returns the scan of the queue (running, idle, paused).getScriptStatus(String JSFIdentifier) Returns the status of the script (running, idle, paused).getStartupOutput(String JSFIdentifier) This is used by clients when they start to immediately give any output messages from the startup script.booleanCheck if given command is aliasedbooleanReturns true if any client holds the baton.booleanlocateScript(String scriptToRun) Find a script with given name in the GDA's script project folders.voidpauseCurrentScan(String JSFIdentifier) Pauses the current scanvoidpauseCurrentScript(String JSFIdentifier) Pauses the current script the next time it calls the ScriptBase.checkForPuases method until resumeCurrentScript is called.voidplaceInJythonNamespace(String objectName, Object obj, String JSFIdentifier) Pass a copy of an object to the Jython interpreter.voidbooleanprojectIsConfigType(String path) booleanprojectIsCoreType(String path) booleanprojectIsUserType(String path) voidremoveAlias(String command, String jsfIdentifier) Remove an aliasvoidremoveFacade(String uniqueFacadeName) Removes the registration of the facade with this server and returns the baton if applicable.booleanrequestBaton(String uniqueIdentifier) Ask for the baton for control of the beamline devices.voidrequestFinishEarly(String JSFIdentifier) Cleanly stops the current scan.voidrestartCurrentScan(String JSFIdentifier) Restarts the last scan which was run, if it ended due to an error or it was interrupted.voidresumeCurrentScan(String JSFIdentifier) Resumes the currently paused scan.voidresumeCurrentScript(String JSFIdentifier) Resumes the currently paused scriptvoidreturnBaton(String uniqueIdentifier) Inform the JythonServer that the baton is no longer required by this connection.voidrunCommand(String command, String JSFIdentifier) Executes the Jython command in a new thread.Runs the Jython script, and changes the ScriptStatus as is goes.booleanSimilar torunCommand(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.booleanrunsource(String command, String JSFIdentifier, InputStream stdin) Similar torunsource(java.lang.String, java.lang.String)but allows a specific InputStream to be used.voidsendMessage(String myJSFIdentifier, String message) Broadcast a message to other users on this beamline.voidsetRawInput(String theInput, String JSFIdentifier) After a requestRawInput has been called, the response should be returned via this method.voidsetScriptStatus(JythonStatus status, String JSFIdentifier) Sets the script status.voidswitchUser(String uniqueFacadeName, String username, String visitID) For an already registered JythonServerFacade, changes information for that facade.Methods inherited from interface gda.observable.IObservable
addIObserver, deleteIObserver, deleteIObservers
-
Field Details
-
SERVER_NAME
Name of this object. This should agree with the string used in Castor.- See Also:
-
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
String passed to IObservers of the CommandServer that it has received input via the setRawInput method- See Also:
-
-
Method Details
-
evaluateCommand
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.
SeeICommandRunnerfor the other options.- Parameters:
command- command to runJSFIdentifier- - the unique ID of the JythonServerFacade calling this method- Returns:
- the string representation of the result
-
runCommand
Executes the Jython command in a new thread.
Non-blocking, Interruptible, Not script locked.
SeeICommandRunnerfor the other options.- Parameters:
command- to runJSFIdentifier- - the unique ID of the JythonServerFacade calling this method
-
executeCommand
Executes the Jython command in a new thread
Blocking, Interruptible, Not script locked.
SeeICommandRunnerfor the other options.- Parameters:
command- to runJSFIdentifier-- 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.
SeeICommandRunnerfor the other options.
SeeexecuteCommand(String, String)for alternative using the RCP input stream- Parameters:
command- to runJSFIdentifier-stdin- an InputStream to use as the source of user input- Throws:
ScriptExecutionException- if there is an exception in the script
-
runScript
Runs the Jython script, and changes the ScriptStatus as is goes.
Non-blocking, Interruptible, Script locked.
SeeICommandRunnerfor the other options.- Parameters:
command- to runscriptName- used to acquire a lockJSFIdentifier- - the unique ID of the JythonServerFacade calling this method- Returns:
- status
-
runsource
Similar torunCommand(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.
SeeICommandRunnerfor the other options.- Parameters:
command- to runJSFIdentifier- 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
Similar torunsource(java.lang.String, java.lang.String)but allows a specific InputStream to be used.
Blocking, Interruptible, Not script locked.
SeeICommandRunnerfor the other options.- Parameters:
command- to runJSFIdentifier- - the unique ID of the JythonServerFacade calling this methodstdin- 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
Removes the registration of the facade with this server and returns the baton if applicable.- Parameters:
uniqueFacadeName-
-
switchUser
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
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
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
Stops all scripts, scans, and commands running from the Jython Server immediately.- Parameters:
JSFIdentifier- - the unique ID of the JythonServerFacade calling this method.
-
pauseCurrentScan
Pauses the current scan- Parameters:
JSFIdentifier- - the unique ID of the JythonServerFacade calling this method.
-
pauseCurrentScript
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
Resumes the currently paused scan.- Parameters:
JSFIdentifier- - the unique ID of the JythonServerFacade calling this method.
-
restartCurrentScan
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
Resumes the currently paused script- Parameters:
JSFIdentifier- - the unique ID of the JythonServerFacade calling this method.
-
getScanStatus
Returns the scan of the queue (running, idle, paused).- Parameters:
JSFIdentifier- - the unique ID of the JythonServerFacade calling this method.- Returns:
- int
-
getScriptStatus
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
Sets the script status.- Parameters:
status- JythonStatus of scriptJSFIdentifier- - the unique ID of the JythonServerFacade calling this method.
-
placeInJythonNamespace
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
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
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
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
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
Ask for the baton for control of the beamline devices.- Parameters:
uniqueIdentifier-- Returns:
- boolean
-
returnBaton
Inform the JythonServer that the baton is no longer required by this connection.- Parameters:
uniqueIdentifier- String
-
assignBaton
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
Returns details of this client- Parameters:
name-- Returns:
- ClientDetails
-
getOtherClientInformation
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
- 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
Broadcast a message to other users on this beamline. Such messages will be displayed in a special viewer.- Parameters:
myJSFIdentifier-message-
-
getMessageHistory
Returns previous messages sent during this visit. -
addAliasedCommand
Add a new aliased command.- Parameters:
commandName-JSFIdentifier- - the unique ID of the JythonServerFacade calling this method.
-
addAliasedVarargCommand
Add a new vararg aliased command- Parameters:
commandName-JSFIdentifier- - the unique ID of the JythonServerFacade calling this method.
-
getAliasedCommands
Get the list of aliased commands - GDA syntax extension in Jython environment- Parameters:
JSFIdentifier-- Returns:
- the aliased commands
-
getAliasedVarargCommands
Get the list of vararg aliased commands - GDA syntax extension in Jython environment- Parameters:
JSFIdentifier-- Returns:
- the aliased vararg commands
-
hasAlias
Check if given command is aliased- Parameters:
command-- Returns:
- True if command is an alias
-
removeAlias
Remove an alias- Parameters:
command- to remove
-
getAllNamesForType
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
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
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
-
getProjectNameForPath
-
projectIsUserType
-
projectIsConfigType
-
projectIsCoreType
-
eval
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
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
-
print
-