java.lang.Object
com.pervasive.datarush.commons.util.Timeout
A representation of a point-in-time when a timeout period expires. While
expressed as a duration, these always represent specific instances of
timeouts; the timeout is relative to the time at which it was created
(although it can be recalculated with the
reset() method).-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionbooleanIndicates whether the timeout period has elapsed.static Timeoutmillis(long duration) Creates a timeout expiring in the specified number of milliseconds from now.longGets the amount of time remaining before the timeout expires.reset()Resets the timeout to the full duration with which it was created.static Timeoutseconds(long duration) Creates a timeout expiring in the specified number of seconds from now.static TimeoutCreates a timeout expiring in the specified duration from now.voidWaits on the specified object using theObject.wait()method, honoring the timeout's expiration time.
-
Field Details
-
NEVER
Specifies a timeout which never expires; that is, an infinite period of time. -
IMMEDIATE
Specifies a timeout which is always expired; that is, no period of time at all.
-
-
Method Details
-
millis
Creates a timeout expiring in the specified number of milliseconds from now.- Parameters:
duration- the length of the timeout, specified in milliseconds- Returns:
- the requested timeout period
- Throws:
IllegalArgumentException- if the duration is non-positive.
-
timeout
Creates a timeout expiring in the specified duration from now.- Parameters:
duration- the length of the timeout, in the given unitunit- the time unit- Returns:
- the specified timeout
- Throws:
IllegalArgumentException- if the duration is non-positive.
-
seconds
Creates a timeout expiring in the specified number of seconds from now.- Parameters:
duration- the length of the timeout, specified in seconds- Returns:
- the requested timeout period
- Throws:
IllegalArgumentException- if the duration is non-positive.
-
hasExpired
public boolean hasExpired()Indicates whether the timeout period has elapsed.- Returns:
- true if the timeout has expired, false otherwise.
-
remainingTime
public long remainingTime()Gets the amount of time remaining before the timeout expires.- Returns:
- the time remaining until expiration, in milliseconds. If the timeout
has expired,
0is returned; if the timeout can never expire,Long.MAX_VALUEis returned.
-
waitOn
Waits on the specified object using theObject.wait()method, honoring the timeout's expiration time. If the timeout has expired, no wait will be performed.The object's monitor must already be held when invoking this method.
- Parameters:
object- the object on which to invokeObject#wait()- Throws:
InterruptedException- if the underlyingObject#wait()is interrupted.IllegalMonitorStateException- if the object's monitor is not held.
-
reset
Resets the timeout to the full duration with which it was created. This permits the reuse ofTimeoutobject in loops without requiring constant creation and destruction of objects.- Returns:
- this timeout recalculated relative to the current time
-