Package jmri.managers

Class AbstractSensorManager

All Implemented Interfaces:
PropertyChangeListener, VetoableChangeListener, EventListener, PropertyChangeFirer, PropertyChangeProvider, SilenceablePropertyChangeProvider, VetoableChangeFirer, VetoableChangeProvider, Manager<Sensor>, NameIncrementingManager, ProvidingManager<Sensor>, SensorManager
Direct Known Subclasses:
AcelaSensorManager, BiDiBSensorManager, CbusSensorManager, Dcc4PcSensorManager, DCCppSensorManager, EcosSensorManager, InternalSensorManager, IpocsSensorManager, JMRIClientSensorManager, LnSensorManager, MarklinSensorManager, MqttSensorManager, NceSensorManager, OlcbSensorManager, RaspberryPiSensorManager, RfidSensorManager, RpsSensorManager, SerialSensorManager, SerialSensorManager, SerialSensorManager, SerialSensorManager, SerialSensorManager, SerialSensorManager, SRCPSensorManager, TamsSensorManager, XBeeSensorManager, XNetSensorManager, Z21SensorManager

public abstract class AbstractSensorManager extends AbstractManager<Sensor> implements SensorManager
Abstract base implementation of the SensorManager interface.
  • Field Details

  • Constructor Details

  • Method Details

    • getXMLOrder

      public int getXMLOrder()
      Determine the order that types should be written when storing panel files. Uses one of the constants defined in this class.

      Yes, that's an overly-centralized methodology, but it works for now.

      Specified by:
      getXMLOrder in interface Manager<Sensor>
      Returns:
      write order for this Manager; larger is later.
    • typeLetter

      public char typeLetter()
      Specified by:
      typeLetter in interface Manager<Sensor>
      Returns:
      The type letter for a specific implementation
    • provideSensor

      Get the Sensor with the user name, then system name if needed; if that fails, create a new Sensor. If the name is a valid system name, it will be used for the new Sensor. Otherwise, the Manager.makeSystemName(java.lang.String) method will attempt to turn it into a valid system name.

      This provides the same function as ProvidingManager.provide(java.lang.String) which has a more generic form.

      Specified by:
      provideSensor in interface SensorManager
      Parameters:
      name - User name, system name, or address which can be promoted to system name
      Returns:
      Never null
    • getSensor

      Get an existing Sensor or return null if it doesn't exist. Locates via user name, then system name if needed.
      Specified by:
      getSensor in interface SensorManager
      Parameters:
      name - User name or system name to match
      Returns:
      null if no match found
    • isNumber

      boolean isNumber(@Nonnull String s)
    • getBySystemName

      Locate an existing instance based on a system name. Special handling for numeric argument, which is treated as the suffix of a new system name
      Specified by:
      getBySystemName in interface Manager<Sensor>
      Specified by:
      getBySystemName in interface SensorManager
      Overrides:
      getBySystemName in class AbstractManager<Sensor>
      Parameters:
      key - System Name of the required NamedBean
      Returns:
      requested NamedBean object or null if none exists
    • newSensor

      @Nonnull public Sensor newSensor(@Nonnull String systemName, String userName) throws IllegalArgumentException
      Create a New Sensor. Return a Sensor with the specified user or system name. Return Sensor by UserName else provide by SystemName.

      Note that two calls with the same arguments will get the same instance; there is only one Sensor object representing a given physical turnout and therefore only one with a specific system or user name.

      This will always return a valid object reference; a new object will be created if necessary. In that case:

      • If a null reference is given for user name, no user name will be associated with the Sensor object created; a valid system name must be provided
      • If both names are provided, the system name defines the hardware access of the desired sensor, and the user address is associated with it. The system name must be valid.
      Note that it is possible to make an inconsistent request if both addresses are provided, but the given values are associated with different objects. This is a problem, and we don't have a good solution except to issue warnings. This will mostly happen if you're creating Turnouts when you should be looking them up.
      Specified by:
      newSensor in interface SensorManager
      Parameters:
      systemName - the desired system name
      userName - the desired user name
      Returns:
      requested Sensor object
      Throws:
      IllegalArgumentException - if cannot create the Sensor due to e.g. an illegal name or name that can't be parsed.
    • getBeanTypeHandled

      @Nonnull public String getBeanTypeHandled(boolean plural)
      Get the user-readable name of the type of NamedBean handled by this manager.

      For instance, in the code where we are dealing with just a bean and a message that needs to be passed to the user or in a log.

      Specified by:
      getBeanTypeHandled in interface Manager<Sensor>
      Parameters:
      plural - true to return plural form of the type; false to return singular form
      Returns:
      a string of the bean type that the manager handles, eg Turnout, Sensor etc
    • getNamedBeanClass

      Get the class of NamedBean supported by this Manager. This should be the generic class used in the Manager's class declaration.
      Specified by:
      getNamedBeanClass in interface Manager<Sensor>
      Returns:
      the class supported by this Manager.
    • createNewSensor

      @Nonnull protected abstract Sensor createNewSensor(@Nonnull String systemName, String userName) throws IllegalArgumentException
      Internal method to invoke the factory and create a new Sensor. Called after all the logic for returning an existing Sensor has been invoked. An existing SystemName is not found, existing UserName not found. Implementing classes should base Sensor on the system name, then add user name.
      Parameters:
      systemName - the system name to use for the new Sensor
      userName - the optional user name to use for the new Sensor
      Returns:
      the new Sensor
      Throws:
      IllegalArgumentException - if unsuccessful with reason for fail.
    • updateAll

      public void updateAll()
      Requests status of all layout sensors under this Sensor Manager.

      This method may be invoked whenever the status of sensors needs to be updated from the layout, for example, when an XML configuration file is read in.

      This method only needs be implemented in system-specific Sensor Managers where readout of Sensor status from the layout is possible. Delay between requesting individual Sensor status is determined by the Connection Output Interval Setting.

      Specified by:
      updateAll in interface SensorManager
    • createSystemName

      Default Sensor ensures a numeric only system name. Create a System Name from hardware address and system letter prefix. AbstractManager performs no validation.
      Specified by:
      createSystemName in interface SensorManager
      Overrides:
      createSystemName in class AbstractManager<Sensor>
      Parameters:
      curAddress - hardware address, no system prefix or type letter.
      prefix - - just system prefix, not including Type Letter.
      Returns:
      full system name with system prefix, type letter and hardware address.
      Throws:
      JmriException - if unable to create a system name.
    • getDefaultSensorDebounceGoingActive

      Specified by:
      getDefaultSensorDebounceGoingActive in interface SensorManager
    • getDefaultSensorDebounceGoingInActive

      Specified by:
      getDefaultSensorDebounceGoingInActive in interface SensorManager
    • setDefaultSensorDebounceGoingActive

      public void setDefaultSensorDebounceGoingActive(long time)
      Specified by:
      setDefaultSensorDebounceGoingActive in interface SensorManager
    • setDefaultSensorDebounceGoingInActive

      public void setDefaultSensorDebounceGoingInActive(long time)
      Specified by:
      setDefaultSensorDebounceGoingInActive in interface SensorManager
    • isPullResistanceConfigurable

      public boolean isPullResistanceConfigurable()
      Do the sensor objects provided by this manager support configuring an internal pullup or pull down resistor? This default implementation always returns false.
      Specified by:
      isPullResistanceConfigurable in interface SensorManager
      Returns:
      true if pull up/pull down configuration is supported.
    • getEntryToolTip

      Provide a manager-specific tooltip for the Add new item beantable pane.
      Specified by:
      getEntryToolTip in interface Manager<Sensor>
      Specified by:
      getEntryToolTip in interface SensorManager
      Returns:
      the tool tip or null to disable the tool tip