Class SimpleTimebase

  • All Implemented Interfaces:
    java.lang.Comparable<NamedBean>, PropertyChangeProvider, NamedBean, Timebase

    public class SimpleTimebase
    extends AbstractNamedBean
    implements Timebase
    Provide basic Timebase implementation from system clock.

    This implementation provides for the internal clock and for one hardware clock. A number of hooks and comments are provided below for implementing multiple hardware clocks should that ever be done.

    The setTimeValue member is the fast time when the clock started. The startAtTime member is the wall-clock time when the clock was started. Together, those can be used to calculate the current fast time.

    The pauseTime member is used to indicate that the Timebase was paused. If non-null, it indicates the current fast time when the clock was paused.

    • Method Detail

      • init

        final void init()
      • 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
      • getTime

        public java.util.Date getTime()
        Get the current time.
        Specified by:
        getTime in interface Timebase
        Returns:
        current time.
      • setTime

        public void setTime​(java.util.Date d)
        Set the current time.
        Specified by:
        setTime in interface Timebase
        Parameters:
        d - the new time
      • setTime

        public void setTime​(java.time.Instant i)
        Set the current time.
        Specified by:
        setTime in interface Timebase
        Parameters:
        i - the new time
      • userSetTime

        public void userSetTime​(java.util.Date d)
        Set the current time and force a synchronization with the DCC system.
        Specified by:
        userSetTime in interface Timebase
        Parameters:
        d - the new time
      • setRun

        public void setRun​(boolean run)
        Set if Timebase is running.
        Specified by:
        setRun in interface Timebase
        Parameters:
        run - true if running else false.
      • getRun

        public boolean getRun()
        Get if Timebase is running.
        Specified by:
        getRun in interface Timebase
        Returns:
        true if running, else false.
      • getRate

        public double getRate()
        Caution: This method may return a fiddled clock rate if certain hardware clocks are the Time Source. Use Timebase.userGetRate() if you want the real clock rate instead.
        Specified by:
        getRate in interface Timebase
        Returns:
        the rate
      • userGetRate

        public double userGetRate()
        Get the true fast clock rate even if the master timebase rate has been modified by a hardware clock. External changes in fast clock rate occur because of the peculiar way some hardware clocks attempt to synchronize with the JMRI fast clock.
        Specified by:
        userGetRate in interface Timebase
        Returns:
        the rate
      • setInternalMaster

        public void setInternalMaster​(boolean master,
                                      boolean update)
        Set internalMaster and update fields.
        Specified by:
        setInternalMaster in interface Timebase
        Parameters:
        master - true if fast clock time is derived from internal computer clock, false if derived from hardware clock.
        update - true to send update, else false.
      • getInternalMaster

        public boolean getInternalMaster()
        Get internalMaster field.
        Specified by:
        getInternalMaster in interface Timebase
        Returns:
        true if fast clock time is derived from internal computer clock, false if derived from hardware clock
      • setMasterName

        public void setMasterName​(java.lang.String name)
        Set the Master Clock Name.
        Specified by:
        setMasterName in interface Timebase
        Parameters:
        name - master clock name.
      • setSynchronize

        public void setSynchronize​(boolean synchronize,
                                   boolean update)
        Set if clock should synchronise.
        Specified by:
        setSynchronize in interface Timebase
        Parameters:
        synchronize - set true to synchronise hardware clocks with Time base.
        update - set true to update clock when function called.
      • getSynchronize

        public boolean getSynchronize()
        Get if clock should synchronise with Time base.
        Specified by:
        getSynchronize in interface Timebase
        Returns:
        true if should synchronise hardware clocks.
      • setCorrectHardware

        public void setCorrectHardware​(boolean correct,
                                       boolean update)
        If update true, calls initializeHardwareClock. Set if should correct or update hardware.
        Specified by:
        setCorrectHardware in interface Timebase
        Parameters:
        correct - set true to correct hardware clocks.
        update - set true to update clock when function called.
      • set12HourDisplay

        public void set12HourDisplay​(boolean display,
                                     boolean update)
        Set 12 or 24 hour display option.
        Specified by:
        set12HourDisplay in interface Timebase
        Parameters:
        display - true for a 12-hour display; false for a 24-hour display
        update - true to update clock when function called.
      • use12HourDisplay

        public boolean use12HourDisplay()
        Get 12 or 24 hour display option.
        Specified by:
        use12HourDisplay in interface Timebase
        Returns:
        true for a 12-hour display; false for a 24-hour display
      • setShowStopButton

        public void setShowStopButton​(boolean displayed)
        Set if to show a Stop / Resume button next to the clock.
        Specified by:
        setShowStopButton in interface Timebase
        Parameters:
        displayed - true if to display, else false.
      • getShowStopButton

        public boolean getShowStopButton()
        Get if to show a Stop / Resume button next to the clock.
        Specified by:
        getShowStopButton in interface Timebase
        Returns:
        true if to display, else false.
      • setStartSetTime

        public void setStartSetTime​(boolean set,
                                    java.util.Date time)
        Set time at start up option, and start up time.
        Specified by:
        setStartSetTime in interface Timebase
        Parameters:
        set - true for set time at startup, else false.
        time - startup time.
      • setStartRate

        public void setStartRate​(double factor)
        Set the start clock speed rate.
        Specified by:
        setStartRate in interface Timebase
        Parameters:
        factor - start clock speed factor.
      • getStartRate

        public double getStartRate()
        Get the startup clock speed rate.
        Specified by:
        getStartRate in interface Timebase
        Returns:
        startup clock speed rate factor.
      • setSetRateAtStart

        public void setSetRateAtStart​(boolean set)
        Set Set Rate at Start option.
        Specified by:
        setSetRateAtStart in interface Timebase
        Parameters:
        set - If true, the rate at startup will be set to the value of getStartRate().
      • getSetRateAtStart

        public boolean getSetRateAtStart()
        Get if to Set Rate at Start option checked.
        Specified by:
        getSetRateAtStart in interface Timebase
        Returns:
        If true, the rate at startup should be set to the value of getStartRate()
      • setStartClockOption

        public void setStartClockOption​(int option)
        Set the Start Clock type Option.
        Specified by:
        setStartClockOption in interface Timebase
        Parameters:
        option - Clock type, e.g. NIXIE_CLOCK or PRAGOTRON_CLOCK
      • initializeClock

        public void initializeClock()
        The following method should only be invoked at start up. Initialise the clock. Should only be invoked at start up.
        Specified by:
        initializeClock in interface Timebase
      • initializeHardwareClock

        public void initializeHardwareClock()
        Initialize hardware clock at start up after all options are set up.

        Note: This method is always called at start up. It should be ignored if there is no communication with a hardware clock

        Specified by:
        initializeHardwareClock in interface Timebase
      • dispose

        public void dispose()
        Stops Timer. 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
        Specified by:
        dispose in interface Timebase
        Overrides:
        dispose in class AbstractNamedBean
      • startAlarm

        void startAlarm()
        Start the minute alarm ticking, if it isnt already.
      • handleAlarm

        void handleAlarm​(java.awt.event.ActionEvent e)
        Handle an "alarm", which is used to count off minutes.

        Listeners will be notified if the hours or minutes changed since the last time.

        Parameters:
        e - Event which triggered this
      • setState

        public void setState​(int s)
                      throws JmriException
        Implementation does nothing. 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:
        s - the state
        Throws:
        JmriException - general error when setting the state fails
      • getState

        public int getState()
        Implementation returns 0 . 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