Class DefaultRoute

    • Constructor Detail

      • DefaultRoute

        public DefaultRoute​(java.lang.String systemName,
                            java.lang.String userName)
        Constructor for a Route instance with a given userName.
        Parameters:
        systemName - suggested system name
        userName - provided user name
      • DefaultRoute

        public DefaultRoute​(java.lang.String systemName)
        Constructor for a Route instance.
        Parameters:
        systemName - suggested system name
    • Method Detail

      • getBeanType

        public java.lang.String getBeanType()
        For instances in the code where we are dealing with just a bean and a message needs to be passed to the user or in a log.
        Specified by:
        getBeanType in interface NamedBean
        Returns:
        a string of the bean type, eg Turnout, Sensor etc
      • getEnabled

        public boolean getEnabled()
        Get enabled status.
        Specified by:
        getEnabled in interface Route
        Returns:
        true if enabled; false otherwise
      • setEnabled

        public void setEnabled​(boolean v)
        Set enabled status.
        Specified by:
        setEnabled in interface Route
        Parameters:
        v - true if enabled; false otherwise
      • getLocked

        public boolean getLocked()
        Get locked status.
        Specified by:
        getLocked in interface Route
        Returns:
        true if locked; false otherwise
      • setLocked

        public void setLocked​(boolean v)
        Set locked status.
        Specified by:
        setLocked in interface Route
        Parameters:
        v - true if locked; false otherwise
      • canLock

        public boolean canLock()
        Has at least one lockable turnout.
        Specified by:
        canLock in interface Route
        Returns:
        true if lockable; false otherwise
      • addOutputTurnout

        public boolean addOutputTurnout​(java.lang.String turnoutName,
                                        int turnoutState)
        Add an output Turnout to this Route.
        Specified by:
        addOutputTurnout in interface Route
        Parameters:
        turnoutName - The turnout system name
        turnoutState - must be Turnout.CLOSED, Turnout.THROWN, or Route.TOGGLE, which determines how the Turnout is to be switched when this Route is set
        Returns:
        true if the output turnout was added
      • getOutputTurnoutByIndex

        public java.lang.String getOutputTurnoutByIndex​(int index)
        Get an output Turnout system name by index.
        Specified by:
        getOutputTurnoutByIndex in interface Route
        Parameters:
        index - the index of the turnout
        Returns:
        the turnout system name or null if no turnout exists at index
      • isOutputTurnoutIncluded

        public boolean isOutputTurnoutIncluded​(java.lang.String turnoutName)
                                        throws java.lang.IllegalArgumentException
        Inquire if a Turnout is included in this Route as an output.
        Specified by:
        isOutputTurnoutIncluded in interface Route
        Parameters:
        turnoutName - the system name of the turnout
        Returns:
        true if the named turnout is an output; false otherwise
        Throws:
        java.lang.IllegalArgumentException
      • getOutputTurnoutSetState

        public int getOutputTurnoutSetState​(java.lang.String name)
                                     throws java.lang.IllegalArgumentException
        get the Set State of an output Turnout.
        Specified by:
        getOutputTurnoutSetState in interface Route
        Parameters:
        name - the system name of the turnout
        Returns:
        the state or -1 if the Turnout is not found
        Throws:
        java.lang.IllegalArgumentException
      • getOutputTurnout

        public Turnout getOutputTurnout​(int k)
        Get the output Turnout by index.
        Specified by:
        getOutputTurnout in interface Route
        Parameters:
        k - the index of the turnout
        Returns:
        the turnout or null if no turnout exists at index
      • getOutputTurnoutState

        public int getOutputTurnoutState​(int k)
        Get the desired state of the Turnout by index.
        Specified by:
        getOutputTurnoutState in interface Route
        Parameters:
        k - the index of the turnout
        Returns:
        the turnout state or -1 if no turnout exists at index
      • addOutputSensor

        public boolean addOutputSensor​(java.lang.String sensorName,
                                       int state)
        Add an output Sensor to this Route.
        Specified by:
        addOutputSensor in interface Route
        Parameters:
        sensorName - the sensor system name
        state - the state the sensor switches to when the Route is set; must be one of Sensor.ACTIVE, Sensor.INACTIVE, or Route.TOGGLE
        Returns:
        true if the sensor was added; false otherwise
      • getOutputSensorByIndex

        public java.lang.String getOutputSensorByIndex​(int index)
        Get an output Sensor system name by index.
        Specified by:
        getOutputSensorByIndex in interface Route
        Parameters:
        index - the index of the sensor
        Returns:
        the sensor or null if no sensor exists at index
      • isOutputSensorIncluded

        public boolean isOutputSensorIncluded​(java.lang.String sensorName)
                                       throws java.lang.IllegalArgumentException
        Inquire if a Sensor is included in this Route as an output.
        Specified by:
        isOutputSensorIncluded in interface Route
        Parameters:
        sensorName - the Sensor system name
        Returns:
        true if the sensor is an output in this Route
        Throws:
        java.lang.IllegalArgumentException
      • getOutputSensorSetState

        public int getOutputSensorSetState​(java.lang.String name)
                                    throws java.lang.IllegalArgumentException
        Get the Set State of an output Sensor.
        Specified by:
        getOutputSensorSetState in interface Route
        Parameters:
        name - the system name of the Sensor
        Returns:
        -1 if the Sensor is not found
        Throws:
        java.lang.IllegalArgumentException
      • getOutputSensor

        public Sensor getOutputSensor​(int k)
        Get the output Sensor by index.
        Specified by:
        getOutputSensor in interface Route
        Parameters:
        k - the index of the sensor
        Returns:
        the sensor or null if no sensor exists at index
      • getOutputSensorState

        public int getOutputSensorState​(int k)
        Get the desired state of an output Sensor by index.
        Specified by:
        getOutputSensorState in interface Route
        Parameters:
        k - the index of the sensor
        Returns:
        the sensor state or -1 if no sensor exists at index
      • setOutputScriptName

        public void setOutputScriptName​(java.lang.String filename)
        Set name of script file to be run when Route is fired.
        Specified by:
        setOutputScriptName in interface Route
        Parameters:
        filename - path to script
      • getOutputScriptName

        public java.lang.String getOutputScriptName()
        Get name of script file to be run when Route is fired.
        Specified by:
        getOutputScriptName in interface Route
        Returns:
        script path or null if not defined
      • setOutputSoundName

        public void setOutputSoundName​(java.lang.String filename)
        Set name of sound file to be played when Route is fired.
        Specified by:
        setOutputSoundName in interface Route
        Parameters:
        filename - path to sound
      • getOutputSoundName

        public java.lang.String getOutputSoundName()
        Get name of sound file to be played when Route is fired.
        Specified by:
        getOutputSoundName in interface Route
        Returns:
        sound file path or null if not defined
      • setTurnoutsAlignedSensor

        public void setTurnoutsAlignedSensor​(java.lang.String sensorName)
                                      throws java.lang.IllegalArgumentException
        Set a sensor to be the turnouts aligned sensor.
        Specified by:
        setTurnoutsAlignedSensor in interface Route
        Parameters:
        sensorName - the system name of the sensor; pass null to disassociate any sensor from this route
        Throws:
        java.lang.IllegalArgumentException
      • addSensorToRoute

        public boolean addSensorToRoute​(java.lang.String sensorName,
                                        int mode)
        Add a Sensor to the list of control Sensors for this Route.
        Specified by:
        addSensorToRoute in interface Route
        Parameters:
        sensorName - system name of the sensor
        mode - the default state of the sensor
        Returns:
        true if added; false otherwise
      • getRouteSensorName

        public java.lang.String getRouteSensorName​(int index)
        Get the SystemName of a control Sensor in this Route.
        Specified by:
        getRouteSensorName in interface Route
        Parameters:
        index - The index in the Sensor array of the requested Sensor
        Returns:
        null If there is no Sensor at index
      • getRouteSensor

        public Sensor getRouteSensor​(int index)
        Get the Sensor of a control Sensor in this Route.
        Specified by:
        getRouteSensor in interface Route
        Parameters:
        index - The index in the Sensor array of the requested Sensor
        Returns:
        null If there is no Sensor with at index
      • getRouteSensorMode

        public int getRouteSensorMode​(int index)
        Get the state of a particular Sensor in this Route.
        Specified by:
        getRouteSensorMode in interface Route
        Parameters:
        index - The index in the Sensor array of the requested Sensor
        Returns:
        ONACTIVE if there is no Sensor with at index
      • setControlTurnout

        public void setControlTurnout​(java.lang.String turnoutName)
                               throws java.lang.IllegalArgumentException
        Set the control Turnout for this Route.
        Specified by:
        setControlTurnout in interface Route
        Parameters:
        turnoutName - the system name of a turnout
        Throws:
        java.lang.IllegalArgumentException
      • getControlTurnout

        public java.lang.String getControlTurnout()
        Get the SystemName of the control Turnout for this Route.
        Specified by:
        getControlTurnout in interface Route
        Returns:
        the name of the control turnout or null if not set
      • getCtlTurnout

        @CheckForNull
        public Turnout getCtlTurnout()
                              throws java.lang.IllegalArgumentException
        Get the Turnout of a control Turnout for this Route.
        Specified by:
        getCtlTurnout in interface Route
        Returns:
        the control turnout or null if not set
        Throws:
        java.lang.IllegalArgumentException
      • setLockControlTurnout

        public void setLockControlTurnout​(@CheckForNull
                                          java.lang.String turnoutName)
                                   throws java.lang.IllegalArgumentException
        Set the lock control Turnout for this Route.
        Specified by:
        setLockControlTurnout in interface Route
        Parameters:
        turnoutName - the system name of the turnout
        Throws:
        java.lang.IllegalArgumentException
      • getLockControlTurnout

        public java.lang.String getLockControlTurnout()
        Get the SystemName of the lock control Turnout for this Route.
        Specified by:
        getLockControlTurnout in interface Route
        Returns:
        the system name or null if not defined
      • getLockCtlTurnout

        @CheckForNull
        public Turnout getLockCtlTurnout()
                                  throws java.lang.IllegalArgumentException
        Get the Turnout of a lock control Turnout for this Route.
        Specified by:
        getLockCtlTurnout in interface Route
        Returns:
        the turnout or null if not defined
        Throws:
        java.lang.IllegalArgumentException
      • setRouteCommandDelay

        public void setRouteCommandDelay​(int delay)
        Set the delay between issuing Turnout commands on this route.
        Specified by:
        setRouteCommandDelay in interface Route
        Parameters:
        delay - the delay in milliseconds
      • setControlTurnoutFeedback

        public void setControlTurnoutFeedback​(boolean turnoutFeedbackIsCommanded)
        Set the feedback to use when checking the control turnout state
        Specified by:
        setControlTurnoutFeedback in interface Route
        Parameters:
        turnoutFeedbackIsCommanded - true if commanded state is to be checked; default is false
      • setRoute

        public void setRoute()
        Set the Route.

        Sets all Route Turnouts to the directed state in the Route definition.

        Specified by:
        setRoute in interface Route
      • checkSensor

        protected void checkSensor​(int newState,
                                   int oldState,
                                   Sensor sensor)
        Handle sensor update event to see if it will set the route.

        Called when a "KnownState" event is received, it assumes that only one sensor is changing right now, so can use state calls for everything other than this sensor.

        This will fire the Route if the conditions are correct.

        Returns nothing explicitly, but has the side effect of firing route.

        Parameters:
        newState - new state of control sensor
        oldState - former state
        sensor - Sensor used as Route control sensor
      • checkTurnout

        void checkTurnout​(int newState,
                          int oldState,
                          Turnout t)
        Turnout has changed, check to see if this fires.

        Will fire Route if appropriate.

        Parameters:
        newState - new state of control turnout
        oldState - former state
        t - Turnout used as Route control turnout
      • checkLockTurnout

        void checkLockTurnout​(int newState,
                              int oldState,
                              Turnout t)
        Turnout has changed, check to see if this will lock or unlock route.
        Parameters:
        newState - new state of lock turnout
        oldState - former turnout state
        t - Turnout used for locking the Route
      • checkTurnoutAlignment

        public void checkTurnoutAlignment()
        Method to check if the turnouts for this route are correctly aligned. Sets turnouits aligned sensor (if there is one) to active if the turnouts are aligned. Sets the sensor to inactive if they are not aligned
      • activateRoute

        public void activateRoute()
        Activate the Route.

        This starts route processing by connecting to inputs, etc. A Route must be activated before it will fire.

        Specified by:
        activateRoute in interface Route
      • isVetoed

        boolean isVetoed()
        Internal method to check whether operation of the route has been vetoed by a sensor or turnout setting.
        Returns:
        true if veto, i.e. don't fire route; false if no veto, OK to fire
      • deActivateRoute

        public void deActivateRoute()
        Deactivate the Route.

        This disconnects the Route from all other objects and stops it from processing. A Route must be deactivated before its input and output definitions are changed.

        Specified by:
        deActivateRoute in interface Route
      • setRouteBusy

        protected void setRouteBusy​(boolean busy)
        Mark the Route as transistioning to an Sensor.ACTIVE state.
        Parameters:
        busy - true if Route should be busy.
      • isRouteBusy

        protected boolean isRouteBusy()
        Method to query if Route is busy (returns true if commands are being issued to Route turnouts)
        Returns:
        true if the Route is transistioning to an Sensor.ACTIVE state, false otherwise.
      • getState

        public int getState()
        Provide generic access to internal state.

        This generally shouldn't be used by Java code; use the class-specific form instead (e.g. getCommandedState in Turnout). This is provided to make scripts easier to read.

        Specified by:
        getState in interface NamedBean
        Returns:
        the state
      • setState

        public void setState​(int state)
        Provide generic access to internal state.

        This generally shouldn't be used by Java code; use the class-specific form instead (e.g. setCommandedState in Turnout). This is provided to make scripts access easier to read.

        Specified by:
        setState in interface NamedBean
        Parameters:
        state - the state
      • vetoableChange

        public void vetoableChange​(java.beans.PropertyChangeEvent evt)
                            throws java.beans.PropertyVetoException
        Specified by:
        vetoableChange in interface NamedBean
        Specified by:
        vetoableChange in interface java.beans.VetoableChangeListener
        Overrides:
        vetoableChange in class AbstractNamedBean
        Throws:
        java.beans.PropertyVetoException