Lines Matching defs:timer

30     For example, in an animation loop, a timer would help in
33 A timer has an interval which determines when it "ticks";
34 that is, a timer delays for the specified interval and then
37 Here's an example of creating a timer with a 5 sec interval:
41 public void tick(Timer timer) {
50 A timer can be stopped, continued, or reset at any time.
51 A timer's state is not stopped while it's calling the
54 A timer can be regular or irregular. If in regular mode,
55 a timer ticks at the specified interval, regardless of
56 how long the owner's tick() method takes. While the timer
61 In irregular mode, a timer starts delaying for exactly
64 Synchronization issues: do not hold the timer's monitor
75 the timer queue monitor is always acquired before the timer
76 object's monitor. However, the timer queue monitor is acquired
77 only if the timer operation will make use of the timer
81 to the timer queue.
83 Possible feature: perhaps a timer should have an associated
90 * This is the owner of the timer. Its tick method is
91 * called when the timer ticks.
104 * that the timer was stopped; otherwise, this variable
105 * is used by the TimerThread to determine when the timer
111 * This is the time remaining before the timer ticks. It
112 * is only valid if 'stopped' is true. If the timer is
119 * True iff the timer is in regular mode.
124 * True iff the timer has been stopped.
133 * A link to another timer object. This is used while the
134 * timer object is enqueued in the timer queue.
151 * Creates a timer object that is owned by 'owner' and
152 * with the interval 'interval' milliseconds. The new timer
156 * @param owner owner of the timer object
157 * @param interval interval of the timer in milliseconds
174 * Returns true if this timer is stopped.
181 * Stops the timer. The amount of time the timer has already
182 * delayed is saved so if the timer is continued, it will only
184 * Note that even after stopping a timer, one more tick may
206 * Continue the timer. The next tick will come at getRemainingTime()
207 * milliseconds later. If the timer is not stopped, this
218 // timer only if the sleepUntil value has changed.
221 // it's theoretically possible for the timer to be
233 * Resets the timer's remaining time to the timer's interval.
234 * If the timer's running state is not altered.
245 * Returns the time at which the timer was last stopped. The
246 * return value is valid only if the timer is stopped.
253 * Returns the timer's interval.
260 * Changes the timer's interval. The new interval setting
263 * running state of the timer.
264 * @param interval new interval of the timer in milliseconds
271 * Returns the remaining time before the timer's next tick.
272 * The return value is valid only if timer is stopped.
279 * Sets the remaining time before the timer's next tick.
280 * This method does not alter the timer's running state.
301 * In regular mode, a timer ticks at the specified interval,
303 * While the timer is running, no ticks are ever discarded.
308 * In irregular mode, a timer starts delaying for exactly
326 This class implements the timer queue and is exclusively used by the
328 enqueue, for inserting a timer into queue and dequeue, for removing
329 a timer from the queue.
331 A timer in the timer queue is awaiting a tick. When a timer is to be
332 ticked, it is removed from the timer queue before the owner's tick()
335 A single timer thread manages the timer queue. This timer thread
336 looks at the head of the timer queue and delays until it's time for
337 the timer to tick. When the time comes, the timer thread creates a
338 callback thread to call the timer owner's tick() method. The timer
339 thread then processes the next timer in the queue.
341 When a timer is inserted at the head of the queue, the timer thread is
342 notified. This causes the timer thread to prematurely wake up and
359 * This flag is set if the timer thread has been notified
361 * timer thread to tell whether or not the wait completed.
391 // remove from timer queue.
393 Timer timer = timerQueue;
396 timer, timer.sleepUntil);
398 long delta = (System.currentTimeMillis() - timer.sleepUntil);
400 + timer.interval + ","+delta+ ")");
414 * The timer queue is a queue of timers waiting to tick.
419 * Uses timer.sleepUntil to determine where in the queue
420 * to insert the timer object.
421 * A new ticker thread is created only if the timer
423 * The timer must not already be in the queue.
426 static protected void enqueue(Timer timer) {
430 if (cur == null || timer.sleepUntil <= cur.sleepUntil) {
432 timer.next = timerQueue;
433 timerQueue = timer;
440 } while (cur != null && timer.sleepUntil > cur.sleepUntil);
441 // insert or append to the timer queue
442 timer.next = cur;
443 prev.next = timer;
449 + ": enqueue " + timer.interval + ": ");
461 * If the timer is not in the queue, returns false;
462 * otherwise removes the timer from the timer queue and returns true.
465 static protected boolean dequeue(Timer timer) {
469 while (cur != null && cur != timer) {
476 + ": dequeue " + timer.interval + ": no-op");
480 timerQueue = timer.next;
484 prev.next = timer.next;
486 timer.next = null;
491 + ": dequeue " + timer.interval + ": ");
504 * Inserts the timer back into the queue. This method
506 * timer owner's tick() method. This method recomputes
510 protected static void requeue(Timer timer) {
511 if (!timer.stopped) {
513 if (timer.regular) {
514 timer.sleepUntil += timer.interval;
516 timer.sleepUntil = now + timer.interval;
518 enqueue(timer);
521 + ": requeue " + timer.interval + ": no-op");
529 timer owner's tick() method. A small fixed-sized pool of threads is
552 * The pool of timer threads.
562 * This is the handle to the timer whose owner's
565 Timer timer;
568 * The value of a timer's sleepUntil value is captured here.
569 * This is used to determine whether or not the timer should
570 * be reinserted into the queue. If the timer's sleepUntil
571 * value has changed, the timer is not reinserted.
576 * Creates a new callback thread to call the timer owner's
582 Timer timer, long sleepUntil) {
588 thread.timer = timer;
593 thread.timer = timer;
618 timer = null;
620 while (timer == null) {
625 // Just drop through and retest timer.
637 timer.owner.tick(timer);
639 synchronized (timer) {
640 if (lastSleepUntil == timer.sleepUntil) {
641 TimerThread.requeue(timer);