bb.util
Class TimeElapsedLatch

java.lang.Object
  extended by bb.util.TimeElapsedLatch

public class TimeElapsedLatch
extends Object

This class provides a simple latch that is set once a specified amount of time has elapsed. The amount of time that must elapse is supplied to the constructor, and the latched method may be queried to determine if this time has elapsed.

The original motivation for this class was for polling applications where the polling should only be tried for a maximum amount of time before it is considered to have failed.

Warning: this class may not operate properly if some external process resets the system clock.

This class is multithread safe: it is immutable (both its immediate state, as well as the deep state of its fields).

Author:
Brent Boyer

Field Summary
private  long timeElapsedTillLatch
           
private  long timeStarted
           
 
Constructor Summary
TimeElapsedLatch(long timeElapsedTillLatch)
          Constructor.
 
Method Summary
 boolean latched()
          Returns true once the specified amount of time has elapsed, false until then.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

timeStarted

private final long timeStarted

timeElapsedTillLatch

private final long timeElapsedTillLatch
Constructor Detail

TimeElapsedLatch

public TimeElapsedLatch(long timeElapsedTillLatch)
                 throws IllegalArgumentException
Constructor.

Parameters:
timeElapsedTillLatch - the amount of time (in milliseconds) that must elapse till this instance will latch
Throws:
IllegalArgumentException - if timeElapsedTillLatch < 0
Method Detail

latched

public boolean latched()
Returns true once the specified amount of time has elapsed, false until then.