A Duration represents a period of time in milliseconds
The following named Durations are available as symbols:
The maximum integer value for the platform. Effectively this will wait forever.
An alias for 0 milliseconds.
An alias for 1,000 milliseconds.
And alias for 60,000 millisecons.
Creates a Duration with the specified length, in milliseconds.
length - The duration in milliseconds.
# 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
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.
# 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
Returns the period of time in milliseconds.
# 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