org.jboss.cdi.tck.util
Class Timer

java.lang.Object
  extended by org.jboss.cdi.tck.util.Timer

public class Timer
extends Object

Delays thread execution for specified time or unless stop conditions are satisfied according to actual resolutionLogic.

Setting the sleep interval to value less than 15 ms is questionable since some operating systems do not provide such precision. Moreover such values may impact test performance.

In case of no stop conditions are specified, timer logic corresponds to regular Thread.sleep(long) execution.


Nested Class Summary
static class Timer.ResolutionLogic
           
static interface Timer.StopCondition
           
 
Constructor Summary
Timer()
          Create new timer with default delay and sleep interval.
 
Method Summary
 Timer addStopCondition(Timer.StopCondition condition)
          Add new stop condition.
 Timer addStopCondition(Timer.StopCondition condition, boolean clear)
          Add new stop condition.
 void clearStopConditions()
          Clear stop conditions and reset stopConditionsSatisfiedBeforeTimeout.
 boolean isStopConditionsSatisfiedBeforeTimeout()
           
 void reset()
          Reset to default values.
 Timer setDelay(long delay)
          Set new delay value.
 Timer setResolutionLogic(Timer.ResolutionLogic resolutionLogic)
          Set new resolution logic.
 Timer setSleepInterval(long sleepInterval)
          Set new sleep interval value.
 Timer start()
          Start the timer.
static Timer startNew(long delay)
          Start a new timer with specified delay.
static Timer startNew(long delay, long sleepInterval)
          Start a new timer with specified delay and sleep interval.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Timer

public Timer()
Create new timer with default delay and sleep interval.

Parameters:
delay -
Method Detail

setDelay

public Timer setDelay(long delay)
Set new delay value.

Parameters:
delay -
Returns:
self

setSleepInterval

public Timer setSleepInterval(long sleepInterval)
Set new sleep interval value.

Parameters:
sleepInterval -
Returns:
self

setResolutionLogic

public Timer setResolutionLogic(Timer.ResolutionLogic resolutionLogic)
Set new resolution logic.

Parameters:
resolutionLogic -
Returns:
self

addStopCondition

public Timer addStopCondition(Timer.StopCondition condition)
Add new stop condition.

Parameters:
condition -
Returns:
self

addStopCondition

public Timer addStopCondition(Timer.StopCondition condition,
                              boolean clear)
Add new stop condition.

Parameters:
condition -
clear - Clear stop conditions and reset stopConditionsSatisfiedBeforeTimeout
Returns:
self

start

public Timer start()
            throws InterruptedException
Start the timer.

Throws:
InterruptedException

reset

public void reset()
Reset to default values.


clearStopConditions

public void clearStopConditions()
Clear stop conditions and reset stopConditionsSatisfiedBeforeTimeout.


isStopConditionsSatisfiedBeforeTimeout

public boolean isStopConditionsSatisfiedBeforeTimeout()
Returns:
true if stop conditions are satisfied according to actual resolutionLogic before timeout occurs, false otherwise

startNew

public static Timer startNew(long delay)
                      throws InterruptedException
Start a new timer with specified delay.

Parameters:
delay -
Returns:
finished timer
Throws:
InterruptedException

startNew

public static Timer startNew(long delay,
                             long sleepInterval)
                      throws InterruptedException
Start a new timer with specified delay and sleep interval.

Parameters:
delay -
Returns:
finished timer
Throws:
InterruptedException


Copyright © 2008-2012 Seam Framework. All Rights Reserved.