Package jmri.managers

Class AbstractSensorManager

    • Method Detail

      • 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.
      • getSensor

        public Sensor getSensor​(@Nonnull
                                java.lang.String name)
        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
      • newSensor

        @Nonnull
        public Sensor newSensor​(@Nonnull
                                java.lang.String systemName,
                                java.lang.String userName)
                         throws java.lang.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:
        java.lang.IllegalArgumentException - if cannot create the Sensor due to e.g. an illegal name or name that can't be parsed.
      • getBeanTypeHandled

        @Nonnull
        public java.lang.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

        public java.lang.Class<SensorgetNamedBeanClass()
        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
                                                  java.lang.String systemName,
                                                  java.lang.String userName)
                                           throws java.lang.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:
        java.lang.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

        @Nonnull
        public java.lang.String createSystemName​(@Nonnull
                                                 java.lang.String curAddress,
                                                 @Nonnull
                                                 java.lang.String prefix)
                                          throws JmriException
        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.
      • 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.