Package com.peterphi.std.threading
Class Timeout
java.lang.Object
com.peterphi.std.threading.Timeout
- All Implemented Interfaces:
Serializable
,Comparable<Timeout>
Represents an immutable Timeout (ie. a duration). Timeouts are distinct from Deadlines in that they do not have a start
time.
This class can be used to represent a duration without needing a dependency on Joda time
This class can be used to represent a duration without needing a dependency on Joda time
- See Also:
-
Field Summary
Modifier and TypeFieldDescriptionstatic final Timeout
Five minutesstatic final Timeout
The maximum possible timeoutstatic final Timeout
One minutestatic final Timeout
0.25 seconds (250 milliseconds)static final Timeout
One secondstatic final Timeout
Ten secondsstatic final Timeout
30 minutesstatic final Timeout
Thirty secondsstatic final Timeout
A zero-length timeout -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionint
boolean
long
Get this timeout represented in a different unitlong
Get the number of milliseconds this timeout representsint
hashCode()
static Timeout
Filter through a number of timeouts to find the one with the longest periodstatic Timeout
Filter through a number of timeouts to find the one with the shortest periodmultiply
(double by) Create a new Timeout which is equal to this timeout multiplied by some value
The resulting Timeout will be in milliseconds to maximise precision.multiply
(long by) Create a new Timeout which is equal to this timeout multiplied by some valuevoid
sleep()
Sleep for the duration of this timeout (or until the thread is interrupted)void
Sleep for the duration of this timeout (or until the thread is interrupted, or until the provided deadline expires)start()
Create a new deadline which is the given period of time in the futureCreate a new deadline within a given maximum timeframe; this preventsstatic Timeout
Adds together all the supplied timeoutsorg.joda.time.Duration
toString()
-
Field Details
-
ZERO
A zero-length timeout -
ONE_QUARTER_SECOND
0.25 seconds (250 milliseconds) -
ONE_SECOND
One second -
TEN_SECONDS
Ten seconds -
THIRTY_SECONDS
Thirty seconds -
ONE_MINUTE
One minute -
FIVE_MINUTES
Five minutes -
THIRTY_MINUTES
30 minutes -
MAX_VALUE
The maximum possible timeout
-
-
Constructor Details
-
Timeout
public Timeout(org.joda.time.Duration duration) -
Timeout
public Timeout(long milliseconds) Constructs a deadline using a given period of time- Parameters:
milliseconds
- period in milliseconds
-
Timeout
Constructs a deadline using a given period of time- Parameters:
period
- the number of unitsunit
- the unit of time being used
-
-
Method Details
-
start
Create a new deadline which is the given period of time in the future- Returns:
- a deadline the given period of time in the future
-
start
Create a new deadline within a given maximum timeframe; this prevents- Parameters:
max
- the maximum deadline- Returns:
- a new deadline which is at most the provided maximum
-
getMilliseconds
public long getMilliseconds()Get the number of milliseconds this timeout represents- Returns:
-
get
Get this timeout represented in a different unit- Parameters:
toUnit
-- Returns:
-
hashCode
public int hashCode() -
equals
-
multiply
Create a new Timeout which is equal to this timeout multiplied by some value- Parameters:
by
- the amount to multiply the current timeout by- Returns:
- a new Timeout which is equal to this timeout multiplied by some value
-
multiply
Create a new Timeout which is equal to this timeout multiplied by some value
The resulting Timeout will be in milliseconds to maximise precision.- Parameters:
by
- the amount to multiply the current timeout by- Returns:
- a new Timeout which is equal to this timeout multiplied by some value (with the unit now set to Milliseconds)
-
toString
-
toEnglishString
-
compareTo
- Specified by:
compareTo
in interfaceComparable<Timeout>
-
sleep
public void sleep()Sleep for the duration of this timeout (or until the thread is interrupted) -
sleep
Sleep for the duration of this timeout (or until the thread is interrupted, or until the provided deadline expires) -
toDuration
public org.joda.time.Duration toDuration() -
max
Filter through a number of timeouts to find the one with the longest period- Parameters:
timeouts
- a list of timeouts (nulls are ignored)- Returns:
- the timeout with the longest period
- Throws:
IllegalArgumentException
- if no non-null timeouts are presented
-
min
Filter through a number of timeouts to find the one with the shortest period- Parameters:
timeouts
- a list of timeouts (nulls are ignored)- Returns:
- the timeout with the shortest period
- Throws:
IllegalArgumentException
- if no non-null timeouts are presented
-
sum
Adds together all the supplied timeouts- Parameters:
timeouts
- a list of timeouts (nulls are ignored)- Returns:
- the sum of all the timeouts specified
-