Class OBlock

  • All Implemented Interfaces:
    java.beans.PropertyChangeListener, java.lang.Comparable<NamedBean>, java.util.EventListener, PropertyChangeProvider, NamedBean, PhysicalLocationReporter

    public class OBlock
    extends Block
    implements java.beans.PropertyChangeListener
    OBlock extends jmri.Block to be used in Logix Conditionals and Warrants. It is the smallest piece of track that can have occupancy detection. A better name would be Detection Circuit. However, an OBlock can be defined without an occupancy sensor and used to calculate routes.

    Additional states are defined to indicate status of the track and trains to control panels. A jmri.Block has a PropertyChangeListener on the occupancy sensor and the OBlock will pass state changes of the occ.sensor on to its Warrant.

    Entrances (exits when train moves in opposite direction) to OBlocks have Portals. A Portal object is a pair of OBlocks. Each OBlock has a list of its Portals.

    When an OBlock (Detection Circuit) has a Portal whose entrance to the OBlock has a signal, then the OBlock and its chains of adjacent OBlocks up to the next OBlock having an entrance Portal with a signal, can be considered a "Block" in the sense of a prototypical railroad. Preferably all entrances to the "Block" should have entrance Portals with a signal.

    A Portal has a list of paths (OPath objects) for each OBlock it separates. The paths are determined by the turnout settings of the turnouts contained in the block. Paths are contained within the Block boundaries. Names of OPath objects only need be unique within an OBlock.

    • Constructor Detail

      • OBlock

        public OBlock​(@Nonnull
                      java.lang.String systemName,
                      java.lang.String userName)
    • Method Detail

      • getLocalStatusName

        public static java.lang.String getLocalStatusName​(java.lang.String str)
      • getSystemStatusName

        public static java.lang.String getSystemStatusName​(java.lang.String str)
      • equals

        public boolean equals​(java.lang.Object obj)
        Description copied from class: Block
        Note: this has to make choices about identity values (always the same) and operation values (can change as the block works). Might be missing some identity values.
        equals in class Block
        obj - the reference object with which to compare.
        true if this object is the same as the obj argument; false otherwise.
      • setSensor

        public boolean setSensor​(java.lang.String pName)
        Set the sensor by name. Fires propertyChange "OccupancySensorChange" when changed.

        Override to only set an existing sensor and to amend state with not UNDETECTED return true if an existing Sensor is set or sensor is to be removed from block.

        setSensor in class Block
        pName - the name of the Sensor to set
        true if a Sensor is set and is not null; false otherwise
      • setNamedSensor

        public void setNamedSensor​(NamedBeanHandle<Sensor> namedSensor)
        Description copied from class: Block
        Set Block Occupancy Sensor. If Sensor set, Adds PCL, sets Block Occupancy Status to Sensor. Block State PropertyChange Event will fire. Does NOT route initial Sensor Status via goingUnknown() / goingActive() etc.

        If Sensor null, removes PCL on previous Sensor, sets Block status to UNDETECTED.

        setNamedSensor in class Block
        namedSensor - Handle for Sensor.
      • setErrorSensor

        public boolean setErrorSensor​(java.lang.String pName)
        pName - name of error sensor
        true if successful
      • propertyChange

        public void propertyChange​(java.beans.PropertyChangeEvent evt)
        Specified by:
        propertyChange in interface java.beans.PropertyChangeListener
      • isPathSet

        protected java.lang.String isPathSet​(java.lang.String path)
        Another block sharing a turnout with this block queries whether turnout is in use.
        path - that uses a common shared turnout
        If warrant exists and path==pathname, return warrant display name, else null.
      • setState

        public void setState​(int v)
        Update the Oblock status. Override Block because change must come from an OBlock for Web Server to receive it
        Specified by:
        setState in interface NamedBean
        setState in class Block
        v - the new state, from OBlock.ALLOCATED etc, named 'status' in JSON Servlet and Web Server
      • setValue

        public void setValue​(java.lang.Object o)
        Set the value retained by this Block. Also used when the Block itself gathers a value from an adjacent Block. This can be overridden in a subclass if e.g. you want to keep track of Blocks elsewhere, but make sure you also eventually invoke the super.setValue() here. Fires propertyChange "value" when changed.
        setValue in class Block
        o - The new Object resident in this block, or null if none
      • statusIs

        public boolean statusIs​(java.lang.String statusName)
      • isDark

        public boolean isDark()
      • occupiedBy

        public java.lang.String occupiedBy()
      • isFree

        public boolean isFree()
        Test that block is not occupied and not allocated
        true if not occupied and not allocated
      • allocate

        public java.lang.String allocate​(Warrant warrant)
        Allocate (reserves) the block for the Warrant Note the block may be OCCUPIED by a non-warranted train, but the allocation is permitted.
        warrant - the Warrant
        message with if block is already allocated to another warrant or block is OUT_OF_SERVICE
      • allocatePath

        public java.lang.String allocatePath​(java.lang.String pathName)
        Note path name may be set if block is not allocated to a warrant. For use by CircuitBuilder Only. (test paths for editCircuitPaths)
        pathName - name of a path
        error message, otherwise null
      • deAllocate

        public boolean deAllocate​(Warrant warrant)
        Remove allocation state // maybe restore this? Remove listener regardless of ownership
        warrant - warrant that has reserved this block. null is allowed for Conditionals and CircuitBuilder to reset the block. Otherwise, null should not be used.
        true if warrant deallocated.
      • setError

        public void setError​(boolean set)
      • addPortal

        public void addPortal​(Portal portal)
        Enforce unique portal names. Portals are now managed beans since 2014. This enforces unique names.
        portal - the Portal to add
      • setLength

        public void setLength​(float len)
        Description copied from class: Block
        Set length in millimeters. Paths will inherit this length, if their length is not specifically set. This length is the maximum length of any Path in the block. Path lengths exceeding this will be set to the default length.

        Fires propertyChange "BlockLengthChange" when changed, float values in mm.

        setLength in class Block
        len - length in millimeters
      • addPath

        public boolean addPath​(OPath path)
        Enforce unique path names within OBlock, but allow a duplicate name of an OPath from another OBlock to be checked if it is in one of the OBlock's Portals.
        path - the OPath to add
        true if path was added to OBlock
      • setPath

        protected java.lang.String setPath​(java.lang.String pathName,
                                           Warrant warrant)
        Set Turnouts for the path.

        Called by warrants to set turnouts for a train it is able to run. The warrant parameter verifies that the block is indeed allocated to the warrant. If the block is unwarranted then the block is allocated to the calling warrant. A logix conditional may also call this method with a null warrant parameter for manual logix control. If the block is under a different warrant the call will be rejected.

        pathName - name of the path
        warrant - warrant the block is allocated to
        error message if the call fails. null if the call succeeds
      • pseudoPropertyChange

        public void pseudoPropertyChange​(java.lang.String propName,
                                         java.lang.Object old,
                                         java.lang.Object n)
      • goingInactive

        public void goingInactive()
        (Override) Handles Block sensor going INACTIVE: this block is empty. Called by handleSensorChange
        goingInactive in class Block
      • goingActive

        public void goingActive()
        (Override) Handles Block sensor going ACTIVE: this block is now occupied, figure out from who and copy their value. Called by handleSensorChange
        goingActive in class Block
      • dispose

        public void dispose()
        Description copied from class: AbstractNamedBean
        Deactivate this object, so that it releases as many resources as possible and no longer effects others.

        For example, if this object has listeners, after a call to this method it should no longer notify those listeners. Any native or system-wide resources it maintains should be released, including threads, files, etc.

        It is an error to invoke any other methods on this object once dispose() has been called. Note, however, that there is no guarantee about behavior in that case.

        Afterwards, references to this object may still exist elsewhere, preventing its garbage collection. But it's formally dead, and shouldn't be keeping any other objects alive. Therefore, this method should null out any references to other objects that this NamedBean contained.

        Specified by:
        dispose in interface NamedBean
        dispose in class AbstractNamedBean
      • getBeanType

        public java.lang.String getBeanType()
        Description copied from interface: NamedBean
        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
        getBeanType in class Block
        a string of the bean type, eg Turnout, Sensor etc