Class JythonServerFacade
- All Implemented Interfaces:
AliasedCommandProvider,ICommandThreadInfoProvider,TextCompleter,IAuthorisationHolder,IBatonStateProvider,ICommandAborter,ICommandRunner,ICurrentScanController,IJythonContext,IJythonNamespace,IScanDataPointProvider,IScanStatusHolder,IScriptController,ITerminalOutputProvider,ITerminalPrinter,JSFObserver,gda.observable.IObservable,gda.observable.IObserver,org.springframework.beans.factory.InitializingBean
This object holds inside a reference to the CommandServer object which holds inside of it the interpreter.
Calls to this class must not occur during instantiation of objects. However, if they use the Configurable interface, then this class can be used during their configure phase.
Objects should register themselves as IObservers of this object to receive updates about scans, scripts, the script queue and data from scans.
This object does not directly implement the Jython interface. This is deliberate to safely restrict what functionality is given to other classes in the GDA. Only this class should communicate directly to the local JythonServer or JythonAdapter.
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedJythonServerFacade(Jython commandServer) Creates a Jython server facade, using the specified Jython command server.protectedJythonServerFacade(Jython commandServer, String username, String fullName) Creates a Jython server facade, using the specified Jython command server, username and fullName. -
Method Summary
Modifier and TypeMethodDescriptionvoidvoidaddAliasedCommand(String commandName) voidaddAliasedVarargCommand(String commandName) voidaddBatonChangedObserver(gda.observable.IObserver anObserver) voidaddCommandThreadObserver(ICommandThreadObserver anObserver) voidaddIObserver(gda.observable.IObserver anIObserver) voidaddIScanDataPointObserver(IScanDataPointObserver anIObserver) Add an object to this objects's list of IObservers.booleanaddOutputTerminal(Terminal term) voidaddScanEventObserver(gda.observable.IObserver anObserver) Register an object to receive ScanEvent messages to be notified of progress, but not data during scans.voidbooleanChecks if the caller is the holder of the batonvoidassignBaton(int receiverIndex, int currentBatonHolderIndex) voidvoidchangeVisitID(String visitID) Switches the visit this client will collect data as when it holds the baton.voiddeleteBatonChangedObserver(gda.observable.IObserver anObserver) voiddeleteCommandThreadObserver(ICommandThreadObserver anObserver) voiddeleteIObserver(gda.observable.IObserver anIObserver) voidvoiddeleteIScanDataPointObserver(IScanDataPointObserver anIObserver) Delete an object from this objects's list of IObservers.booleandeleteOutputTerminal(Terminal term) voiddeleteScanEventObserver(gda.observable.IObserver anObserver) Delete an object from this objects's list of IObservers which receive ScanEvent messagesstatic voidDeregisters the local singleton instance from the JythonServer and sets it to null.org.python.core.PyObjectEvaluates a string as a Python expression and returns the result.evaluateCommand(String command) 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) Executes the Jython command in a new thread.voidexecuteCommand(String command, InputStream stdin) Returns the list of alias in the GDA command serverReturns the list of variable argument alias in the GDA command serverReturns all names for an Object in the Jython namespacegetAllNamesForType(Class<F> clazz) As a Collection, this should be able to be passed over any serialisation method and is therefore available to client code. All of the folders in which the Jython server looks for scripts.intReturns the current authorisation level (this value could be dynamic if a baton is in use)intReturns the baton holder from the list of known clients connected, even if the baton holder is this client.intgetCompletionsFor(String line, int posn) static JythonServerFacadeReturns the local singleton instance throwing an Exception if one is required rather than logging it directly.The first folder in which the Jython server looks for scripts.getFromJythonNamespace(String objectName) Get a copy of an object from the Jython interpreter.static JythonServerFacadeReturns the local singleton instance, or null if there was an exception creating it.Returns previous messages sent during this visit.Returns the current ClientDetails for this client.getProjectNameForPath(String path) Given the path to a Jython project, return its name.Returns the name of the currently running script, if presentstatic JythonServerFacadebooleanChecks if the the given command is aliased (either vararg or not)booleanThis checks if the baton is held, at all, by any client.booleanbooleanlocateScript(String scriptToRun) Find a script with given name in the GDA's script project folders.voidvoidvoidplaceInJythonNamespace(String objectName, Object obj) Pass a copy of an object to the Jython interpreter.voidPrint to Jython console on all clients (and notify anything added viaaddOutputTerminal(Terminal)).booleanprojectIsConfigType(String path) Whether a project specified by path is a configuration project.booleanprojectIsCoreType(String path) Whether a project specified by path is a core project.booleanprojectIsUserType(String path) Whether a project specified by path is a user project.voidremoveAliasedCommand(String commandName) booleanvoidCall requestFinishEarly() on the current scan.voidvoidvoidvoidvoidReverts to the original user this client was initially logged in as.runAsJython(Runnable task) Run the given task in a Jython thread - allows it to be linked to a specific client and be restricted by its authorization level.voidrunCommand(String command) Executes the Jython command in a new thread.Runs the Jython script, and changes the ScriptStatus as is goes.Runs the jython command string, and changes the ScriptStatus as is goes.booleanSimilar toICommandRunner.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.booleanrunsource(String command, InputStream stdin) Similar torunsource(java.lang.String)but allows a specific InputStream to be used.voidsendMessage(String message) Broadcast a message to other users on this beamline.voidsetRawInput(String theRawInput) voidsetScriptStatus(JythonStatus status) booleanswitchUser(String username, String password) toString()void
-
Constructor Details
-
JythonServerFacade
Creates a Jython server facade, using the specified Jython command server.- Parameters:
commandServer- the Jython command server- Throws:
InstantiationException
-
JythonServerFacade
protected JythonServerFacade(Jython commandServer, String username, String fullName) throws InstantiationException Creates a Jython server facade, using the specified Jython command server, username and fullName.- Parameters:
commandServer- the Jython command serverusername- the username of the person using this JSFfullName- the full name of the person using this JSF- Throws:
InstantiationException
-
-
Method Details
-
getInstance
Returns the local singleton instance, or null if there was an exception creating it.- Returns:
- JythonServerFacade
-
getCurrentInstance
Returns the local singleton instance throwing an Exception if one is required rather than logging it directly.- Returns:
- JythonServerFacade
- Throws:
InstantiationException
-
disconnect
public static void disconnect()Deregisters the local singleton instance from the JythonServer and sets it to null. This should only be used when shutting down the process. -
getUnattendedClientFacade
- Returns:
- The JSf singleton for unattended data collections
- Throws:
InstantiationException
-
getAuthorisationLevel
public int getAuthorisationLevel()Returns the current authorisation level (this value could be dynamic if a baton is in use)- Specified by:
getAuthorisationLevelin interfaceIAuthorisationHolder- Returns:
- the authorisationLevel at this moment in time
-
getAuthorisationLevelAtRegistration
public int getAuthorisationLevelAtRegistration()- Specified by:
getAuthorisationLevelAtRegistrationin interfaceIAuthorisationHolder- Returns:
- the authorisation level ignoring any current baton status
-
getClientID
public int getClientID()- Returns:
- the index (public id) of this Client.
-
runScript
Runs the jython command string, and changes the ScriptStatus as is goes.
Non-blocking, Interruptible, Script locked.
SeeICommandRunnerfor the other options.- Specified by:
runScriptin interfaceICommandRunner- Parameters:
scriptContents- to run- Returns:
- status
-
runScript
Description copied from interface:ICommandRunnerRuns the Jython script, and changes the ScriptStatus as is goes.
Non-blocking, Interruptible, Script locked.
SeeICommandRunnerfor the other options.- Specified by:
runScriptin interfaceICommandRunner- Parameters:
script- to run- Returns:
- status
-
runCommand
Description copied from interface:ICommandRunnerExecutes the Jython command in a new thread.
Non-blocking, Interruptible, Not script locked.
SeeICommandRunnerfor the other options.- Specified by:
runCommandin interfaceICommandRunner- Parameters:
command- to run
-
executeCommand
Description copied from interface:ICommandRunnerExecutes the Jython command in a new thread.
Blocking, Interruptible, Not script locked and throws ScriptExecutionException- Specified by:
executeCommandin interfaceICommandRunner- Parameters:
command-- Throws:
ScriptExecutionException
-
executeCommand
- Throws:
ScriptExecutionException
-
evaluateCommand
Description copied from interface:ICommandRunnerRuns 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.- Specified by:
evaluateCommandin interfaceICommandRunner- Parameters:
command- to run- Returns:
- the string representation of the result
-
runAsJython
Run the given task in a Jython thread - allows it to be linked to a specific client and be restricted by its authorization level. Requires this facade to be on the server -
requestFinishEarly
public void requestFinishEarly()Description copied from interface:ICurrentScanControllerCall requestFinishEarly() on the current scan.- Specified by:
requestFinishEarlyin interfaceICurrentScanController
-
isFinishEarlyRequested
public boolean isFinishEarlyRequested()- Specified by:
isFinishEarlyRequestedin interfaceICurrentScanController- Returns:
- true if a request for the current scan to finish early has been made (probably via a gui).
-
pauseCurrentScan
public void pauseCurrentScan()- Specified by:
pauseCurrentScanin interfaceICurrentScanController
-
resumeCurrentScan
public void resumeCurrentScan()- Specified by:
resumeCurrentScanin interfaceICurrentScanController
-
restartCurrentScan
public void restartCurrentScan()- Specified by:
restartCurrentScanin interfaceICurrentScanController
-
beamlineHalt
public void beamlineHalt()- Specified by:
beamlineHaltin interfaceICommandAborter- See Also:
-
abortCommands
public void abortCommands()- Specified by:
abortCommandsin interfaceICommandAborter- See Also:
-
pauseCurrentScript
public void pauseCurrentScript()- Specified by:
pauseCurrentScriptin interfaceIScriptController- See Also:
-
resumeCurrentScript
public void resumeCurrentScript()- Specified by:
resumeCurrentScriptin interfaceIScriptController- See Also:
-
update
- Specified by:
updatein interfaceIBatonStateProvider- Specified by:
updatein interfacegda.observable.IObserver- Parameters:
dataSource-data-
-
runsource
Description copied from interface:ICommandRunnerSimilar toICommandRunner.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.
SeeICommandRunnerfor the other options.- Specified by:
runsourcein interfaceICommandRunner- Parameters:
command- to run- 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)but allows a specific InputStream to be used.- Parameters:
command- to runstdin- input stream to use as stdin for this command- Returns:
- true if more is needed, false if not
- See Also:
-
getScriptStatus
- Specified by:
getScriptStatusin interfaceIScriptController- Returns:
- status see values in Jython e.g. JYTHON.IDLE
-
setRawInput
-
getScanStatus
- Specified by:
getScanStatusin interfaceIScanStatusHolder- Returns:
- status of Jython scan e.g. JythonStatus.IDLE
-
getServerStatus
-
getScriptName
Description copied from interface:IScriptControllerReturns the name of the currently running script, if present- Specified by:
getScriptNamein interfaceIScriptController- Returns:
- name of current script
-
isScanRunning
public boolean isScanRunning()- Specified by:
isScanRunningin interfaceIScanStatusHolder- Returns:
trueif a scan is running,falseotherwise
-
setScriptStatus
- Specified by:
setScriptStatusin interfaceIScriptController- Parameters:
status- see values in Jython e.g. JYTHON.IDLE
-
addIObserver
public void addIObserver(gda.observable.IObserver anIObserver) - Specified by:
addIObserverin interfacegda.observable.IObservable
-
deleteIObserver
public void deleteIObserver(gda.observable.IObserver anIObserver) - Specified by:
deleteIObserverin interfacegda.observable.IObservable
-
deleteIObservers
public void deleteIObservers()- Specified by:
deleteIObserversin interfacegda.observable.IObservable
-
placeInJythonNamespace
Description copied from interface:IJythonNamespacePass 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.- Specified by:
placeInJythonNamespacein interfaceIJythonNamespace- Parameters:
objectName-obj-
-
getFromJythonNamespace
Description copied from interface:IJythonNamespaceGet a copy of an object from the Jython interpreter. Note that the retrieved 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.- Specified by:
getFromJythonNamespacein interfaceIJythonNamespace- Parameters:
objectName-- Returns:
- Object
-
print
Print to Jython console on all clients (and notify anything added viaaddOutputTerminal(Terminal)). Makes it easy for strings to be printed on the console and not anywhere else.- Specified by:
printin interfaceITerminalPrinter- Parameters:
text- the string to be printed
-
getStartupOutput
- Returns:
- string of the message from the last (re)start of the Command Server
- See Also:
-
addAliasedCommand
-
addAliasedVarargCommand
-
removeAliasedCommand
-
requestBaton
public boolean requestBaton()- Specified by:
requestBatonin interfaceIBatonStateProvider- Returns:
- boolean
- See Also:
-
returnBaton
public void returnBaton()- Specified by:
returnBatonin interfaceIBatonStateProvider- See Also:
-
assignBaton
public void assignBaton(int receiverIndex, int currentBatonHolderIndex) - Specified by:
assignBatonin interfaceIBatonStateProvider- Parameters:
receiverIndex-currentBatonHolderIndex-- See Also:
-
switchUser
- Specified by:
switchUserin interfaceIBatonStateProvider- Parameters:
username-password-- Returns:
- true if switch successful
- See Also:
-
revertToOriginalUser
public void revertToOriginalUser()Reverts to the original user this client was initially logged in as.- Specified by:
revertToOriginalUserin interfaceIBatonStateProvider- See Also:
-
changeVisitID
Switches the visit this client will collect data as when it holds the baton.- Specified by:
changeVisitIDin interfaceIBatonStateProvider- Parameters:
visitID-
-
getOtherClientInformation
- Specified by:
getOtherClientInformationin interfaceIBatonStateProvider- Returns:
- ClientDetails[]
- See Also:
-
getBatonHolder
Description copied from interface:IBatonStateProviderReturns the baton holder from the list of known clients connected, even if the baton holder is this client.- Specified by:
getBatonHolderin interfaceIBatonStateProvider- Returns:
- ClientDetails
-
amIBatonHolder
public boolean amIBatonHolder()Description copied from interface:IBatonStateProviderChecks if the caller is the holder of the baton- Specified by:
amIBatonHolderin interfaceIBatonStateProvider- Returns:
trueif the caller holds the batonfalseotherwise- See Also:
-
isBatonHeld
public boolean isBatonHeld()Description copied from interface:IBatonStateProviderThis checks if the baton is held, at all, by any client. It does not check it the caller is the baton holder.- Specified by:
isBatonHeldin interfaceIBatonStateProvider- Returns:
trueif the baton is held by any client,falseotherwise- See Also:
-
sendMessage
Description copied from interface:IBatonStateProviderBroadcast a message to other users on this beamline. Such messages will be displayed in a special viewer.- Specified by:
sendMessagein interfaceIBatonStateProvider- Parameters:
message-
-
getMessageHistory
Description copied from interface:IBatonStateProviderReturns previous messages sent during this visit.- Specified by:
getMessageHistoryin interfaceIBatonStateProvider
-
addIScanDataPointObserver
Description copied from interface:IScanDataPointProviderAdd an object to this objects's list of IObservers.- Specified by:
addIScanDataPointObserverin interfaceIScanDataPointProvider- Parameters:
anIObserver- object that implement IObserver and wishes to be notified by this object
-
deleteIScanDataPointObserver
Description copied from interface:IScanDataPointProviderDelete an object from this objects's list of IObservers.- Specified by:
deleteIScanDataPointObserverin interfaceIScanDataPointProvider- Parameters:
anIObserver- object that implement IObserver and wishes to be notified by this object
-
getLastScanDataPoint
- Specified by:
getLastScanDataPointin interfaceIScanDataPointProvider
-
addBatonChangedObserver
public void addBatonChangedObserver(gda.observable.IObserver anObserver) - Specified by:
addBatonChangedObserverin interfaceIBatonStateProvider- Parameters:
anObserver-
-
deleteBatonChangedObserver
public void deleteBatonChangedObserver(gda.observable.IObserver anObserver) - Specified by:
deleteBatonChangedObserverin interfaceIBatonStateProvider- Parameters:
anObserver-
-
toString
-
afterPropertiesSet
- Specified by:
afterPropertiesSetin interfaceorg.springframework.beans.factory.InitializingBean- Throws:
Exception
-
addScanEventObserver
public void addScanEventObserver(gda.observable.IObserver anObserver) Description copied from interface:IScanDataPointProviderRegister an object to receive ScanEvent messages to be notified of progress, but not data during scans.- Specified by:
addScanEventObserverin interfaceIScanDataPointProvider- Parameters:
anObserver-
-
deleteScanEventObserver
public void deleteScanEventObserver(gda.observable.IObserver anObserver) Description copied from interface:IScanDataPointProviderDelete an object from this objects's list of IObservers which receive ScanEvent messages- Specified by:
deleteScanEventObserverin interfaceIScanDataPointProvider- Parameters:
anObserver-
-
addCommandThreadObserver
- Specified by:
addCommandThreadObserverin interfaceICommandThreadInfoProvider
-
deleteCommandThreadObserver
- Specified by:
deleteCommandThreadObserverin interfaceICommandThreadInfoProvider
-
getCommandThreadInfo
- Specified by:
getCommandThreadInfoin interfaceICommandThreadInfoProvider
-
getMyDetails
Description copied from interface:IBatonStateProviderReturns the current ClientDetails for this client. What is returned will change depending on the baton status and if the user has been switched using the switchUser method.The authorisationLevel returned takes into account any alternate user, but not whether the baton is held. For this, call getAuthorisationLevel().
- Specified by:
getMyDetailsin interfaceIBatonStateProvider- Returns:
- ClientDetails
-
getAliasedCommands
Description copied from interface:AliasedCommandProviderReturns the list of alias in the GDA command server- Specified by:
getAliasedCommandsin interfaceAliasedCommandProvider- Returns:
- the aliased commands
-
getAliasedVarargCommands
Description copied from interface:AliasedCommandProviderReturns the list of variable argument alias in the GDA command server- Specified by:
getAliasedVarargCommandsin interfaceAliasedCommandProvider- Returns:
- the list of variable argument alias
-
hasAlias
Description copied from interface:AliasedCommandProviderChecks if the the given command is aliased (either vararg or not)- Specified by:
hasAliasin interfaceAliasedCommandProvider- Parameters:
command- the string to check- Returns:
- whether the command is aliased or not
-
getAllNamesForObject
Description copied from interface:IJythonNamespaceReturns all names for an Object in the Jython namespace- Specified by:
getAllNamesForObjectin interfaceIJythonNamespace- Parameters:
obj-- Returns:
- All names that refer to the Object in the Jython namespace
- Throws:
DeviceException
-
getAllNamesForType
Description copied from interface:IJythonNamespaceAs a Collection, this should be able to be passed over any serialisation method and is therefore available to client code. We may have e.g. Scannables written entirely in Jython that we may not be able to pass across, meaning the similar method LocalJython#getAllObjectsOfTypeis limited to server side.- Specified by:
getAllNamesForTypein interfaceIJythonNamespace- Parameters:
clazz- a Class extending Findable- Returns:
- a set of all names of all objects of a type in the Jython namespace.
-
locateScript
Description copied from interface:ICommandRunnerFind a script with given name in the GDA's script project folders.- Specified by:
locateScriptin interfaceICommandRunner- 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.
-
getDefaultScriptProjectFolder
Description copied from interface:IJythonContextThe first folder in which the Jython server looks for scripts.- Specified by:
getDefaultScriptProjectFolderin interfaceIJythonContext- Returns:
- A path to the default location for Jython scripts.
-
getAllScriptProjectFolders
Description copied from interface:IJythonContextAll of the folders in which the Jython server looks for scripts.- Specified by:
getAllScriptProjectFoldersin interfaceIJythonContext- Returns:
- A list of paths to the Jython script project folders.
-
getProjectNameForPath
Description copied from interface:IJythonContextGiven the path to a Jython project, return its name.- Specified by:
getProjectNameForPathin interfaceIJythonContext- Parameters:
path- The path to a Jython script project.- Returns:
- The name of the specified Jython project. If the path is not a known project, then null is returned.
-
projectIsUserType
Description copied from interface:IJythonContextWhether a project specified by path is a user project.- Specified by:
projectIsUserTypein interfaceIJythonContext- Parameters:
path- The project folder path.- Returns:
- true if the project exists and is a user project.
-
projectIsConfigType
Description copied from interface:IJythonContextWhether a project specified by path is a configuration project.- Specified by:
projectIsConfigTypein interfaceIJythonContext- Parameters:
path- The project folder path.- Returns:
- true if the project exists and is a config project.
-
projectIsCoreType
Description copied from interface:IJythonContextWhether a project specified by path is a core project.- Specified by:
projectIsCoreTypein interfaceIJythonContext- Parameters:
path- The project folder path.- Returns:
- true if the project exists and is a core project.
-
addOutputTerminal
- Specified by:
addOutputTerminalin interfaceITerminalOutputProvider
-
deleteOutputTerminal
- Specified by:
deleteOutputTerminalin interfaceITerminalOutputProvider
-
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.
- Throws:
org.python.core.PyException
-
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.
- Throws:
org.python.core.PyException
-
getCompletionsFor
- Specified by:
getCompletionsForin interfaceTextCompleter
-