activemq-cpp-3.9.5
TimeUnit.h
Go to the documentation of this file.
1/*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18#ifndef _DECAF_UTIL_CONCURRENT_TIMEUNIT_H_
19#define _DECAF_UTIL_CONCURRENT_TIMEUNIT_H_
20
21#include <string>
22#include <decaf/util/Config.h>
28
29namespace decaf {
30namespace lang {
31 class Thread;
32}
33namespace util {
34namespace concurrent {
35
62 class DECAF_API TimeUnit : public decaf::lang::Comparable<TimeUnit> {
63 private:
64
66 int index;
67
69 std::string name;
70
72 static const long long multipliers[];
73
74 public:
75
77 static const TimeUnit NANOSECONDS;
78 static const TimeUnit MICROSECONDS;
79 static const TimeUnit MILLISECONDS;
80 static const TimeUnit SECONDS;
81 static const TimeUnit MINUTES;
82 static const TimeUnit HOURS;
83 static const TimeUnit DAYS;
84
86 static const TimeUnit* const values[];
87
88 protected:
89
95 TimeUnit( int index, const std::string& name );
96
97 public:
98
99 virtual ~TimeUnit() {}
100
116 long long convert( long long sourceDuration, const TimeUnit& sourceUnit ) const;
117
126 long long toNanos( long long duration ) const {
127 return doConvert( this->index, NANOSECONDS.index, duration );
128 }
129
138 long long toMicros( long long duration ) const {
139 return doConvert( this->index, MICROSECONDS.index, duration );
140 }
141
150 long long toMillis( long long duration ) const {
151 return doConvert( this->index, MILLISECONDS.index, duration );
152 }
153
160 long long toSeconds( long long duration ) const {
161 return doConvert( this->index, SECONDS.index, duration );
162 }
163
170 long long toMinutes( long long duration ) const {
171 return doConvert( this->index, MINUTES.index, duration );
172 }
173
180 long long toHours( long long duration ) const {
181 return doConvert( this->index, HOURS.index, duration );
182 }
183
190 long long toDays( long long duration ) const {
191 return doConvert( this->index, DAYS.index, duration );
192 }
193
220 void timedWait( Synchronizable* obj, long long timeout ) const;
221
235 void timedJoin( decaf::lang::Thread* thread, long long timeout );
236
244 void sleep( long long timeout ) const;
245
250 virtual std::string toString() const;
251
252 public: // Static Methods
253
266 static const TimeUnit& valueOf( const std::string& name );
267
268 public:
269
270 virtual int compareTo( const TimeUnit& value ) const;
271
272 virtual bool equals( const TimeUnit& value ) const;
273
274 virtual bool operator==( const TimeUnit& value ) const;
275
276 virtual bool operator<( const TimeUnit& value ) const;
277
278 private:
279
280 /* Perform the actual conversion */
281 long long doConvert( int srcIndex, int destIndex, long long duration ) const;
282
283 /*
284 * Utility method to compute the excess-nanosecond argument to
285 * wait, sleep, join.
286 */
287 int excessNanos( long long time, long long ms ) const;
288
295 static long long scale( long long duration, long long multiplier, long long overflow );
296
297 };
298
299}}}
300
301#endif /*_DECAF_UTIL_CONCURRENT_TIMEUNIT_H_*/
This interface imposes a total ordering on the objects of each class that implements it.
Definition Comparable.h:33
A Thread is a concurrent unit of execution.
Definition Thread.h:64
The interface for all synchronizable objects (that is, objects that can be locked and unlocked).
Definition Synchronizable.h:37
static const TimeUnit MICROSECONDS
Definition TimeUnit.h:78
long long toNanos(long long duration) const
Equivalent to NANOSECONDS.convert(duration, this).
Definition TimeUnit.h:126
virtual bool operator==(const TimeUnit &value) const
void timedWait(Synchronizable *obj, long long timeout) const
Perform a timed Object.wait using this time unit.
long long convert(long long sourceDuration, const TimeUnit &sourceUnit) const
Convert the given time duration in the given unit to this unit.
long long toDays(long long duration) const
Equivalent to DAYS.convert(duration, this).
Definition TimeUnit.h:190
TimeUnit(int index, const std::string &name)
Hidden Constructor, this class can not be instantiated directly.
void sleep(long long timeout) const
Perform a Thread.sleep using this unit.
static const TimeUnit MILLISECONDS
Definition TimeUnit.h:79
static const TimeUnit NANOSECONDS
The Actual TimeUnit enumerations.
Definition TimeUnit.h:77
static const TimeUnit MINUTES
Definition TimeUnit.h:81
static const TimeUnit *const values[]
The An Array of TimeUnit Instances.
Definition TimeUnit.h:86
virtual bool equals(const TimeUnit &value) const
static const TimeUnit HOURS
Definition TimeUnit.h:82
static const TimeUnit SECONDS
Definition TimeUnit.h:80
long long toMillis(long long duration) const
Equivalent to MILLISECONDS.convert(duration, this).
Definition TimeUnit.h:150
long long toMicros(long long duration) const
Equivalent to MICROSECONDS.convert(duration, this).
Definition TimeUnit.h:138
static const TimeUnit & valueOf(const std::string &name)
Returns the TimeUnit constant of this type with the specified name.
virtual bool operator<(const TimeUnit &value) const
static const TimeUnit DAYS
Definition TimeUnit.h:83
virtual int compareTo(const TimeUnit &value) const
long long toMinutes(long long duration) const
Equivalent to MINUTES.convert(duration, this).
Definition TimeUnit.h:170
virtual std::string toString() const
Converts the TimeUnit type to the Name of the TimeUnit.
long long toSeconds(long long duration) const
Equivalent to SECONDS.convert(duration, this).
Definition TimeUnit.h:160
void timedJoin(decaf::lang::Thread *thread, long long timeout)
Perform a timed Thread.join using this time unit.
virtual ~TimeUnit()
Definition TimeUnit.h:99
long long toHours(long long duration) const
Equivalent to HOURS.convert(duration, this).
Definition TimeUnit.h:180
#define DECAF_API
Definition Config.h:29
Definition ThreadingTypes.h:31
Definition AbstractExecutorService.h:28
Definition AbstractCollection.h:33
Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements.
Definition AprPool.h:25