activemq-cpp-3.9.0
|
A TimeUnit represents time durations at a given unit of granularity and provides utility methods to convert across units, and to perform timing and delay operations in these units. More...
#include <src/main/decaf/util/concurrent/TimeUnit.h>
Public Member Functions | |
virtual | ~TimeUnit () |
long long | convert (long long sourceDuration, const TimeUnit &sourceUnit) const |
Convert the given time duration in the given unit to this unit. More... | |
long long | toNanos (long long duration) const |
Equivalent to NANOSECONDS.convert(duration, this) . More... | |
long long | toMicros (long long duration) const |
Equivalent to MICROSECONDS.convert(duration, this) . More... | |
long long | toMillis (long long duration) const |
Equivalent to MILLISECONDS.convert(duration, this) . More... | |
long long | toSeconds (long long duration) const |
Equivalent to SECONDS.convert(duration, this) . More... | |
long long | toMinutes (long long duration) const |
Equivalent to MINUTES.convert(duration, this) . More... | |
long long | toHours (long long duration) const |
Equivalent to HOURS.convert(duration, this) . More... | |
long long | toDays (long long duration) const |
Equivalent to DAYS.convert(duration, this) . More... | |
void | timedWait (Synchronizable *obj, long long timeout) const |
Perform a timed Object.wait using this time unit. More... | |
void | timedJoin (decaf::lang::Thread *thread, long long timeout) |
Perform a timed Thread.join using this time unit. More... | |
void | sleep (long long timeout) const |
Perform a Thread.sleep using this unit. More... | |
virtual std::string | toString () const |
Converts the TimeUnit type to the Name of the TimeUnit. More... | |
virtual int | compareTo (const TimeUnit &value) const |
virtual bool | equals (const TimeUnit &value) const |
virtual bool | operator== (const TimeUnit &value) const |
virtual bool | operator< (const TimeUnit &value) const |
![]() | |
virtual | ~Comparable () |
virtual int | compareTo (const TimeUnit &value) const =0 |
Compares this object with the specified object for order. More... | |
virtual bool | equals (const TimeUnit &value) const =0 |
virtual bool | operator== (const TimeUnit &value) const =0 |
Compares equality between this object and the one passed. More... | |
virtual bool | operator< (const TimeUnit &value) const =0 |
Compares this object to another and returns true if this object is considered to be less than the one passed. More... | |
Static Public Member Functions | |
static const TimeUnit & | valueOf (const std::string &name) |
Returns the TimeUnit constant of this type with the specified name. More... | |
Static Public Attributes | |
static const TimeUnit | NANOSECONDS |
The Actual TimeUnit enumerations. More... | |
static const TimeUnit | MICROSECONDS |
static const TimeUnit | MILLISECONDS |
static const TimeUnit | SECONDS |
static const TimeUnit | MINUTES |
static const TimeUnit | HOURS |
static const TimeUnit | DAYS |
static const TimeUnit *const | values [] |
The An Array of TimeUnit Instances. More... | |
Protected Member Functions | |
TimeUnit (int index, const std::string &name) | |
Hidden Constructor, this class can not be instantiated directly. More... | |
A TimeUnit represents time durations at a given unit of granularity and provides utility methods to convert across units, and to perform timing and delay operations in these units.
A TimeUnit does not maintain time information, but only helps organize and use time representations that may be maintained separately across various contexts. A nanosecond is defined as one thousandth of a microsecond, a microsecond as one thousandth of a millisecond, a millisecond as one thousandth of a second, a minute as sixty seconds, an hour as sixty minutes, and a day as twenty four hours.
A TimeUnit is mainly used to inform time-based methods how a given timing parameter should be interpreted. For example, the following code will timeout in 50 milliseconds if the lock is not available:
Lock lock = ...; if ( lock.tryLock( 50, TimeUnit.MILLISECONDS ) ) ...
while this code will timeout in 50 seconds:
Lock lock = ...; if ( lock.tryLock( 50, TimeUnit.SECONDS ) ) ...
Note however, that there is no guarantee that a particular timeout implementation will be able to notice the passage of time at the same granularity as the given TimeUnit.
|
protected |
Hidden Constructor, this class can not be instantiated directly.
index | - Index into the Time Unit set. |
name | - Name of the unit type being represented. |
|
inlinevirtual |
long long decaf::util::concurrent::TimeUnit::convert | ( | long long | sourceDuration, |
const TimeUnit & | sourceUnit | ||
) | const |
Convert the given time duration in the given unit to this unit.
Conversions from finer to coarser granularities truncate, so lose precision. For example converting 999 milliseconds to seconds results in 0. Conversions from coarser to finer granularities with arguments that would numerically overflow saturate to Long.MIN_VALUE if negative or Long.MAX_VALUE if positive.
For example, to convert 10 minutes to milliseconds, use: TimeUnit.MILLISECONDS.convert(10L, TimeUnit.MINUTES)
sourceDuration | - Duration value to convert. |
sourceUnit | - Unit type of the source duration. |
void decaf::util::concurrent::TimeUnit::sleep | ( | long long | timeout | ) | const |
Perform a Thread.sleep
using this unit.
This is a convenience method that converts time arguments into the form required by the Thread.sleep
method.
timeout | the minimum time to sleep |
void decaf::util::concurrent::TimeUnit::timedJoin | ( | decaf::lang::Thread * | thread, |
long long | timeout | ||
) |
Perform a timed Thread.join
using this time unit.
This is a convenience method that converts time arguments into the form required by the Thread.join
method.
thread | the thread to wait for |
timeout | the maximum time to wait |
InterruptedException | if interrupted while waiting. |
NullPointerException | if the thread object is null. |
void decaf::util::concurrent::TimeUnit::timedWait | ( | Synchronizable * | obj, |
long long | timeout | ||
) | const |
Perform a timed Object.wait
using this time unit.
This is a convenience method that converts timeout arguments into the form required by the Object.wait
method.
For example, you could implement a blocking poll
method (see BlockingQueue.poll) using:
Object poll( long long timeout, const TimeUnit& unit )
while( empty ) { unit.timedWait(this, timeout); ... } }
obj | the object to wait on |
timeout | the maximum time to wait. |
InterruptedException | if interrupted while waiting. |
NullPointerException | if the Synchronizable object is null. |
|
inline |
Equivalent to DAYS.convert(duration, this)
.
duration | the duration |
|
inline |
Equivalent to HOURS.convert(duration, this)
.
duration | the duration |
|
inline |
Equivalent to MICROSECONDS.convert(duration, this)
.
duration | the duration |
Long.MIN_VALUE
if conversion would negatively overflow, or Long.MAX_VALUE
if it would positively overflow.
|
inline |
Equivalent to MILLISECONDS.convert(duration, this)
.
duration | the duration |
Long.MIN_VALUE
if conversion would negatively overflow, or Long.MAX_VALUE
if it would positively overflow.
|
inline |
Equivalent to MINUTES.convert(duration, this)
.
duration | the duration |
|
inline |
Equivalent to NANOSECONDS.convert(duration, this)
.
duration | the duration |
Long.MIN_VALUE
if conversion would negatively overflow, or Long.MAX_VALUE
if it would positively overflow. Referenced by decaf::util::concurrent::LinkedBlockingQueue< decaf::lang::Pointer< activemq::transport::Transport > >::offer(), decaf::util::concurrent::LinkedBlockingQueue< decaf::lang::Pointer< activemq::transport::Transport > >::poll(), and decaf::util::concurrent::CopyOnWriteArrayList< E >::wait().
|
inline |
Equivalent to SECONDS.convert(duration, this)
.
duration | the duration |
|
virtual |
|
static |
Returns the TimeUnit constant of this type with the specified name.
The string must match exactly an identifier used to declare an TimeUnit constant in this type. (Extraneous whitespace characters are not permitted.)
name | The Name of the TimeUnit constant to be returned. |
IllegalArgumentException | if this enum type has no constant with the specified name |
Referenced by decaf::util::concurrent::CopyOnWriteArrayList< E >::wait().
The Actual TimeUnit enumerations.
The An Array of TimeUnit Instances.