java.lang.Object
stormpot.Timeout
A Timeout represents the maximum amount of time a caller is willing to wait
for a blocking operation to complete.
Timeouts are independent of their units, so two timeouts of equivalent duration but constructed in different units, will be equal to each other and work exactly the same.
Timeouts are also independent of "calendar time" in the sense that they represent and work as a duration of absolute time. In other words, timeouts do not grow or shrink with passing leap seconds or daylight savings time adjustments.
- Author:
- Chris Vest
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanTimeouts of equivalent duration are equal, even if they were constructed with different units.Get the unit of precision for the underlying clock.longGet the timeout value in terms of theunit.longGet the timeout value in terms of thebase unit.getUnit()Get the unit for thetimeout value.inthashCode()
-
Constructor Details
-
Timeout
Construct a new timeout with the given value and unit. The unit cannot benull, but the timeout value is unrestricted. The meaning of a negative timeout value is specific to the implementation of the use site, but typically means that no amount of blocking or waiting is tolerated.- Parameters:
timeout- A numerical value for the timeout. Can be zero or negative, though the meaning is implementation specific.unit- The unit of the timeout value. Nevernull.
-
Timeout
Construct a new timeout with the given duration. An exception will be thrown if the duration cannot be converted to a nanosecond quantity. The duration also cannot benull. Apart from these two, there are no restrictions on the duration.- Parameters:
duration- A duration to use for the timeout.
-
-
Method Details
-
getTimeout
public long getTimeout()Get the timeout value in terms of theunit.- Returns:
- A numerical value of the timeout. Possibly zero or negative.
-
getUnit
Get the unit for thetimeout value.- Returns:
- The
TimeUnitof the timeout value. Nevernull.
-
getTimeoutInBaseUnit
public long getTimeoutInBaseUnit()Get the timeout value in terms of thebase unit.- Returns:
- A numerical value of the timeout. Possibly zero or negative.
-
getBaseUnit
Get the unit of precision for the underlying clock.- Returns:
- TimeUnit The unit of precision used by the clock in this Timeout.
-
hashCode
public int hashCode() -
equals
Timeouts of equivalent duration are equal, even if they were constructed with different units.
-