org.erights.e.extern.timer
Class Timer

java.lang.Object
  |
  +--org.erights.e.extern.timer.Timer

public class Timer
extends Object

Untamed: The master control object for timers and clocks.

Conceptually, there's one ephemeral (non-persistent) Timer per vat, but actually there's just one per JVM, where each delayed event remembers which vat it came from, and, when its time comes due, queues that event on that vat. Conceptually, when a vat is shut down, its per-vat-Timer is destroyed with it, freeing all its delayed events. Actually, nothing in the per-jvm-Timer is effected by a vat shutdown, but when these events come due, the attempt to queue them on their originating (and now, shut down) vat will silently fail.

If you build a virtual persistent Timer on top of the ephemeral Timer + org.erights.e.extern.persist.SturdyRefMaker#onRevival, be sure to cancel the onRevival when the timer event is received, not when it is sent. If you cancel the onRevival when the timer event is sent, and if your vat checkpoints after it is sent and before its received, and if your vat then revives from that checkpoint, then your event will be undelivered and lost. To do the cancellation on reception, your virtualization should wrap the real event with a persistent cancelling event.

Author:
Chip Morningstar, Mark S. Miller

Field Summary
private  TimerThread myThread
          Our timer thread
private static Timer TheTimer
          The single permitted instance of this class
 
Constructor Summary
private Timer()
          Private constructor.
 
Method Summary
 void __printOn(TextWriter out)
          Enabled:
 Clock every(long resolution, TickReactor target)
          Enabled: Creates a new clock.
 long now()
          Enabled: The current time in absolute millis
static Timer theTimer()
          Enabled: XXX Return the single permitted Timer object.
 Timeout whenAlarm(long absMillis, Runnable target)
          Enabled: Sets an alarm to occur after the specified time, unless cancelled.
 Ref whenPast(long absMillis, Object target, String verb, Object[] args)
          Enabled: When the current time is >= absMillis, evaluate
target <- verb(args...).
 Ref whenPast(long absMillis, Thunk target)
          Enabled: Sets a timeout to occur after the specified time.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TheTimer

private static final Timer TheTimer
The single permitted instance of this class


myThread

private TimerThread myThread
Our timer thread

Constructor Detail

Timer

private Timer()
Private constructor. Just start the timer thread.

Method Detail

now

public long now()
Enabled: The current time in absolute millis


whenAlarm

public Timeout whenAlarm(long absMillis,
                         Runnable target)
Enabled: Sets an alarm to occur after the specified time, unless cancelled.

After the alarm expires, target is eventually sent the run() message.

Parameters:
absMillis - When should the alarm go off?
target - Object to be informed when the time comes
Returns:
A Timeout object that can be used to cancel or identify the timeout.

whenPast

public Ref whenPast(long absMillis,
                    Object target,
                    String verb,
                    Object[] args)
Enabled: When the current time is >= absMillis, evaluate
target <- verb(args...).

Remembers the SendingContext info.

Returns:
a promise for the result of the send.

whenPast

public Ref whenPast(long absMillis,
                    Thunk target)
Enabled: Sets a timeout to occur after the specified time.

After the timer expires, target is eventually sent the run() message.

Parameters:
absMillis - When to time out
target - A thunk to be informed when the time comes
Returns:
A promise for the result of evaluating the thunk.

every

public Clock every(long resolution,
                   TickReactor target)
Enabled: Creates a new clock. The new clock begins life stopped with its tick count at zero.

Parameters:
resolution - The clock tick interval
target - Object to be sent tick notifications
Returns:
A new Clock object according to the given parameters
See Also:
org.erights.e.extern.timer.TickReactor

__printOn

public void __printOn(TextWriter out)
               throws IOException
Enabled:

IOException

theTimer

public static Timer theTimer()
Enabled: XXX Return the single permitted Timer object.

There shouldn't be a single one.



comments?