Package org.eclipse.scanning.api.device
Class AbstractRunnableDevice<T>
java.lang.Object
org.eclipse.scanning.api.AbstractNameable
org.eclipse.scanning.api.device.AbstractRunnableDevice<T>
- Type Parameters:
T-
- All Implemented Interfaces:
IActivatable,IPausableDevice<T>,IResettableDevice,IRunnableDevice<T>,IRunnableEventDevice<T>,IDeviceRoleActor,IConfigurable<T>,ILevel,IModelProvider<T>,INameable,IScanAttributeContainer,IValidator<T>
- Direct Known Subclasses:
AbstractAreaDetectorRunnableDevice,AbstractMalcolmDevice,ConstantVelocityDevice,DarkImageDetector,DummyMalcolmTriggeredDetector,ElectronAnalyserRunnableDevice,MandelbrotDetector,PosDetector,RandomIntDetector,RandomLineDevice,RunnableDeviceProxy,XmapRunnableDeviceBase,ZebraRunnableDevice
public abstract class AbstractRunnableDevice<T>
extends AbstractNameable
implements IRunnableEventDevice<T>, IScanAttributeContainer, IActivatable
A device should create its own model when its constructor is called. This
can be done by reading the current hardware state for the device. In this
case the runnable device service does not set its model. If a given device
does not set its own model, when the service makes the device, it will attempt
to create a new empty model and set this empty model as the current model.
This means that the device does not have a null model and the user can get
the model and configure it.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected IScannableDeviceServiceprotected Tprotected IRunnableDeviceService -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAbstractRunnableDevice(IRunnableDeviceService dservice) Devices may be created during the cycle of a runnable device service being made. -
Method Summary
Modifier and TypeMethodDescriptionvoidabort()Call to terminate the scan before it has finished.voidA listener which notifies when a run of the device will occur and after it has occurred.voidCall to configure the device.voiddisable()Call to disable the device, stopping all activity.voidfireRunPerformed(IPosition position) Called during the scanning to notify the device that the run method has been called at a given position.voidfireRunWillPerform(IPosition position) Called during the scanning to notify the device that the run method will be called at a given position.protected voidfireStateChanged(DeviceState oldState, DeviceState newState) voidfireWritePerformed(IPosition position) Called during the scanning to notify the device that the write method has been called at a given position, if the device implements one.voidfireWriteWillPerform(IPosition position) Called during the scanning to notify the device that the write method will be called at a given position, if the device implements one.longPlease override to provide a device health (which a malcolm device will have) The default returns null.final DeviceInformation<T> Do not override without calling super.getDeviceInformation() Method is final for now to help avoid that problem.getDeviceInformation(boolean includeNonAlive) Do not override without calling super.getDeviceInformation() Method is final for now to help avoid that problem.intgetLevel()get the operation level of this scannable.getModel()The model being used for the device.getRole()The role of the device.<A> AgetScanAttribute(String attributeName) Get the value of the specified attributeReturns a set of the scan modes that this device can participate in.booleanbooleanisAlive()Gets whether the device is 'alive' or not.booleanGets whether the device is busy or notvoidpause()Allowed when the device is in Running state.voidregister()Used by spring to register the detector with the Runnable device service *WARNING* Before calling register the detector must be given a service to register this.voidA listener which notifies when a run of the device will occur and after it has occurred.voidreset()Allowed from Fault.voidresume()Allowed when the device is in Paused state.voidseek(int stepNumber) Seek to/from a point number (absolute) in the scan.booleansetActivated(boolean activated) voidsetAlive(boolean alive) Sets whether the device is alive or notvoidsetBusy(boolean busy) Call to set the busy state while the device is running.voidsetConfigureTime(long configureTime) voidsetConnectorService(IScannableDeviceService connectorService) voidsetDeviceInformation(DeviceInformation<T> deviceInformation) protected voidsetDeviceState(DeviceState newDeviceState) voidsetLevel(int level) Used for ordering the operations of Scannables during scansvoidThe model for some providers may be set but be warned that others throw an IllegalArgumentException.voidsetPublisher(IPublisher<ScanBean> publisher) voidsetRole(DeviceRole role) The role of the device.voidsetRunnableDeviceService(IRunnableDeviceService runnableDeviceService) <A> voidsetScanAttribute(String attributeName, A value) Set any attribute the implementing classes may providevoidvoidsetSupportedScanMode(ScanMode supportedScanMode) voidsetSupportedScanModes(Set<ScanMode> supportedScanModes) protected voidsetSupportedScanModes(ScanMode... supportedScanModes) toString()If overriding don't forget the old super.validate(...)Methods inherited from class org.eclipse.scanning.api.AbstractNameable
equals, getName, hashCode, setNameMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface org.eclipse.scanning.api.IModelProvider
updateModelMethods inherited from interface org.eclipse.scanning.api.device.IRunnableDevice
latch, latch, run, run, start, throwFirstRunExceptionMethods inherited from interface org.eclipse.scanning.api.IValidator
setService
-
Field Details
-
model
-
runnableDeviceService
-
connectorService
-
-
Constructor Details
-
AbstractRunnableDevice
Devices may be created during the cycle of a runnable device service being made. Therefore the parameter dservice may be null. This is acceptable because when used in spring the service is going and then the register(...) method may be used.- Parameters:
dservice-
-
-
Method Details
-
register
public void register()Used by spring to register the detector with the Runnable device service *WARNING* Before calling register the detector must be given a service to register this. This can be done from the constructor super(IRunnableDeviceService) of the detector to make it easy to instantiate a no-argument detector and register it from spring. -
getRunnableDeviceService
-
setRunnableDeviceService
-
getConnectorService
-
setConnectorService
-
getLevel
public int getLevel()Description copied from interface:ILevelget the operation level of this scannable. -
setLevel
public void setLevel(int level) Description copied from interface:ILevelUsed for ordering the operations of Scannables during scans -
reset
Description copied from interface:IResettableDeviceAllowed from Fault. Will try to reset the device into Idle state. Will block until the device is in a rest state.- Specified by:
resetin interfaceIResettableDevice- Throws:
ScanningException
-
setDeviceState
- Parameters:
newDeviceState-- Throws:
ScanningException
-
getDeviceState
- Specified by:
getDeviceStatein interfaceIRunnableDevice<T>- Returns:
- the current device State. This is not the same as the Status of the scan.
- Throws:
ScanningException
-
getScanId
-
setScanId
-
getPublisher
-
setPublisher
-
addRunListener
Description copied from interface:IRunnableEventDeviceA listener which notifies when a run of the device will occur and after it has occurred. This can be used to modify the model before the next run.- Specified by:
addRunListenerin interfaceIRunnableEventDevice<T>
-
removeRunListener
Description copied from interface:IRunnableEventDeviceA listener which notifies when a run of the device will occur and after it has occurred. This can be used to modify the model before the next run.- Specified by:
removeRunListenerin interfaceIRunnableEventDevice<T>
-
fireStateChanged
protected void fireStateChanged(DeviceState oldState, DeviceState newState) throws ScanningException - Throws:
ScanningException
-
fireRunWillPerform
Description copied from interface:IRunnableEventDeviceCalled during the scanning to notify the device that the run method will be called at a given position. This method is called on the same thread that the run() method is called on, e.g. parallel execution by level in the case of AcquisitionDevice.- Specified by:
fireRunWillPerformin interfaceIRunnableEventDevice<T>- Parameters:
position-- Throws:
ScanningException
-
fireRunPerformed
Description copied from interface:IRunnableEventDeviceCalled during the scanning to notify the device that the run method has been called at a given position. This method is called on the same thread that the run() method is called on, e.g. parallel execution by level in the case of AcquisitionDevice.- Specified by:
fireRunPerformedin interfaceIRunnableEventDevice<T>- Parameters:
position-- Throws:
ScanningException
-
fireWriteWillPerform
Description copied from interface:IRunnableEventDeviceCalled during the scanning to notify the device that the write method will be called at a given position, if the device implements one. This method is called on the same thread that the write() method is called on, e.g. parallel execution by level in the case of AcquisitionDevice. NOTE: If the write method returns false, fireWritePerformed is not called. However fireWriteWillPerform will still be called. This is because until the device attempts to write we do not know if is has written.- Specified by:
fireWriteWillPerformin interfaceIRunnableEventDevice<T>- Parameters:
position-- Throws:
ScanningException
-
fireWritePerformed
Description copied from interface:IRunnableEventDeviceCalled during the scanning to notify the device that the write method has been called at a given position, if the device implements one. This method is called on the same thread that the write() method is called on, e.g. parallel execution by level in the case of AcquisitionDevice. NOTE: If the write method returns false, fireWritePerformed is not called. However fireWriteWillPerform will still be called. This is because until the device attempts to write we do not know if is has written.- Specified by:
fireWritePerformedin interfaceIRunnableEventDevice<T>- Parameters:
position-- Throws:
ScanningException
-
getModel
Description copied from interface:IRunnableDeviceThe model being used for the device.- Specified by:
getModelin interfaceIModelProvider<T>- Specified by:
getModelin interfaceIRunnableDevice<T>- Returns:
-
setModel
Description copied from interface:IModelProviderThe model for some providers may be set but be warned that others throw an IllegalArgumentException.- Specified by:
setModelin interfaceIModelProvider<T>- Parameters:
model-
-
configure
Description copied from interface:IConfigurableCall to configure the device. If the model provided is invalid, a scanning exception will be thrown.- Specified by:
configurein interfaceIConfigurable<T>- Parameters:
model-- Throws:
ScanningException
-
abort
Description copied from interface:IRunnableDeviceCall to terminate the scan before it has finished.- Specified by:
abortin interfaceIRunnableDevice<T>- Throws:
ScanningExceptionInterruptedException
-
disable
Description copied from interface:IRunnableDeviceCall to disable the device, stopping all activity.- Specified by:
disablein interfaceIRunnableDevice<T>- Throws:
ScanningException
-
pause
Description copied from interface:IPausableDeviceAllowed when the device is in Running state. Will block until the device is in a rest state. When paused the same thread must call resume() or abort() which has paused or an IllegalMonitorState Exception will be thrown.- Specified by:
pausein interfaceIPausableDevice<T>- Throws:
ScanningExceptionInterruptedException
-
seek
Description copied from interface:IPausableDeviceSeek to/from a point number (absolute) in the scan.- Specified by:
seekin interfaceIPausableDevice<T>- Throws:
ScanningExceptionInterruptedException
-
resume
Description copied from interface:IPausableDeviceAllowed when the device is in Paused state. Will block until the device is unpaused. When paused the same thread must call resume() or abort() which has paused or an IllegalMonitorState Exception will be thrown.- Specified by:
resumein interfaceIPausableDevice<T>- Throws:
ScanningExceptionInterruptedException
-
getScanAttributeNames
- Specified by:
getScanAttributeNamesin interfaceIScanAttributeContainer- Returns:
- null if no attributes, otherwise collection of the names of the attributes set
-
setScanAttribute
Set any attribute the implementing classes may provide- Specified by:
setScanAttributein interfaceIScanAttributeContainer- Parameters:
attributeName- is the name of the attributevalue- is the value of the attribute
-
getScanAttribute
Get the value of the specified attribute- Specified by:
getScanAttributein interfaceIScanAttributeContainer- Parameters:
attributeName- is the name of the attribute- Returns:
- the value of the attribute
-
getDeviceInformation
Do not override without calling super.getDeviceInformation() Method is final for now to help avoid that problem.- Returns:
- Throws:
ScanningException
-
getDeviceInformation
Do not override without calling super.getDeviceInformation() Method is final for now to help avoid that problem. Gets the device information, with the ability to specify whether to get information that is potentially held on a device or not in the case that the device is not marked as being alive.- Parameters:
includeNonAlive- If set to false, if a device is not alive, information potentially held on the device will not be retrieved- Returns:
- Throws:
ScanningException
-
setDeviceInformation
-
validate
If overriding don't forget the old super.validate(...)- Specified by:
validatein interfaceIValidator<T>- Parameters:
model- - a model of type T to validate- Returns:
- a valid model
-
isActivated
public boolean isActivated()- Specified by:
isActivatedin interfaceIActivatable- Returns:
- true if device is activated.
-
setActivated
public boolean setActivated(boolean activated) - Specified by:
setActivatedin interfaceIActivatable- Parameters:
activated-- Returns:
- the old value of activated
-
getDeviceHealth
Please override to provide a device health (which a malcolm device will have) The default returns null.- Specified by:
getDeviceHealthin interfaceIRunnableDevice<T>- Returns:
- the current device Health.
- Throws:
ScanningException
-
isDeviceBusy
Gets whether the device is busy or not- Specified by:
isDeviceBusyin interfaceIRunnableDevice<T>- Returns:
- the current value of the device 'busy' flag.
- Throws:
ScanningException
-
setBusy
public void setBusy(boolean busy) Call to set the busy state while the device is running. This should not be part of IRunnableDevice, it is derived by the device when it is running or set by the scanning when it is scanning on CPU devices. This means that the creator of a Detector does not have to worry about setting it busy during scans.- Parameters:
busy-
-
getRole
Description copied from interface:IDeviceRoleActorThe role of the device.- Specified by:
getRolein interfaceIDeviceRoleActor- Returns:
- role of the device
-
setRole
Description copied from interface:IDeviceRoleActorThe role of the device.- Specified by:
setRolein interfaceIDeviceRoleActor- Parameters:
role- role of the device
-
getSupportedScanModes
Description copied from interface:IDeviceRoleActorReturns a set of the scan modes that this device can participate in.- Specified by:
getSupportedScanModesin interfaceIDeviceRoleActor- Returns:
- possible roles of the device
-
setSupportedScanModes
-
setSupportedScanModes
-
setSupportedScanMode
-
getConfigureTime
public long getConfigureTime() -
setConfigureTime
public void setConfigureTime(long configureTime) -
toString
- Overrides:
toStringin classAbstractNameable
-
isAlive
public boolean isAlive()Description copied from interface:IRunnableDeviceGets whether the device is 'alive' or not. 'Alive' is taken to mean that the device is on and responding.- Specified by:
isAlivein interfaceIRunnableDevice<T>- Returns:
-
setAlive
public void setAlive(boolean alive) Description copied from interface:IRunnableDeviceSets whether the device is alive or not- Specified by:
setAlivein interfaceIRunnableDevice<T>- Parameters:
alive-
-