From adfea171e68298b9b0ced9fe54c2232b963e077e Mon Sep 17 00:00:00 2001 From: Gordon Sim Date: Mon, 29 Mar 2010 18:15:42 +0000 Subject: QPID-2406: a more explicit solution for durations in the messaging api git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk/qpid@928855 13f79535-47bb-0310-9956-ffa450edef68 --- cpp/include/qpid/messaging/Duration.h | 19 +++++++++++++++---- cpp/include/qpid/messaging/Receiver.h | 8 ++++---- cpp/include/qpid/messaging/Session.h | 4 ++-- 3 files changed, 21 insertions(+), 10 deletions(-) (limited to 'cpp/include/qpid') diff --git a/cpp/include/qpid/messaging/Duration.h b/cpp/include/qpid/messaging/Duration.h index 5f95acf04d..a127e86f29 100644 --- a/cpp/include/qpid/messaging/Duration.h +++ b/cpp/include/qpid/messaging/Duration.h @@ -22,7 +22,6 @@ * */ #include "qpid/sys/IntegerTypes.h" -#include namespace qpid { namespace messaging { @@ -30,9 +29,21 @@ namespace messaging { /** * A duration is a time in milliseconds. */ -typedef uint64_t Duration; -const Duration INFINITE_DURATION = std::numeric_limits::max(); -const Duration DURATION_SEC = 1000; +class Duration +{ + public: + explicit Duration(uint64_t milliseconds); + uint64_t getMilliseconds() const; + static const Duration INFINITE; + static const Duration IMMEDIATE; + static const Duration SECOND; + static const Duration MINUTE; + private: + uint64_t milliseconds; +}; + +Duration operator*(const Duration& duration, uint64_t multiplier); +Duration operator*(uint64_t multiplier, const Duration& duration); }} // namespace qpid::messaging diff --git a/cpp/include/qpid/messaging/Receiver.h b/cpp/include/qpid/messaging/Receiver.h index 80b58106d7..f0b9a7d66e 100644 --- a/cpp/include/qpid/messaging/Receiver.h +++ b/cpp/include/qpid/messaging/Receiver.h @@ -53,7 +53,7 @@ class Receiver : public qpid::messaging::Handle * available. Returns false if there is no message to give after * waiting for the specified timeout. */ - QPID_CLIENT_EXTERN bool get(Message& message, Duration timeout=INFINITE_DURATION); + QPID_CLIENT_EXTERN bool get(Message& message, Duration timeout=Duration::INFINITE); /** * Retrieves a message from this receivers local queue, or waits * for up to the specified timeout for a message to become @@ -62,7 +62,7 @@ class Receiver : public qpid::messaging::Handle *@exception NoMessageAvailable if there is no message to give * after waiting for the specified timeout. */ - QPID_CLIENT_EXTERN Message get(Duration timeout=INFINITE_DURATION); + QPID_CLIENT_EXTERN Message get(Duration timeout=Duration::INFINITE); /** * Retrieves a message for this receivers subscription or waits * for up to the specified timeout for one to become @@ -70,7 +70,7 @@ class Receiver : public qpid::messaging::Handle * that there is no message for the subscription this receiver is * serving before returning false. */ - QPID_CLIENT_EXTERN bool fetch(Message& message, Duration timeout=INFINITE_DURATION); + QPID_CLIENT_EXTERN bool fetch(Message& message, Duration timeout=Duration::INFINITE); /** * Retrieves a message for this receivers subscription or waits * for up to the specified timeout for one to become @@ -81,7 +81,7 @@ class Receiver : public qpid::messaging::Handle *@exception NoMessageAvailable if there is no message to give * after waiting for the specified timeout. */ - QPID_CLIENT_EXTERN Message fetch(Duration timeout=INFINITE_DURATION); + QPID_CLIENT_EXTERN Message fetch(Duration timeout=Duration::INFINITE); /** * Sets the capacity for the receiver. The capacity determines how * many incoming messages can be held in the receiver before being diff --git a/cpp/include/qpid/messaging/Session.h b/cpp/include/qpid/messaging/Session.h index 032b678c5c..bc5aaed6ba 100644 --- a/cpp/include/qpid/messaging/Session.h +++ b/cpp/include/qpid/messaging/Session.h @@ -102,7 +102,7 @@ class Session : public qpid::messaging::Handle * which case the passed in receiver reference will be set to the * receiver for that message or false if no message was available. */ - QPID_CLIENT_EXTERN bool nextReceiver(Receiver&, Duration timeout=INFINITE_DURATION); + QPID_CLIENT_EXTERN bool nextReceiver(Receiver&, Duration timeout=Duration::INFINITE); /** * Returns the receiver for the next available message. If there * are no available messages at present the call will block for up @@ -111,7 +111,7 @@ class Session : public qpid::messaging::Handle *@exception Receiver::NoMessageAvailable if no message became available in * time. */ - QPID_CLIENT_EXTERN Receiver nextReceiver(Duration timeout=INFINITE_DURATION); + QPID_CLIENT_EXTERN Receiver nextReceiver(Duration timeout=Duration::INFINITE); /** * Create a new sender through which messages can be sent to the -- cgit v1.2.1