Package org.jboss.weld.test.util
Class Timer
- java.lang.Object
-
- org.jboss.weld.test.util.Timer
-
public class Timer extends Object
Delays thread execution for specified time or unless stop conditions are satisfied according to the actualTimer.ResolutionLogic. This class is not thread-safe.Setting the sleep interval to the 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 (not recommended), the timer logic corresponds to the regular
Thread.sleep(long)execution.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classTimer.ResolutionLogicstatic interfaceTimer.StopCondition
-
Constructor Summary
Constructors Constructor Description Timer()Create new timer with default delay, sleep interval and stop conditions resolution logic.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description TimeraddStopCondition(Timer.StopCondition condition)Add new stop condition.TimeraddStopCondition(Timer.StopCondition condition, boolean clear)Add new stop condition.voidclearStopConditions()Clear stop conditions and resetstopConditionsSatisfiedBeforeTimeout.longgetDelay()longgetSleepInterval()booleanisStopConditionsSatisfiedBeforeTimeout()voidreset()Reset to default values.TimersetDelay(long delay)Set the delay value.TimersetDelay(long delay, TimeUnit timeUnit)Set the delay value.TimersetResolutionLogic(Timer.ResolutionLogic resolutionLogic)Set new resolution logic.TimersetSleepInterval(long sleepInterval)Set new sleep interval value.Timerstart()Start the timer.static TimerstartNew(long delay)Start a new timer with specified delay.static TimerstartNew(long delay, long sleepInterval)Start a new timer with specified delay and sleep interval.
-
-
-
Method Detail
-
setDelay
public Timer setDelay(long delay)
Set the delay value. The value is automatically adjusted according to theConfiguration#getTestTimeoutFactor()so that it's possible to configure timeouts according to the testing runtime performance and throughput.- Parameters:
delay- The delay in milliseconds- Returns:
- self
-
setDelay
public Timer setDelay(long delay, TimeUnit timeUnit)
Set the delay value. The value is automatically adjusted according to theConfiguration#getTestTimeoutFactor()so that it's possible to configure timeouts according to the testing runtime performance and throughput.- Parameters:
delay-timeUnit-- 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 resetstopConditionsSatisfiedBeforeTimeout- 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 resetstopConditionsSatisfiedBeforeTimeout.
-
isStopConditionsSatisfiedBeforeTimeout
public boolean isStopConditionsSatisfiedBeforeTimeout()
- Returns:
trueif stop conditions are satisfied according to actualresolutionLogicbefore timeout occurs,falseotherwise
-
getDelay
public long getDelay()
- Returns:
- the current delay in ms
-
getSleepInterval
public long getSleepInterval()
- Returns:
- the current sleep interval in ms
-
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
-
-