public class MTimer extends MEventSource
MTimer
event source triggers the generation of
an MTimerEvent
after a specified time interval.
The MTimer
class provides configurable repeating and non-repeating timers.
To associate a listener with a timer, call its inherited
MEventSource.addListener()
method.
m_handlers, m_listeners
m_registry
Constructor and Description |
---|
MTimer(MApp app,
java.lang.String name,
int waitTime,
boolean isRepeating,
MEventListener listener,
boolean canStart)
Create an instance of
MTimer . |
MTimer(MComponentRegistry register,
java.lang.String name,
int waitTime,
boolean isRepeating,
MEventListener listener,
boolean canStart)
Specify the component registry on which to create an instance of
MTimer . |
Modifier and Type | Method and Description |
---|---|
void |
activate()
Start the timer; if the timer is active, restart it.
|
void |
deactivate()
Deactivate this timer.
|
int |
getInterval()
Retrieve the interval at which this timer dispatches
MTimerEvent . |
boolean |
isRepeating()
Determine whether the timer is repeating.
|
void |
setInterval(int waitTime)
Change the time interval of this timer Restart
the timer with the new interval if the timer has already been activated.
|
addListener, getListeners, hasListeners, notify, removeListener
getComponentRegistry, getName, getStatus, isActivated, remove
public MTimer(MApp app, java.lang.String name, int waitTime, boolean isRepeating, MEventListener listener, boolean canStart) throws MException
MTimer
.
If you use a timer, you should also create an instance of MEventListener
with the appropriate onEvent()
method to serve as the event handler. You can pass in
the timer to the constructor or associate the timer and the listener by calling the
timers inherited MEventSource.addListener()
method.
Timers are used in applications that poll based on a continuous interval instead of, for example, listening for data.
A timer name must be unique across one MApp
application manager.
app
- MApp
application manager for this MTimer
.name
- Name of this timer. Must be unique.waitTime
- Interval of this timer activity, in milliseconds.isRepeating
- listener
- Event listener to add to this MTimer
.canStart
- When set to true this timer is created as an active
timer. Otherwise, applications must explicitly call the activate()
method.MException
- under these conditions:
startTimer
is true, on any failure to start the timer
MTimer(MComponentRegistry, String, int, boolean, MEventListener, boolean)
public MTimer(MComponentRegistry register, java.lang.String name, int waitTime, boolean isRepeating, MEventListener listener, boolean canStart) throws MException
MTimer
.
register
- Component registry for which this MTimer
is to be created.name
- Name of this timer. Must be unique.waitTime
- Interval of this timer activity, in milliseconds.isRepeating
- listener
- Event listener to add to this MTimer
.canStart
- When set to true this timer is created as an active
timer. Otherwise, applications have to explicitly call the activate()
method.MException
- under these conditions:
startTimer
is true, on any failure to start the timer
MTimer(MApp, String, int, boolean, MEventListener, boolean)
public int getInterval()
MTimerEvent
.setInterval(int)
public void setInterval(int waitTime) throws MException
waitTime
- Interval for the timer. This is the period of time for which the timer goes off.MException
getInterval()
public boolean isRepeating()
true
if this is a repeating timer. Return false
otherwise.public void activate() throws MException
activate
in interface MComponent
activate
in class MBaseComponent
MException
- On any failure to start the timerpublic void deactivate() throws MException
If you deactivate a timer that is not active, nothing happens.
deactivate
in interface MComponent
deactivate
in class MBaseComponent
MException
- on any failure to stop the timer.activate()