javax.realtime
Class Timer

java.lang.Object
  extended byjavax.realtime.AsyncEvent
      extended byjavax.realtime.Timer
Direct Known Subclasses:
OneShotTimer, PeriodicTimer

public abstract class Timer
extends AsyncEvent

A Timer is a timed event that measures time relative to a given Clock. This class defines basic functionality available to all timers. Applications will generally use either PeriodicTimer to create an event that is fired repeatedly at regular intervals, or OneShotTimer for an event that just fires once at a specific time. A timer is always based on a Clock, which provides the basic facilities of something that ticks along following some time line (real-time, cpu-time, user-time, simulation-time, etc.). All timers are created disabled and do nothing until start() is called.

Author:
Angelo Corsaro

Field Summary
protected  Clock clock
           
protected  boolean isEnabled
           
protected  boolean isRunning
           
 
Fields inherited from class javax.realtime.AsyncEvent
handlerList, listIterator, releaseParams
 
Constructor Summary
protected Timer(HighResolutionTime t, Clock c, AsyncEventHandler handler)
          Create a timer that fires at time t, according to Clock c and is handled by the specified handler.
 
Method Summary
 ReleaseParameters createReleaseParameters()
          Create a ReleaseParameters block appropriate to the timing characteristics of this event.
 void destroy()
          Stop this from counting and return as many of its resources as possible back to the system.
 void disable()
          Disable this timer, preventing it from firing.
 void enable()
          Re-enable this timer after it has been disabled.
 Clock getClock()
          Return the Clock that this timer is based on.
 AbsoluteTime getFireTime()
          Get the time at which this event will fire.
protected abstract  javax.realtime.TimerImpl getTimerImpl()
          This method is implemented in subclasses.
 boolean isRunning()
          Tests this to determine if this and been started and is in a state (enabled) such that when the given time occurs it will fire the event.
 void reschedule(HighResolutionTime time)
          Changes the scheduled time for this event.
 void start()
          A Timer starts measuring time from when it is started.
 boolean stop()
          Stops a timer that is running and changes its state to not started.
 
Methods inherited from class javax.realtime.AsyncEvent
addHandler, bindTo, fire, handledBy, removeHandler, setHandler, unbindTo
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

clock

protected Clock clock

isEnabled

protected boolean isEnabled

isRunning

protected boolean isRunning
Constructor Detail

Timer

protected Timer(HighResolutionTime t,
                Clock c,
                AsyncEventHandler handler)
Create a timer that fires at time t, according to Clock c and is handled by the specified handler.

Parameters:
t - The time to fire the event, Will be converted to absolute time.
c - The clock on which to base this time. If null, the system realtime clock is used.
handler - The default handler to use for this event. If null, no handler is associated with it and nothing will happen when this event fires until a handler is provided.
Method Detail

createReleaseParameters

public ReleaseParameters createReleaseParameters()
Create a ReleaseParameters block appropriate to the timing characteristics of this event. The default is the most pessimistic: AperiodicParameters. This is typically called by code that is setting up a handler for this event that will fill in the parts of the release parameters that it knows the values for, like cost.

Overrides:
createReleaseParameters in class AsyncEvent
Returns:
an instance of ReleaseParameters.

destroy

public void destroy()
Stop this from counting and return as many of its resources as possible back to the system.


disable

public void disable()
Disable this timer, preventing it from firing. It may subsequently be reenabled. If the timer is disabled when its fire time occurs then it will not fire. However, a disabled timer continues to count while it is disabled and if it is subsequently reabled before its fire time occures and is enabled when its fire time occurs it will fire. However, it is important to note that this method does not delay the time before a possible firing. For example, if the timer is set to fire at time 42 and the disable() is called at time 30 and enable() is called at time 40 the firing will occur at time 42 (not time 52). These semantics imply also, that firings are not queued. Using the above example, if enable was called at time 43 no firing will occur, since at time 42 this was disabled.


enable

public void enable()
Re-enable this timer after it has been disabled. See Timer.disable() .


getClock

public Clock getClock()
Return the Clock that this timer is based on.

Returns:
a Clock value representing the Clock that this timer is based on.

getFireTime

public AbsoluteTime getFireTime()
Get the time at which this event will fire.

Returns:
an AbsoluteTime object representing the absolute time at which this will fire.

isRunning

public boolean isRunning()
Tests this to determine if this and been started and is in a state (enabled) such that when the given time occurs it will fire the event.

Returns:
True if the timer has been started and is in the enabled state. False, if the timer has either not been started, started and is in the disabled state, or started and stopped.

reschedule

public void reschedule(HighResolutionTime time)
Changes the scheduled time for this event. It can take either absolute or relative times.

Parameters:
time - the time to reschedule for this event firing if t is null, the previous fire time is still the time at which this will fire.

start

public void start()
A Timer starts measuring time from when it is started.


stop

public boolean stop()
Stops a timer that is running and changes its state to not started.

Returns:
True, if this was started and enabled and stops this. The new state of this is not started. False, if this was not started or disabled. The state of this is not changed.

getTimerImpl

protected abstract javax.realtime.TimerImpl getTimerImpl()
This method is implemented in subclasses.



jRate is developed and maintained by the jRate project development team.
Copyright (c) 2001-2005 Angelo Corsaro and Morgan Deters.