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 Details

  • Constructor Details

    • AbstractRunnableDevice

      protected AbstractRunnableDevice(IRunnableDeviceService dservice)
      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

      public IRunnableDeviceService getRunnableDeviceService()
    • setRunnableDeviceService

      public void setRunnableDeviceService(IRunnableDeviceService runnableDeviceService)
    • getConnectorService

      public IScannableDeviceService getConnectorService()
    • setConnectorService

      public void setConnectorService(IScannableDeviceService connectorService)
    • getLevel

      public int getLevel()
      Description copied from interface: ILevel
      get the operation level of this scannable.
      Specified by:
      getLevel in interface ILevel
      Returns:
      int - the level
    • setLevel

      public void setLevel(int level)
      Description copied from interface: ILevel
      Used for ordering the operations of Scannables during scans
      Specified by:
      setLevel in interface ILevel
      Parameters:
      level -
    • reset

      public void reset() throws ScanningException
      Description copied from interface: IResettableDevice
      Allowed from Fault. Will try to reset the device into Idle state. Will block until the device is in a rest state.
      Specified by:
      reset in interface IResettableDevice
      Throws:
      ScanningException
    • setDeviceState

      protected void setDeviceState(DeviceState newDeviceState) throws ScanningException
      Parameters:
      newDeviceState -
      Throws:
      ScanningException
    • getDeviceState

      public DeviceState getDeviceState() throws ScanningException
      Specified by:
      getDeviceState in interface IRunnableDevice<T>
      Returns:
      the current device State. This is not the same as the Status of the scan.
      Throws:
      ScanningException
    • getScanId

      public String getScanId()
    • setScanId

      public void setScanId(String scanId)
    • getPublisher

      public IPublisher<ScanBean> getPublisher()
    • setPublisher

      public void setPublisher(IPublisher<ScanBean> publisher)
    • addRunListener

      public void addRunListener(IRunListener l)
      Description copied from interface: IRunnableEventDevice
      A 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:
      addRunListener in interface IRunnableEventDevice<T>
    • removeRunListener

      public void removeRunListener(IRunListener l)
      Description copied from interface: IRunnableEventDevice
      A 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:
      removeRunListener in interface IRunnableEventDevice<T>
    • fireStateChanged

      protected void fireStateChanged(DeviceState oldState, DeviceState newState) throws ScanningException
      Throws:
      ScanningException
    • fireRunWillPerform

      public void fireRunWillPerform(IPosition position) throws ScanningException
      Description copied from interface: IRunnableEventDevice
      Called 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:
      fireRunWillPerform in interface IRunnableEventDevice<T>
      Parameters:
      position -
      Throws:
      ScanningException
    • fireRunPerformed

      public void fireRunPerformed(IPosition position) throws ScanningException
      Description copied from interface: IRunnableEventDevice
      Called 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:
      fireRunPerformed in interface IRunnableEventDevice<T>
      Parameters:
      position -
      Throws:
      ScanningException
    • fireWriteWillPerform

      public void fireWriteWillPerform(IPosition position) throws ScanningException
      Description copied from interface: IRunnableEventDevice
      Called 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:
      fireWriteWillPerform in interface IRunnableEventDevice<T>
      Parameters:
      position -
      Throws:
      ScanningException
    • fireWritePerformed

      public void fireWritePerformed(IPosition position) throws ScanningException
      Description copied from interface: IRunnableEventDevice
      Called 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:
      fireWritePerformed in interface IRunnableEventDevice<T>
      Parameters:
      position -
      Throws:
      ScanningException
    • getModel

      public T getModel()
      Description copied from interface: IRunnableDevice
      The model being used for the device.
      Specified by:
      getModel in interface IModelProvider<T>
      Specified by:
      getModel in interface IRunnableDevice<T>
      Returns:
    • setModel

      public void setModel(T model)
      Description copied from interface: IModelProvider
      The model for some providers may be set but be warned that others throw an IllegalArgumentException.
      Specified by:
      setModel in interface IModelProvider<T>
      Parameters:
      model -
    • configure

      public void configure(T model) throws ScanningException
      Description copied from interface: IConfigurable
      Call to configure the device. If the model provided is invalid, a scanning exception will be thrown.
      Specified by:
      configure in interface IConfigurable<T>
      Parameters:
      model -
      Throws:
      ScanningException
    • abort

      public void abort() throws ScanningException, InterruptedException
      Description copied from interface: IRunnableDevice
      Call to terminate the scan before it has finished.
      Specified by:
      abort in interface IRunnableDevice<T>
      Throws:
      ScanningException
      InterruptedException
    • disable

      public void disable() throws ScanningException
      Description copied from interface: IRunnableDevice
      Call to disable the device, stopping all activity.
      Specified by:
      disable in interface IRunnableDevice<T>
      Throws:
      ScanningException
    • pause

      public void pause() throws ScanningException, InterruptedException
      Description copied from interface: IPausableDevice
      Allowed 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:
      pause in interface IPausableDevice<T>
      Throws:
      ScanningException
      InterruptedException
    • seek

      public void seek(int stepNumber) throws ScanningException, InterruptedException
      Description copied from interface: IPausableDevice
      Seek to/from a point number (absolute) in the scan.
      Specified by:
      seek in interface IPausableDevice<T>
      Throws:
      ScanningException
      InterruptedException
    • resume

      public void resume() throws ScanningException, InterruptedException
      Description copied from interface: IPausableDevice
      Allowed 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:
      resume in interface IPausableDevice<T>
      Throws:
      ScanningException
      InterruptedException
    • getScanAttributeNames

      public Set<String> getScanAttributeNames()
      Specified by:
      getScanAttributeNames in interface IScanAttributeContainer
      Returns:
      null if no attributes, otherwise collection of the names of the attributes set
    • setScanAttribute

      public <A> void setScanAttribute(String attributeName, A value) throws Exception
      Set any attribute the implementing classes may provide
      Specified by:
      setScanAttribute in interface IScanAttributeContainer
      Parameters:
      attributeName - is the name of the attribute
      value - is the value of the attribute
    • getScanAttribute

      public <A> A getScanAttribute(String attributeName) throws Exception
      Get the value of the specified attribute
      Specified by:
      getScanAttribute in interface IScanAttributeContainer
      Parameters:
      attributeName - is the name of the attribute
      Returns:
      the value of the attribute
    • getDeviceInformation

      public final DeviceInformation<T> getDeviceInformation() throws ScanningException
      Do not override without calling super.getDeviceInformation() Method is final for now to help avoid that problem.
      Returns:
      Throws:
      ScanningException
    • getDeviceInformation

      public DeviceInformation<T> getDeviceInformation(boolean includeNonAlive) throws ScanningException
      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

      public void setDeviceInformation(DeviceInformation<T> deviceInformation)
    • validate

      public T validate(T model)
      If overriding don't forget the old super.validate(...)
      Specified by:
      validate in interface IValidator<T>
      Parameters:
      model - - a model of type T to validate
      Returns:
      a valid model
    • isActivated

      public boolean isActivated()
      Specified by:
      isActivated in interface IActivatable
      Returns:
      true if device is activated.
    • setActivated

      public boolean setActivated(boolean activated)
      Specified by:
      setActivated in interface IActivatable
      Parameters:
      activated -
      Returns:
      the old value of activated
    • getDeviceHealth

      public String getDeviceHealth() throws ScanningException
      Please override to provide a device health (which a malcolm device will have) The default returns null.
      Specified by:
      getDeviceHealth in interface IRunnableDevice<T>
      Returns:
      the current device Health.
      Throws:
      ScanningException
    • isDeviceBusy

      public boolean isDeviceBusy() throws ScanningException
      Gets whether the device is busy or not
      Specified by:
      isDeviceBusy in interface IRunnableDevice<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

      public DeviceRole getRole()
      Description copied from interface: IDeviceRoleActor
      The role of the device.
      Specified by:
      getRole in interface IDeviceRoleActor
      Returns:
      role of the device
    • setRole

      public void setRole(DeviceRole role)
      Description copied from interface: IDeviceRoleActor
      The role of the device.
      Specified by:
      setRole in interface IDeviceRoleActor
      Parameters:
      role - role of the device
    • getSupportedScanModes

      public Set<ScanMode> getSupportedScanModes()
      Description copied from interface: IDeviceRoleActor
      Returns a set of the scan modes that this device can participate in.
      Specified by:
      getSupportedScanModes in interface IDeviceRoleActor
      Returns:
      possible roles of the device
    • setSupportedScanModes

      public void setSupportedScanModes(Set<ScanMode> supportedScanModes)
    • setSupportedScanModes

      protected void setSupportedScanModes(ScanMode... supportedScanModes)
    • setSupportedScanMode

      public void setSupportedScanMode(ScanMode supportedScanMode)
    • getConfigureTime

      public long getConfigureTime()
    • setConfigureTime

      public void setConfigureTime(long configureTime)
    • toString

      public String toString()
      Overrides:
      toString in class AbstractNameable
    • isAlive

      public boolean isAlive()
      Description copied from interface: IRunnableDevice
      Gets whether the device is 'alive' or not. 'Alive' is taken to mean that the device is on and responding.
      Specified by:
      isAlive in interface IRunnableDevice<T>
      Returns:
    • setAlive

      public void setAlive(boolean alive)
      Description copied from interface: IRunnableDevice
      Sets whether the device is alive or not
      Specified by:
      setAlive in interface IRunnableDevice<T>
      Parameters:
      alive -