de.michab.simulator
Class Clock.ClockHandle

java.lang.Object
  extended byde.michab.simulator.Clock.ClockHandle
Enclosing class:
Clock

public class Clock.ClockHandle
extends java.lang.Object

Each clock client receives a ClockHandle as the result of performing the register() operation. This handle is used for further communication with the clock. The client is responsible to call prepare() on the clock handle as soon as it is ready to be scheduled.

See Also:
prepare()

Method Summary
 long advance(int ticks)
          Advances the local time of this client for the given number of ticks.
 long currentLocalTime()
          Returns the client's local time.
 long currentTime()
          Returns the current time of the Clock.
 void prepare()
          Signals to the Clock that the calling thread is ready to be scheduled.
 long reschedule()
          Signals that the thread that is responsible for this handle is ready to be scheduled again.
 long stealTicks(int number)
          experimental
 long unschedule()
          Remove the calling thread from the list of threads that can be scheduled.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

prepare

public void prepare()
Signals to the Clock that the calling thread is ready to be scheduled. Actual scheduling for all registered Clock clients is started by a call to Clock.start(). As a result each thread calling prepare() is blocked until scheduling is started.


advance

public long advance(int ticks)
Advances the local time of this client for the given number of ticks. The calling thread is subject to a thread switch.

Parameters:
ticks - The number of ticks to advance.
Returns:
This client's local time. The value returned here is equivalent to a call to currentLocalTime() but prevents another call.
Throws:
java.lang.IllegalArgumentException - This is thrown if zero is passed.
See Also:
currentLocalTime()

stealTicks

public long stealTicks(int number)
experimental

Parameters:
number - The number of ticks to steal.
Returns:
The updated time.

unschedule

public long unschedule()
                throws java.lang.InterruptedException
Remove the calling thread from the list of threads that can be scheduled. The calling thread will be blocked until reschedule() is called.

Returns:
The current local time of the newly scheduled client.
Throws:
java.lang.InterruptedException

reschedule

public long reschedule()
Signals that the thread that is responsible for this handle is ready to be scheduled again. Note that this must not (cannot) be called from the actual thread that is to be scheduled again since this is blocked in unschedule(). Instead reschedule() has to be called from a different thread. The calling thread will not be blocked.

Returns:
The current local time of the newly scheduled client.

currentLocalTime

public long currentLocalTime()
Returns the client's local time. Note that advance() also returns the local time.

Returns:
The local time.
See Also:
advance(int)

currentTime

public long currentTime()
Returns the current time of the Clock. This represents overall clock time which is different and normally earlier than the clock client's local time.

Returns:
The current clock time.
See Also:
Clock.currentTime(), currentLocalTime()