class Qpid::Messaging::Duration
A Duration represents a period of time in milliseconds
Named Durations¶ ↑
The following named Durations
are available as symbols:
- FOREVER
-
The maximum integer value for the platform. Effectively this will wait forever.
- IMMEDIATE
-
An alias for 0 milliseconds.
- SECOND
-
An alias for 1,000 milliseconds.
- MINUTE
-
And alias for 60,000 millisecons.
Public Class Methods
new(length)
click to toggle source
Creates a Duration with the specified length, in milliseconds.
Options¶ ↑
-
length
- The duration inmilliseconds
.
Examples¶ ↑
# creates a duration of 15 seconds # REMEMBER: Duration deals in milliseconds delay = Qpid::Messaging::Duration.new 15000
# File lib/qpid_messaging/duration.rb, line 57 def initialize length @duration_impl = Cqpid::Duration.new length end
Public Instance Methods
*(factor)
click to toggle source
Multiplies the duration of the Duration
and returns a new
instance.
Raises exceptions on a negative factor. Returns Qpid::Messaging::Duration::IMMEDIATE when the factor is 0.
Examples¶ ↑
# return a duration that is 2 minutes (120,000 ms) twominutes = Qpid::Messaging::Duration::MINUTE * 2
# File lib/qpid_messaging/duration.rb, line 103 def *(factor) raise TypeError.new "Factors must be non-zero positive values" if factor < 0 return Qpid::Messaging::Duration::IMMEDIATE if factor.zero? Qpid::Messaging::Duration.new((self.milliseconds * factor).floor) end
milliseconds()
click to toggle source
Returns the period of time in milliseconds
.
Examples¶ ↑
# doubling growth in waiting for messages in a loop do loop set the base duration waiting length timeout = Qpid::Messaging::Duration::SECOND msg = nil # loop until we receive a message while msg.nil? puts "Waiting #{timeout.milliseconds}ms" msg = recv.get timeout # if nothing was received, double the duration if msg.nil? # double out timeout timeout = timeout * 2 else # do something with the message puts "Received: #{msg.content}" end end end
# File lib/qpid_messaging/duration.rb, line 89 def milliseconds @duration_impl.getMilliseconds end