Aztec® Programming Language
Version 1.1 Alpha 2

Copyright © 2010-2017, Aztec Development Group, All Rights Reserved

Download Aztec

Search        Contact Us

But it'll shine when it shines...

You might think I'm wastin' time...

I'm just a good ol' boy who's learned to wait.

- John Dillon and Steve Cash

 

aztec.util.Timer

public class Timer from<Base>

Base

Timer

aztec.util.ITimer

public class abstract ITimer from<Base>

Base

ITimer

The Timer class provides a mechanism to set an alarm and register event handlers to get invoked when the alarm goes off. An alarm can be set at a specific "abolute time", or it can be set to go off at a "relative time" (a specified number of seconds and/or milliseconds from when the alarm is set). For the relative time alarm, a repeat count can be specified so the alarm will go off at the specified interval for any number of times.

 

The ITimer class is an abstract interface class which contains a virtual event handler method for each event which the Timer class supports (currently just one - TimerAlarmEvent).

Timer Methods

Timer() Constructor for the Timer class
SetAlarm() Sets the alarm to go off at an absolute time (given by Time object)
SetAlarm() Sets the alarm to go off at a relative interval (given by # of milliseconds) for a specified number of times
SetAlarm() Sets the alarm to go off at a relative interval (given by TimeInterval object) for a specified number of times
IsActive() Returns true if the alarm is currently set to go off in the future
Remaining() Returns number of alarm occurrences remaining
AddTimerAlarmHandler() Registers an event handler for an alarm event using a method reference
AddTimerAlarmHandler() Registers an event handler for an alarm event using an ITimer reference
OnTimerAlarm() Default event handler for the timer alarm event

ITimer Methods

OnTimerAlarm() Virtual method to handle TimerAlarmEvent processing

Derived Classes

See Also

 


Timer()

public method Timer()

Parameters

None

Return Value

None

Description

Constructor for the Timer class.

 

Timer Class


SetAlarm()

public method SetAlarm(Time AbsoluteTime)

Parameters

AbsoluteTime

Time alarm will go off

Return Value

None

Description

Sets an alarm within the Timer object to go off at the specified time (given as a Time object). When the alarm goes off, a TimeAlarmEvent is issued for this Timer object and normal Aztec event handling takes place. The alarm will only go off once and then is turned off.

 

Timer Class


SetAlarm()

public method SetAlarm(int RelativeTime, int RepeatCount = 1)

Parameters

RelativeTime

Number of milliseconds to wait before alarm goes off

RepeatCount

Number of times alarm is to be repeated

Return Value

None

Description

Sets an alarm within the Timer object to go off at a specified interval from when the alarm is set. The RelativeTime is specified in miliseconds. If the repeat count is greater than one, the alarm goes off at the same interval for the specified number of times. If RepeatCount is zero, it will continue to issue an alarm forever using the same interval each time.

 

Timer Class


SetAlarm()

public method SetAlarm(TimeInterval RelativeTime, int RepeatCount = 1)

Parameters

RelativeTime

Number of seconds and milliseconds (based on TimeInterval contents) to wait before alarm goes off

RepeatCount

Number of times alarm is to be repeated

Return Value

None

Description

Sets an alarm within the Timer object to go off at a specified interval from when the alarm is set. The RelativeTime is specified by a TimeInterval object, which contains the number of seconds and millseconds. If the repeat count is greater than one, the alarm goes off at the same interval for the specified number of times. If RepeatCount is zero, it will continue to issue an alarm forever using the same interval each time.

 

Timer Class


IsActive()

public method<bool> IsActive()

Parameters

None

Return Value

True if alarm is currently set

Description

This method returnstrue if the Timer is currently active. If an alarm is currently set, it is said to be active.

 

Timer Class


Remaining()

public method<int> Remaining()

Parameters

None

Return Value

Returns the repeat count still remaining

Description

This method returns the number of alarm instances still remaining from the original repeat count. The original repeat count is decremented by one each time the alarm event is issued. If the repeat count was set to zero (infinite repeat), this will method also return zero.

 

Timer Class


AddTimerAlarmHandler()

public method AddTimerAlarmHandler(TimerAlarmHandler Handler, Base ExtraObject = null)

Parameters

Handler

Method reference to be executed when the event occurs

ExtraObject

Optional object which will be sent along to each event handler when it is executed

Return Value

NONE

Description

This method registers a method reference to be executed when the timer alarm goes off. An optional object can also be registered which will be sent to each event handler as it is executed.

 

As is true with all Aztec event handling, this method can be called by any thread. When the event occurs, each registered event handler is scheduled to execute within the thread that registered it. So an alarm that goes off in one thread can be handled by event handlers executing in one or more other threads.

 

The TimerAlarmHandler data type represents a method reference specific to a handler for TimerAlarmEvent. TimerAlarmHandler is defined as follows:

 

        public type<method<TimerAlarmEvent,Base>> TimerAlarmHandler

 

Given this definition, the method handler must be defined with the following signature (name can be anything):

 

        public method TimerAlarmMethod(TimerAlarmEvent event, Base Extra) { }.

 

Timer Class


AddTimerAlarmHandler()

public method AddTimerAlarmHandler(ITimer Interface, Base ExtraObject = null)

Parameters

Interface

Reference to an ITimer object

ExtraObject

Optional object which will be sent along to each event handler when it is executed

Return Value

NONE

Description

This method registers an ITimer interface object to be executed when a timer alarm goes off. An optional object can also be registered which will be sent to each event handler as it is executed.

 

As is true with all Aztec event handling, this method can be called by any thread. When the event occurs, each registered event handler is scheduled to execute within the thread that registered it. So an alarm that goes off in one thread can be handled by event handlers executing in one or more other threads.

 

When the alarm goes off and the TimerAlarmEvent is issued, the OnTimerAlarm() method within the ITimer object will be executed.

 

Timer Class


OnTimerAlarm()

public method virtual OnTimerAlarm(TimerAlarmEvent AlarmEvent, Base ExtraObject)

Parameters

AlarmEvent

TimerAlarmEvent object associated with the event

ExtraObject

Optional object sent along from when it was registered

Return Value

NONE

Description

This method is the default event handler for TimerAlarmEvent within the Timer. It is invoked internally as a result of the timer alarm going off. This method in turn executes every registered handler with the same argument list which comes in. Both implementations of the Timer.AddTimerAlarmHandler() method register the event handlers which get invoked by this method.

 

If this method is overridden by a class derived from Timer, it must call this implementation of the method if it needs to execute handlers registered with the Timer.AddTimerAlarmHandler() methods.

 

Timer Class


OnTimerAlarm()

public method virtual OnTimerAlarm(TimerAlarmEvent AlarmEvent, Base ExtraObject)

Parameters

AlarmEvent

TimerAlarmEvent object associated with the event

ExtraObject

Optional object sent along from when it was registered

Return Value

NONE

Description

This virtual method is the event handler for TimerAlarmEvent within the ITimer interface class. The method which overrides it is invoked when the alarm goes off and the interface object is registered with the Timer.AddTimerAlarmHandler() method.

 

ITimer Class

 

Copyright © 2010-2017

Aztec Development Group

All Rights Reserved

Download Aztec