Class DemoTimer
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
FieldsModifier and TypeFieldDescriptionstatic final shortBabel timer id for this demo timer (matchesDemoTimer.TIMER_IDin the handler registration). -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionpt.unl.fct.di.novasys.babel.generic.ProtoTimerclone()Babel clones a timer each time a periodic timer re-fires.longMethods inherited from class pt.unl.fct.di.novasys.babel.generic.ProtoTimer
getId
-
Field Details
-
TIMER_ID
public static final short TIMER_IDBabel timer id for this demo timer (matchesDemoTimer.TIMER_IDin 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: returningthisis the Babel convention for a statelessProtoTimerand avoids a needless allocation per tick.- Specified by:
clonein classpt.unl.fct.di.novasys.babel.generic.ProtoTimer
-
getTimestamp
public long getTimestamp()- Returns:
- the timestamp this tick was created with.
-