Package gda.jython
Class MockJythonServerFacade
java.lang.Object
gda.jython.MockJythonServerFacade
- All Implemented Interfaces:
AliasedCommandProvider,IAuthorisationHolder,IBatonStateProvider,ICommandAborter,ICommandRunner,ICurrentScanController,ICurrentScanInformationHolder,IDefaultScannableProvider,IJythonNamespace,IJythonServerNotifer,IScanDataPointProvider,IScanStatusHolder,IScriptController,ITerminalPrinter,JSFObserver,gda.observable.IObservable
public class MockJythonServerFacade
extends Object
implements IDefaultScannableProvider, ICurrentScanInformationHolder, IJythonServerNotifer, IScanStatusHolder, ICommandRunner, ITerminalPrinter, ICurrentScanController, IJythonNamespace, IAuthorisationHolder, IScanDataPointProvider, IScriptController, ICommandAborter, IBatonStateProvider, JSFObserver, AliasedCommandProvider
Mock implementation of interfaces usually provided by JythonServerFacade to be used when running tests outside of gda
This implementation is used if you set the property JythonServerFacade.dummy to true
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidvoidaddBatonChangedObserver(gda.observable.IObserver anObserver) voidaddIObserver(gda.observable.IObserver anIObserver) voidaddIScanDataPointObserver(IScanDataPointObserver anObserver) Add an object to this objects's list of IObservers.voidaddScanEventObserver(gda.observable.IObserver anObserver) Register an object to receive ScanEvent messages to be notified of progress, but not data during scans.booleanChecks if the caller is the holder of the batonvoidassignBaton(int receiverIndex, int holderIndex) voidvoidchangeVisitID(String visitID) Switches the visit this client will collect data as when it holds the baton.voiddeleteBatonChangedObserver(gda.observable.IObserver anObserver) voiddeleteIObserver(gda.observable.IObserver anIObserver) voidvoiddeleteIScanDataPointObserver(IScanDataPointObserver anObserver) Delete an object from this objects's list of IObservers.voiddeleteScanEventObserver(gda.observable.IObserver anObserver) Delete an object from this objects's list of IObservers which receive ScanEvent messagesevaluateCommand(String command) Runs a single line Jython command through the interpreter and returns the result in the form of a string.voidexecuteCommand(String command) Executes the Jython command in a new thread.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. 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.Return some information about the currently running scanReturns a collection of scannable objects which must be called in every scan.getFromJythonNamespace(String objectName) Get a copy of an object from the Jython interpreter.Returns previous messages sent during this visit.Returns the current ClientDetails for this client.Returns the name of the currently running script, if presentbooleanChecks 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.voidnotifyServer(Object source, Object data) This method passes information from a scan to the local facade objects.voidvoidvoidplaceInJythonNamespace(String objectName, Object obj) Pass a copy of an object to the Jython interpreter.voidbooleanvoidCall requestFinishEarly() on the current scan.voidvoidvoidvoidvoidReverts to the original user this client was initially logged in as.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.voidsendMessage(String message) Broadcast a message to other users on this beamline.voidsetAuthorisationLevel(int authorisationLevel) Allows tests to change authorisation level returned by getAuthorisationLevelvoidsetCurrentScan(Scan newScan) This should be used by tests to tell this class the current scan.voidsetEvaluateCommandResult(String evaluateCommandResult) voidsetScanObserver(String scanObserver) voidsetScanStatus(JythonStatus newStatus) voidsetScriptName(String scriptName) voidsetScriptStatus(JythonStatus newStatus) voidsetTerminalOutput(String terminalOutput) booleanswitchUser(String username, String password) void
-
Constructor Details
-
MockJythonServerFacade
public MockJythonServerFacade()
-
-
Method Details
-
getTerminalOutput
-
setTerminalOutput
-
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
-
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).
-
print
- Specified by:
printin interfaceITerminalPrinter- Parameters:
text-
-
setScanStatus
-
getScanStatus
- Specified by:
getScanStatusin interfaceIScanStatusHolder- Returns:
- status of Jython scan e.g. JythonStatus.IDLE
-
isScanRunning
public boolean isScanRunning()- Specified by:
isScanRunningin interfaceIScanStatusHolder- Returns:
trueif a scan is running,falseotherwise
-
pauseCurrentScan
public void pauseCurrentScan()- Specified by:
pauseCurrentScanin interfaceICurrentScanController
-
restartCurrentScan
public void restartCurrentScan()- Specified by:
restartCurrentScanin interfaceICurrentScanController
-
resumeCurrentScan
public void resumeCurrentScan()- Specified by:
resumeCurrentScanin interfaceICurrentScanController
-
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
-
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-
-
getAuthorisationLevel
public int getAuthorisationLevel()Description copied from interface:IAuthorisationHolderReturns 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
-
setAuthorisationLevel
public void setAuthorisationLevel(int authorisationLevel) Allows tests to change authorisation level returned by getAuthorisationLevel- Parameters:
authorisationLevel-
-
addIScanDataPointObserver
Description copied from interface:IScanDataPointProviderAdd an object to this objects's list of IObservers.- Specified by:
addIScanDataPointObserverin interfaceIScanDataPointProvider- Parameters:
anObserver- 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:
anObserver- object that implement IObserver and wishes to be notified by this object
-
getLastScanDataPoint
- Specified by:
getLastScanDataPointin interfaceIScanDataPointProvider
-
setScriptStatus
- Specified by:
setScriptStatusin interfaceIScriptController- Parameters:
newStatus- see values in Jython e.g. JYTHON.IDLE
-
getScriptStatus
- Specified by:
getScriptStatusin interfaceIScriptController- Returns:
- status see values in Jython e.g. JYTHON.IDLE
-
setScriptName
-
getScriptName
Description copied from interface:IScriptControllerReturns the name of the currently running script, if present- Specified by:
getScriptNamein interfaceIScriptController- Returns:
- name of current script
-
abortCommands
public void abortCommands()- Specified by:
abortCommandsin interfaceICommandAborter- See Also:
-
beamlineHalt
public void beamlineHalt()- Specified by:
beamlineHaltin 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- Parameters:
dataSource-data-
-
addBatonChangedObserver
public void addBatonChangedObserver(gda.observable.IObserver anObserver) - Specified by:
addBatonChangedObserverin interfaceIBatonStateProvider- Parameters:
anObserver-
-
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:
-
assignBaton
public void assignBaton(int receiverIndex, int holderIndex) - Specified by:
assignBatonin interfaceIBatonStateProvider- Parameters:
receiverIndex-holderIndex-- See Also:
-
deleteBatonChangedObserver
public void deleteBatonChangedObserver(gda.observable.IObserver anObserver) - Specified by:
deleteBatonChangedObserverin interfaceIBatonStateProvider- Parameters:
anObserver-
-
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
-
getOtherClientInformation
- Specified by:
getOtherClientInformationin interfaceIBatonStateProvider- Returns:
- ClientDetails[]
- 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:
-
returnBaton
public void returnBaton()- Specified by:
returnBatonin interfaceIBatonStateProvider- See Also:
-
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
-
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
-
setEvaluateCommandResult
-
changeVisitID
Description copied from interface:IBatonStateProviderSwitches the visit this client will collect data as when it holds the baton.- Specified by:
changeVisitIDin interfaceIBatonStateProvider- Parameters:
visitID-
-
revertToOriginalUser
public void revertToOriginalUser()Description copied from interface:IBatonStateProviderReverts to the original user this client was initially logged in as.- Specified by:
revertToOriginalUserin interfaceIBatonStateProvider- See Also:
-
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
-
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
-
requestBaton
public boolean requestBaton()- Specified by:
requestBatonin interfaceIBatonStateProvider- Returns:
- boolean
- 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
-
switchUser
- Specified by:
switchUserin interfaceIBatonStateProvider- Parameters:
username-password-- Returns:
- true if switch successful
- See Also:
-
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.
-
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
-
runScript
Description copied from interface:ICommandRunnerRuns 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
-
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:
-
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.
-
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-
-
notifyServer
Description copied from interface:IJythonServerNotiferThis method passes information from a scan to the local facade objects. These in turn pass the data to the local version of the GUI panel which created the scan.- Specified by:
notifyServerin interfaceIJythonServerNotifer- Parameters:
source- The serialized scan object which has created the data.data- A vector carrying the latest data collected by the scan
-
setCurrentScan
This should be used by tests to tell this class the current scan. In the real system the JythonServer would know what the current scan is and so would be able to provide information about it. In this mock, the unit tests need to tell this MockJythonServer what the current scan is.- Specified by:
setCurrentScanin interfaceICurrentScanInformationHolder- Parameters:
newScan-
-
getCurrentScanInformation
Description copied from interface:ICurrentScanInformationHolderReturn some information about the currently running scan- Specified by:
getCurrentScanInformationin interfaceICurrentScanInformationHolder- Returns:
- ScanInformation
-
getDefaultScannables
Description copied from interface:IDefaultScannableProviderReturns a collection of scannable objects which must be called in every scan. Used by scans to construct the list of objects whose positions are reported at every node of a scan.This returns a collection of object references of all the objects in the Jython namepsace listed in the DefaultScannablesList object named "scannablesList" in the configuration information.
As this method returns object references, this method must only be called by objects local to this object. This method must never be available remotely.
- Specified by:
getDefaultScannablesin interfaceIDefaultScannableProvider- Returns:
- Collection
-
setScanObserver
-
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-
-