java.lang.Object
pt.unl.fct.di.novasys.babel.generic.ProtoTimer
pt.unl.fct.di.tardis.babel.iot.demos.events.DemoTimer
All Implemented Interfaces:
Cloneable

public class DemoTimer extends pt.unl.fct.di.novasys.babel.generic.ProtoTimer
The periodic "tick" timer that the Grove device demos use to do something over and over — e.g. BabelLcdDemo sets one up to scroll a new line of text onto the LCD every 1.5 s.

In Babel a timer is just an event you schedule on your own protocol with setupTimer / setupPeriodicTimer; when it fires, Babel delivers it back to the handler you registered for TIMER_ID via registerTimerHandler. This class carries no behaviour — it is only a typed marker the event loop hands back to that handler. The optional timestamp lets a handler tell instances apart if it cares (the demos mostly don't).

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final short
    Babel timer id for this demo timer (matches DemoTimer.TIMER_ID in the handler registration).
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a tick stamped with the current wall-clock time.
    DemoTimer(long ts)
    Creates a tick carrying a caller-supplied timestamp.
  • Method Summary

    Modifier and Type
    Method
    Description
    pt.unl.fct.di.novasys.babel.generic.ProtoTimer
    Babel clones a timer each time a periodic timer re-fires.
    long
     

    Methods inherited from class pt.unl.fct.di.novasys.babel.generic.ProtoTimer

    getId

    Methods inherited from class java.lang.Object

    equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • TIMER_ID

      public static final short TIMER_ID
      Babel timer id for this demo timer (matches DemoTimer.TIMER_ID in the handler registration).
      See Also:
  • Constructor Details

    • DemoTimer

      public DemoTimer()
      Creates a tick stamped with the current wall-clock time.
    • DemoTimer

      public DemoTimer(long ts)
      Creates a tick carrying a caller-supplied timestamp.
  • Method Details

    • clone

      public pt.unl.fct.di.novasys.babel.generic.ProtoTimer clone()
      Babel clones a timer each time a periodic timer re-fires. Because this timer is immutable (stateless apart from a read-only timestamp), there is nothing to copy: returning this is the Babel convention for a stateless ProtoTimer and avoids a needless allocation per tick.
      Specified by:
      clone in class pt.unl.fct.di.novasys.babel.generic.ProtoTimer
    • getTimestamp

      public long getTimestamp()
      Returns:
      the timestamp this tick was created with.