seda.sandStorm.core
Class ssTimer

java.lang.Object
  extended by seda.sandStorm.core.ssTimer
All Implemented Interfaces:
java.lang.Runnable, ProfilableIF

public class ssTimer
extends java.lang.Object
implements java.lang.Runnable, ProfilableIF

The ssTimer class provides a mechanism for registering timer events that will go off at some future time. The future time can be specified in absolute or relative terms. When the timer goes off, an element is placed on a queue. There is no way to unregister a timer. Events will be delivered guaranteed, but the time that they are delivered may slip depending on stuff like how loaded the system is and all that.

WARNING: you should use cancelEvent to cancel timers that you no longer need, otherwise you will waste many, many cycles on unneeded timer firings. This was the bottleneck in vSpace and the DDS before we fixed it. For example, if you set a timer to go off on a cross-CPU task to detect failure, then if the task returns successfully, cancel the timer!

WARNING: delivery is NOT guaranteed given the use of enqueue_lossy().


Nested Class Summary
private static class ssTimer.GQEString
           
static class ssTimer.ssTimerEvent
           
 
Field Summary
private static int DEBUG_LEVEL
           
private  boolean die_thread
           
private  ssTimer.ssTimerEvent head_event
           
private  int num_events
           
private  java.lang.Object sync_o
           
private  ssTimer.ssTimerEvent tail_event
           
private  java.lang.Thread thr
           
 
Constructor Summary
ssTimer()
           
 
Method Summary
 void cancelAll()
          Cancel all events, removing them from the queue.
 void cancelEvent(ssTimer.ssTimerEvent evt)
          Cancels the firing of this timer event.
private static boolean DEBUG(int n)
           
 void doneWithTimer()
          Kills off this timer object, dropping all pending events on floor.
private  void insertEvent(ssTimer.ssTimerEvent newTimer)
           
static void main(java.lang.String[] args)
           
private  void process_head()
          called by run() with a lock on sync_o and an event in the queue
 int profileSize()
          Return the profile size of this timer.
 ssTimer.ssTimerEvent registerEvent(java.util.Date the_date, QueueElementIF obj, SinkIF queue)
          Object obj will be placed on SinkIF queue no earlier than absolute time the_date.
 ssTimer.ssTimerEvent registerEvent(long millis, QueueElementIF obj, SinkIF queue)
          Object obj will be placed on SinkIF queue no earlier than millis milliseconds from now.
 void run()
          loop while die_thread==false, processing events as they are queued
 int size()
          How many events yet to fire?
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEBUG_LEVEL

private static final int DEBUG_LEVEL
See Also:
Constant Field Values

head_event

private ssTimer.ssTimerEvent head_event

tail_event

private ssTimer.ssTimerEvent tail_event

thr

private java.lang.Thread thr

sync_o

private java.lang.Object sync_o

die_thread

private boolean die_thread

num_events

private int num_events
Constructor Detail

ssTimer

public ssTimer()
Method Detail

DEBUG

private static final boolean DEBUG(int n)

registerEvent

public ssTimer.ssTimerEvent registerEvent(long millis,
                                          QueueElementIF obj,
                                          SinkIF queue)
Object obj will be placed on SinkIF queue no earlier than millis milliseconds from now.

Parameters:
millis - the number of milliseconds from now when the event will take place
obj - the object that will be placed on the queue
queue - the queue on which the object will be placed

registerEvent

public ssTimer.ssTimerEvent registerEvent(java.util.Date the_date,
                                          QueueElementIF obj,
                                          SinkIF queue)
Object obj will be placed on SinkIF queue no earlier than absolute time the_date.

Parameters:
the_date - the date when the event will take place - if this date is in the past, the event will happen right away
obj - the object that will be placed on the queue
queue - the queue on which the object will be placed

doneWithTimer

public void doneWithTimer()
Kills off this timer object, dropping all pending events on floor.


size

public int size()
How many events yet to fire?


profileSize

public int profileSize()
Return the profile size of this timer.

Specified by:
profileSize in interface ProfilableIF

cancelAll

public void cancelAll()
Cancel all events, removing them from the queue.


cancelEvent

public void cancelEvent(ssTimer.ssTimerEvent evt)
Cancels the firing of this timer event.

Parameters:
evt - the ssTimer.ssTimerEvent to cancel. This ssTimerEvent is returned to you when you call registerEvent

insertEvent

private void insertEvent(ssTimer.ssTimerEvent newTimer)

process_head

private void process_head()
called by run() with a lock on sync_o and an event in the queue


run

public void run()
loop while die_thread==false, processing events as they are queued

Specified by:
run in interface java.lang.Runnable

main

public static void main(java.lang.String[] args)